|
1 | 1 | /*! |
2 | | - * angularjs-color-picker v2.1.1 |
| 2 | + * angularjs-color-picker v2.1.2 |
3 | 3 | * https://github.com/ruhley/angular-color-picker/ |
4 | 4 | * |
5 | 5 | * Copyright 2016 ruhley |
6 | 6 | * |
7 | | - * 2016-07-14 08:05:35 |
| 7 | + * 2016-07-15 10:26:38 |
8 | 8 | * |
9 | 9 | */ |
10 | 10 |
|
|
40 | 40 |
|
41 | 41 | var AngularColorPickerController = function () { |
42 | 42 | function AngularColorPickerController(_$scope, _$element, _$document, _$timeout) { |
43 | | - var _this = this; |
44 | | - |
45 | 43 | classCallCheck(this, AngularColorPickerController); |
46 | 44 |
|
47 | 45 | // set angular injected variables |
|
50 | 48 | this.$document = _$document; |
51 | 49 | this.$timeout = _$timeout; |
52 | 50 |
|
53 | | - // browser variables |
54 | | - this.chrome = Boolean(window.chrome); |
55 | | - var _android_version = window.navigator.userAgent.match(/Android\s([0-9\.]*)/i); |
56 | | - this.android_version = _android_version && _android_version.length > 1 ? parseFloat(_android_version[1]) : NaN; |
57 | | - |
58 | | - // needed variables |
59 | | - this.onChangeValue = null; |
60 | | - this.updateModel = true; |
61 | | - |
62 | | - //--------------------------- |
63 | | - // watchers |
64 | | - //--------------------------- |
65 | | - |
66 | | - // ngModel |
67 | | - |
68 | | - this.$scope.$watch('AngularColorPickerController.ngModel', this.watchNgModel.bind(this)); |
69 | | - |
70 | | - // options |
71 | | - |
72 | | - this.$scope.$watch('AngularColorPickerController.options.swatchPos', this.watchSwatchPos.bind(this)); |
73 | | - |
74 | | - this.$scope.$watchGroup(['AngularColorPickerController.options.format', 'AngularColorPickerController.options.alpha', 'AngularColorPickerController.options.case'], this.reInitAndUpdate.bind(this)); |
75 | | - |
76 | | - this.$scope.$watchGroup(['AngularColorPickerController.options.disabled', 'AngularColorPickerController.options.swatchBootstrap', 'AngularColorPickerController.options.swatchOnly', 'AngularColorPickerController.options.swatch', 'AngularColorPickerController.options.pos', 'AngularColorPickerController.options.inline'], this.reInit.bind(this)); |
77 | | - |
78 | | - // api |
79 | | - |
80 | | - this.$scope.$watch('AngularColorPickerController.api', this.watchApi.bind(this)); |
81 | | - |
82 | | - // internal |
83 | | - |
84 | | - this.$scope.$watch('AngularColorPickerController.swatchColor', this.updateSwatchBackground.bind(this)); |
85 | | - |
86 | | - this.$scope.$watch('AngularColorPickerController.hue', this.hueUpdate.bind(this)); |
87 | | - |
88 | | - this.$scope.$watch('AngularColorPickerController.saturation', this.saturationUpdate.bind(this)); |
89 | | - |
90 | | - this.$scope.$watch('AngularColorPickerController.lightness', this.lightnessUpdate.bind(this)); |
91 | | - |
92 | | - this.$scope.$watch('AngularColorPickerController.opacity', this.opacityUpdate.bind(this)); |
93 | | - |
94 | | - //--------------------------- |
95 | | - // destroy |
96 | | - //--------------------------- |
97 | | - |
98 | | - this.$scope.$on('$destroy', function () { |
99 | | - _this.$document.off('mousedown', _this.onMouseDown); |
100 | | - _this.$document.off('mouseup', _this.onMouseUp); |
101 | | - _this.$document.off('mousemove', _this.onMouseMove); |
102 | | - |
103 | | - _this.eventApiDispatch('onDestroy'); |
104 | | - }); |
105 | | - |
106 | | - //--------------------------- |
107 | | - // Init |
108 | | - //--------------------------- |
109 | | - |
110 | | - this.init(); |
| 51 | + this.$scope.init = this.init.bind(this); |
111 | 52 | } |
112 | 53 |
|
113 | 54 | createClass(AngularColorPickerController, [{ |
114 | 55 | key: 'watchNgModel', |
115 | 56 | value: function watchNgModel(newValue, oldValue) { |
116 | | - var _this2 = this; |
| 57 | + var _this = this; |
117 | 58 |
|
118 | 59 | if (this.colorMouse) { |
119 | 60 | return; |
|
136 | 77 | } |
137 | 78 |
|
138 | 79 | this.$timeout(function () { |
139 | | - _this2.updateModel = true; |
| 80 | + _this.updateModel = true; |
140 | 81 | }); |
141 | 82 |
|
142 | 83 | this.isValid = true; |
|
163 | 104 | }, { |
164 | 105 | key: 'watchSwatchPos', |
165 | 106 | value: function watchSwatchPos(newValue) { |
166 | | - var _this3 = this; |
| 107 | + var _this2 = this; |
167 | 108 |
|
168 | 109 | if (newValue !== undefined) { |
169 | 110 | this.initConfig(); |
170 | 111 |
|
171 | 112 | this.$timeout(function () { |
172 | | - _this3.updateSwatchBackground(); |
| 113 | + _this2.updateSwatchBackground(); |
173 | 114 | }); |
174 | 115 | } |
175 | 116 | } |
176 | 117 | }, { |
177 | | - key: 'watchApi', |
178 | | - value: function watchApi() { |
179 | | - var _this4 = this; |
| 118 | + key: 'setupApi', |
| 119 | + value: function setupApi() { |
| 120 | + var _this3 = this; |
180 | 121 |
|
181 | 122 | if (!this.api) { |
182 | 123 | this.api = {}; |
183 | 124 | } |
184 | 125 |
|
185 | 126 | this.api.open = function (event) { |
186 | 127 | // if already visible then don't run show again |
187 | | - if (_this4.visible) { |
| 128 | + if (_this3.visible) { |
188 | 129 | return true; |
189 | 130 | } |
190 | 131 |
|
191 | | - _this4.visible = true; |
192 | | - _this4.hueMouse = false; |
193 | | - _this4.opacityMouse = false; |
194 | | - _this4.colorMouse = false; |
| 132 | + _this3.visible = true; |
| 133 | + _this3.hueMouse = false; |
| 134 | + _this3.opacityMouse = false; |
| 135 | + _this3.colorMouse = false; |
195 | 136 |
|
196 | 137 | // force the sliders to re-caculate their position |
197 | | - _this4.hueUpdate(); |
198 | | - _this4.saturationUpdate(); |
199 | | - _this4.lightnessUpdate(); |
200 | | - _this4.opacityUpdate(); |
| 138 | + _this3.hueUpdate(); |
| 139 | + _this3.saturationUpdate(); |
| 140 | + _this3.lightnessUpdate(); |
| 141 | + _this3.opacityUpdate(); |
201 | 142 |
|
202 | | - _this4.eventApiDispatch('onOpen', [event]); |
| 143 | + _this3.eventApiDispatch('onOpen', [event]); |
203 | 144 | }; |
204 | 145 |
|
205 | 146 | this.api.close = function (event) { |
206 | | - if (!_this4.options.inline && (_this4.visible || _this4.$element[0].querySelector('.color-picker-panel').offsetParent !== null)) { |
| 147 | + if (!_this3.options.inline && (_this3.visible || _this3.$element[0].querySelector('.color-picker-panel').offsetParent !== null)) { |
207 | 148 |
|
208 | | - _this4.visible = false; |
209 | | - _this4.$scope.$apply(); |
| 149 | + _this3.visible = false; |
| 150 | + _this3.$scope.$apply(); |
210 | 151 |
|
211 | | - _this4.eventApiDispatch('onClose', [event]); |
| 152 | + _this3.eventApiDispatch('onClose', [event]); |
212 | 153 | } |
213 | 154 | }; |
214 | 155 |
|
215 | 156 | this.api.getElement = function () { |
216 | | - return _this4.$element; |
| 157 | + return _this3.$element; |
217 | 158 | }; |
218 | 159 | } |
219 | 160 | }, { |
|
234 | 175 | }, { |
235 | 176 | key: 'init', |
236 | 177 | value: function init() { |
| 178 | + var _this4 = this; |
| 179 | + |
| 180 | + // browser variables |
| 181 | + this.chrome = Boolean(window.chrome); |
| 182 | + var _android_version = window.navigator.userAgent.match(/Android\s([0-9\.]*)/i); |
| 183 | + this.android_version = _android_version && _android_version.length > 1 ? parseFloat(_android_version[1]) : NaN; |
| 184 | + |
| 185 | + // needed variables |
| 186 | + this.onChangeValue = null; |
| 187 | + this.updateModel = true; |
| 188 | + |
| 189 | + //--------------------------- |
| 190 | + // watchers |
| 191 | + //--------------------------- |
| 192 | + |
| 193 | + // ngModel |
| 194 | + |
| 195 | + this.$scope.$watch('AngularColorPickerController.ngModel', this.watchNgModel.bind(this)); |
| 196 | + |
| 197 | + // options |
| 198 | + |
| 199 | + this.$scope.$watch('AngularColorPickerController.options.swatchPos', this.watchSwatchPos.bind(this)); |
| 200 | + |
| 201 | + this.$scope.$watchGroup(['AngularColorPickerController.options.format', 'AngularColorPickerController.options.alpha', 'AngularColorPickerController.options.case'], this.reInitAndUpdate.bind(this)); |
| 202 | + |
| 203 | + this.$scope.$watchGroup(['AngularColorPickerController.options.disabled', 'AngularColorPickerController.options.swatchBootstrap', 'AngularColorPickerController.options.swatchOnly', 'AngularColorPickerController.options.swatch', 'AngularColorPickerController.options.pos', 'AngularColorPickerController.options.inline'], this.reInit.bind(this)); |
| 204 | + |
| 205 | + // api |
| 206 | + |
| 207 | + this.$scope.$watch('AngularColorPickerController.api', this.setupApi.bind(this)); |
| 208 | + |
| 209 | + // internal |
| 210 | + |
| 211 | + this.$scope.$watch('AngularColorPickerController.swatchColor', this.updateSwatchBackground.bind(this)); |
| 212 | + |
| 213 | + this.$scope.$watch('AngularColorPickerController.hue', this.hueUpdate.bind(this)); |
| 214 | + |
| 215 | + this.$scope.$watch('AngularColorPickerController.saturation', this.saturationUpdate.bind(this)); |
| 216 | + |
| 217 | + this.$scope.$watch('AngularColorPickerController.lightness', this.lightnessUpdate.bind(this)); |
| 218 | + |
| 219 | + this.$scope.$watch('AngularColorPickerController.opacity', this.opacityUpdate.bind(this)); |
| 220 | + |
| 221 | + //--------------------------- |
| 222 | + // destroy |
| 223 | + //--------------------------- |
| 224 | + |
| 225 | + this.$scope.$on('$destroy', function () { |
| 226 | + _this4.$document.off('mousedown', _this4.onMouseDown); |
| 227 | + _this4.$document.off('mouseup', _this4.onMouseUp); |
| 228 | + _this4.$document.off('mousemove', _this4.onMouseMove); |
| 229 | + |
| 230 | + _this4.eventApiDispatch('onDestroy'); |
| 231 | + }); |
| 232 | + |
237 | 233 | // if no color provided |
238 | 234 | if (this.ngModel === undefined) { |
239 | 235 | this.setDefaults(); |
|
286 | 282 | value: function onMouseUp(event) { |
287 | 283 | // no current mouse events and not an element in the picker |
288 | 284 | if (!this.colorMouse && !this.hueMouse && !this.opacityMouse && this.find(event.target).length === 0) { |
| 285 | + this.setupApi(); // TODO - there are some weird times when this is needed to call close. Need to figure out why. |
289 | 286 | this.api.close(event); |
290 | 287 | // mouse event on color grid |
291 | 288 | } else if (this.colorMouse) { |
|
843 | 840 | controllerAs: 'AngularColorPickerController', |
844 | 841 | link: function link($scope, element, attrs, control) { |
845 | 842 | $scope.control = control; |
| 843 | + $scope.init(); |
846 | 844 | } |
847 | 845 | }; |
848 | 846 | } |
|
0 commit comments