11/*!
2- * angularjs-color-picker v1.0.1
2+ * angularjs-color-picker v1.0.3
33 * https://github.com/ruhley/angular-color-picker/
44 *
55 * Copyright 2016 ruhley
66 *
7- * 2016-03-23 08 :35:46
7+ * 2016-04-08 09 :35:35
88 *
99 */
1010if ( typeof module !== "undefined" && typeof exports !== "undefined" && module . exports === exports ) {
@@ -26,6 +26,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
2626 require : [ '^ngModel' ] ,
2727 scope : {
2828 ngModel : '=' ,
29+ colorPickerDisabled : '=' ,
2930 colorPickerAlpha : '=' ,
3031 colorPickerCase : '=' ,
3132 colorPickerFormat : '=' ,
@@ -44,9 +45,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
4445 $scope . init = function ( ) {
4546 // if no color provided
4647 if ( $scope . ngModel === undefined ) {
47- $scope . hue = 0 ;
48- $scope . saturation = 0 ;
49- $scope . lightness = 100 ;
48+ $scope . setDefaults ( ) ;
5049 } else {
5150 var color = tinycolor ( $scope . ngModel ) ;
5251
@@ -155,9 +154,14 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
155154 }
156155 } ;
157156
157+ $scope . onBlur = function ( ) {
158+ $scope . updateModel = true ;
159+ $scope . update ( ) ;
160+ } ;
158161
159162 $scope . initConfig = function ( ) {
160163 $scope . config = { } ;
164+ $scope . config . disabled = $scope . colorPickerDisabled === undefined ? false : $scope . colorPickerDisabled ;
161165 $scope . config . alpha = $scope . colorPickerAlpha === undefined ? true : $scope . colorPickerAlpha ;
162166 $scope . config . case = $scope . colorPickerCase === undefined ? 'upper' : $scope . colorPickerCase ;
163167 $scope . config . format = $scope . colorPickerFormat === undefined ? 'hsl' : $scope . colorPickerFormat ;
@@ -195,54 +199,76 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
195199 }
196200 } ;
197201
202+ $scope . setDefaults = function ( ) {
203+ if ( $scope . hue === undefined ) {
204+ $scope . hue = 0 ;
205+ }
206+
207+ if ( $scope . saturation === undefined ) {
208+ $scope . saturation = 0 ;
209+ }
210+
211+ if ( $scope . lightness === undefined ) {
212+ $scope . lightness = 100 ;
213+ }
214+
215+ if ( $scope . opacity === undefined ) {
216+ $scope . opacity = 100 ;
217+ }
218+ } ;
219+
198220 $scope . update = function ( ) {
199- if ( $scope . hue !== undefined && $scope . saturation !== undefined && $scope . lightness ! == undefined ) {
200- var color = tinycolor ( { h : $scope . hue , s : $scope . saturation / 100 , v : $scope . lightness / 100 } ) ,
201- colorString ;
221+ if ( $scope . hue === undefined && $scope . saturation === undefined && $scope . lightness = == undefined ) {
222+ return false ;
223+ }
202224
203- if ( $scope . config . alpha ) {
204- color . setAlpha ( $scope . opacity / 100 ) ;
205- }
225+ $scope . setDefaults ( ) ;
206226
207- $scope . log ( 'Color Picker: COLOR CHANGED TO ' , color , $scope . hue , $scope . saturation , $scope . lightness , $scope . opacity ) ;
208-
209- $scope . swatchColor = color . toHslString ( ) ;
210-
211- switch ( $scope . config . format ) {
212- case 'rgb' :
213- colorString = color . toRgbString ( ) ;
214- break ;
215-
216- case 'hex' :
217- colorString = color . toHexString ( ) ;
218- if ( $scope . config . case === 'lower' ) {
219- colorString = colorString . toLowerCase ( ) ;
220- } else {
221- colorString = colorString . toUpperCase ( ) ;
222- }
223- break ;
224-
225- case 'hex8' :
226- colorString = color . toHex8String ( ) ;
227- if ( $scope . config . case === 'lower' ) {
228- colorString = colorString . toLowerCase ( ) ;
229- } else {
230- colorString = colorString . toUpperCase ( ) ;
231- }
232- break ;
233-
234- case 'hsv' :
235- colorString = color . toHsvString ( ) ;
236- break ;
237-
238- default :
239- colorString = color . toHslString ( ) ;
240- break ;
241- }
227+ var color = tinycolor ( { h : $scope . hue , s : $scope . saturation / 100 , v : $scope . lightness / 100 } ) ,
228+ colorString ;
242229
243- if ( $scope . updateModel ) {
244- $scope . ngModel = colorString ;
245- }
230+ if ( $scope . config . alpha ) {
231+ color . setAlpha ( $scope . opacity / 100 ) ;
232+ }
233+
234+ $scope . log ( 'Color Picker: COLOR CHANGED TO ' , color , $scope . hue , $scope . saturation , $scope . lightness , $scope . opacity ) ;
235+
236+ $scope . swatchColor = color . toHslString ( ) ;
237+
238+ switch ( $scope . config . format ) {
239+ case 'rgb' :
240+ colorString = color . toRgbString ( ) ;
241+ break ;
242+
243+ case 'hex' :
244+ colorString = color . toHexString ( ) ;
245+ if ( $scope . config . case === 'lower' ) {
246+ colorString = colorString . toLowerCase ( ) ;
247+ } else {
248+ colorString = colorString . toUpperCase ( ) ;
249+ }
250+ break ;
251+
252+ case 'hex8' :
253+ colorString = color . toHex8String ( ) ;
254+ if ( $scope . config . case === 'lower' ) {
255+ colorString = colorString . toLowerCase ( ) ;
256+ } else {
257+ colorString = colorString . toUpperCase ( ) ;
258+ }
259+ break ;
260+
261+ case 'hsv' :
262+ colorString = color . toHsvString ( ) ;
263+ break ;
264+
265+ default :
266+ colorString = color . toHslString ( ) ;
267+ break ;
268+ }
269+
270+ if ( $scope . updateModel ) {
271+ $scope . ngModel = colorString ;
246272 }
247273 } ;
248274
@@ -279,6 +305,13 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
279305 control [ 0 ] . $setDirty ( ) ;
280306 }
281307 } else {
308+ if ( newValue === null ) {
309+ $scope . hue = undefined ;
310+ $scope . saturation = undefined ;
311+ $scope . lightness = undefined ;
312+ $scope . opacity = undefined ;
313+ }
314+
282315 $scope . swatchColor = '' ;
283316 }
284317 } ) ;
@@ -305,7 +338,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
305338 ) ;
306339
307340 $scope . $watchGroup (
308- [ 'colorPickerSwatchPos' , 'colorPickerSwatchBootstrap' , 'colorPickerSwatchOnly' , 'colorPickerSwatch' , 'colorPickerPos' ] ,
341+ [ 'colorPickerDisabled' , ' colorPickerSwatchPos', 'colorPickerSwatchBootstrap' , 'colorPickerSwatchOnly' , 'colorPickerSwatch' , 'colorPickerPos' ] ,
309342 function ( newValue , oldValue ) {
310343 if ( newValue !== undefined ) {
311344 $scope . initConfig ( ) ;
@@ -646,7 +679,7 @@ angular.module('color.picker').run(['$templateCache', function($templateCache) {
646679 '<div class="color-picker-wrapper" ng-class="{\'color-picker-swatch-only\': config.swatchOnly}">\n' +
647680 ' <div class="color-picker-input-wrapper" ng-class="{\'input-group\': config.swatchBootstrap && config.swatch}">\n' +
648681 ' <span ng-if="config.swatchPos === \'left\'" class="color-picker-swatch" ng-click="focus()" ng-show="config.swatch" ng-class="{\'color-picker-swatch-left\': config.swatchPos !== \'right\', \'color-picker-swatch-right\': config.swatchPos === \'right\', \'input-group-addon\': config.swatchBootstrap}"></span>\n' +
649- ' <input class="color-picker-input form-control" type="text" ng-model="ngModel" ng-change="onChange($event)" size="7" ng-focus="show()" ng-class="{\'color-picker-input-swatch\': config.swatch && !config.swatchOnly && config.swatchPos === \'left\'}">\n' +
682+ ' <input class="color-picker-input form-control" type="text" ng-model="ngModel" ng-disabled="config.disabled" ng-blur="onBlur()" ng- change="onChange($event)" size="7" ng-focus="show()" ng-class="{\'color-picker-input-swatch\': config.swatch && !config.swatchOnly && config.swatchPos === \'left\'}">\n' +
650683 ' <span ng-if="config.swatchPos === \'right\'" class="color-picker-swatch" ng-click="focus()" ng-show="config.swatch" ng-class="{\'color-picker-swatch-left\': config.swatchPos !== \'right\', \'color-picker-swatch-right\': config.swatchPos === \'right\', \'input-group-addon\': config.swatchBootstrap}"></span>\n' +
651684 ' </div>\n' +
652685 ' <div class="color-picker-panel" ng-show="visible" ng-class="{\n' +
0 commit comments