Skip to content

Commit b00a59d

Browse files
author
Thierry Charbonnel
committed
colorpicker remote controll and auto apply...
1 parent 4282ad5 commit b00a59d

5 files changed

Lines changed: 34 additions & 36 deletions

File tree

app/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@
5858

5959
// load all of the dependencies asynchronously.
6060
$script([
61-
'lib/less/less-1.3.3.min.js',
61+
'lib/less/less-1.3.3.js',
6262
'lib/jquery/jquery-1.8.3.min.js'
6363
], function() {
6464
$script([
65-
'../twitter-bootstrap/js/bootstrap.min.js',
65+
'../twitter-bootstrap/js/bootstrap.js',
6666
'lib/colorpicker/bootstrap-colorpicker.js'
6767
], function() {
6868
$script([

app/js/controllers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ function LessCtrl($scope, $http, ap_less) {
5353
};
5454
initLessVariables();
5555

56+
$scope.autoapplyless = false;
57+
58+
$scope.autoApplyLess = function (event) {
59+
if ($scope.autoapplyless){
60+
var vars = ap_less.getVariables($scope);
61+
less.modifyVars(vars);
62+
}
63+
};
5664

5765
$scope.applyLess = function (event) {
5866
var vars = ap_less.getVariables($scope);
@@ -98,6 +106,10 @@ function LessCtrl($scope, $http, ap_less) {
98106
$scope.applyLess();
99107
};
100108

109+
$scope.upDateValue = function () {
110+
        
111+
    };
112+
101113
$scope.isViewLoading = false;
102114

103115
$scope.$on('$routeChangeStart', function() {

app/js/directives.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,23 @@ angular.module('bootstrapVariablesEditor.directives', []).
1212
}]).
1313

1414
directive('apColorPicker',[ function() {
15-
16-
return function(scope, element, attrs) {
17-
18-
scope.$watch(attrs.ngModel,
19-
function(value){
20-
/*
21-
lessData.variables[scope.variable.key] = value;
22-
clearTimeout(lessData.timer);
23-
lessData.timer = setTimeout(
15+
return {
16+
restrict: 'C',
17+
link: function(scope, element, attrs) {
18+
var inputChange;
19+
20+
element.bind('change', function () {
21+
if (scope.variable.value.charAt(0) == '#') {
22+
element.colorpicker('setValue', scope.variable.value);
23+
}
24+
clearTimeout(inputChange);
25+
inputChange = setTimeout(
2426
function () {
25-
console.log('update');
26-
less.modifyVars(lessData.variables);
27-
}, 3000
27+
scope.$apply(attrs.colorpickerapply);
28+
}, 400
2829
);
29-
*/
30-
}
31-
);
32-
33-
34-
element.bind('blur',
35-
function(event){
36-
lessData.variables[scope.variable.key] = scope.variable.value;
37-
clearTimeout(lessData.timer);
38-
lessData.timer = setTimeout(
39-
function () {
40-
console.log('update');
41-
less.modifyVars(lessData.variables);
42-
}, 100
43-
);
44-
45-
}
46-
);
47-
30+
});
31+
32+
}
4833
};
4934
}]);

app/lib/colorpicker/bootstrap-colorpicker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,15 @@
345345
}
346346
}
347347

348-
$.fn.colorpicker = function ( option ) {
348+
$.fn.colorpicker = function ( option, args ) {
349349
return this.each(function () {
350350
var $this = $(this),
351351
data = $this.data('colorpicker'),
352352
options = typeof option === 'object' && option;
353353
if (!data) {
354354
$this.data('colorpicker', (data = new Colorpicker(this, $.extend({}, $.fn.colorpicker.defaults,options))));
355355
}
356-
if (typeof option === 'string') data[option]();
356+
if (typeof option === 'string') data[option](args);
357357
});
358358
};
359359

app/partials/editor.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<div class="navbar navbar-fixed-bottom" id="menuBottom" class="isEditor">
33
<ul>
44
<li><button class="btn btn-primary" ng-click="applyLess()">Apply</button></li>
5+
<li><label class="checkbox"><input type="checkbox" name="cssAutoapplyless" data-ng-model="autoapplyless">Auto</label></li>
56
<li><button class="btn btn-info" ng-click="saveLessVariables()">Save Less Variables</button></li>
67
<li><button class="btn btn-success" ng-click="saveCSS()">Save CSS</button></li>
78
<li><label class="checkbox"><input type="checkbox" name="cssMinified" data-ng-model="minified">Minified</label></li>
@@ -24,7 +25,7 @@ <h2 class="groupNameTitle" id="{{ group.name }}">{{ group.name }}</h2>
2425
<div class="span4">
2526
<div ng-repeat="variable in group.data" class="protected">
2627
<label class="labelTitle">{{variable.key}}</label></td>
27-
<div class="input" data-color="{{ color(variable.type, variable.value) }}" data-color-format="hex" ng-class="{ 'input-append color colorpicker' : colorpicker(variable.type)}">
28+
<div data-ColorPickerApply="autoApplyLess()" class="input {' ap-color-picker: variable.value': colorpicker(variable.type)}" data-color="{{ color(variable.type, variable.value) }}" data-color-format="hex" ng-class="{'input-append color colorpicker' : colorpicker(variable.type)}">
2829
<input id="appendedDropdownButton" type="text" data-ng-model="variable.value" class="span3 lessVariable">
2930
<span class="add-on" ng-class="{ 'hidden' : !colorpicker(variable.type)}"><i></i></span>
3031
</div>

0 commit comments

Comments
 (0)