Skip to content

Commit c874f71

Browse files
committed
No longer showing and hiding on load for a better user experience
1 parent 2cdec41 commit c874f71

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

lib/scripts/directive.js

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
$scope.hueMouse = false;
6868
$scope.opacityMouse = false;
6969
$scope.colorMouse = false;
70+
71+
// force the grid selection circle to redraw and fix its position
72+
$scope.saturationUpdate();
73+
$scope.lightnessUpdate();
7074
};
7175

7276
$scope.hide = function (apply) {
@@ -135,23 +139,7 @@
135139
if (color.isValid()) {
136140
var hsl = color.toHsv();
137141

138-
if (!$scope.isValid) {
139-
$scope.show();
140-
141-
$timeout(function() {
142-
$scope.hue = hsl.h;
143-
$scope.saturation = hsl.s * 100;
144-
$scope.lightness = hsl.v * 100;
145-
146-
if ($scope.config.alpha) {
147-
$scope.opacity = hsl.a * 100;
148-
}
149-
150-
if (oldValue === undefined) {
151-
$scope.hide();
152-
}
153-
});
154-
} else {
142+
if ($scope.isValid) {
155143
$scope.hue = hsl.h;
156144
$scope.saturation = hsl.s * 100;
157145
$scope.lightness = hsl.v * 100;
@@ -225,11 +213,11 @@
225213
}
226214
};
227215

228-
$scope.$watch('hue', function (newValue, oldValue) {
229-
if (newValue !== undefined) {
216+
$scope.hueUpdate = function() {
217+
if ($scope.hue !== undefined) {
230218
$scope.log('Color Picker: HUE - CHANGED');
231-
$scope.huePos = (1 - (newValue / 360)) * 100;
232-
$scope.grid = tinycolor({h: newValue, s: 100, v: 1}).toHslString();
219+
$scope.huePos = (1 - ($scope.hue / 360)) * 100;
220+
$scope.grid = tinycolor({h: $scope.hue, s: 100, v: 1}).toHslString();
233221

234222
if ($scope.huePos < 0) {
235223
$scope.huePos = 0;
@@ -239,6 +227,10 @@
239227

240228
$scope.update();
241229
}
230+
};
231+
232+
$scope.$watch('hue', function (newValue, oldValue) {
233+
$scope.hueUpdate();
242234
});
243235

244236
//---------------------------
@@ -262,10 +254,10 @@
262254
}
263255
};
264256

265-
$scope.$watch('opacity', function (newValue, oldValue) {
266-
if (newValue !== undefined) {
257+
$scope.opacityUpdate = function() {
258+
if ($scope.opacity !== undefined) {
267259
$scope.log('Color Picker: OPACITY - CHANGED');
268-
$scope.opacityPos = (1 - (newValue / 100)) * 100;
260+
$scope.opacityPos = (1 - ($scope.opacity / 100)) * 100;
269261

270262
if ($scope.opacityPos < 0) {
271263
$scope.opacityPos = 0;
@@ -275,6 +267,10 @@
275267

276268
$scope.update();
277269
}
270+
};
271+
272+
$scope.$watch('opacity', function (newValue, oldValue) {
273+
$scope.opacityUpdate();
278274
});
279275

280276
//---------------------------
@@ -299,10 +295,10 @@
299295
}
300296
};
301297

302-
$scope.$watch('saturation', function (newValue, oldValue) {
303-
if (newValue !== undefined && newValue !== oldValue) {
298+
$scope.saturationUpdate = function(oldValue) {
299+
if ($scope.saturation !== undefined && $scope.saturation !== oldValue) {
304300
$scope.log('Color Picker: SATURATION - CHANGED');
305-
$scope.saturationPos = (newValue / 100) * 100;
301+
$scope.saturationPos = ($scope.saturation / 100) * 100;
306302

307303
if ($scope.saturationPos < 0) {
308304
$scope.saturationPos = 0;
@@ -312,12 +308,16 @@
312308

313309
$scope.update();
314310
}
311+
};
312+
313+
$scope.$watch('saturation', function (newValue, oldValue) {
314+
$scope.saturationUpdate(oldValue);
315315
});
316316

317-
$scope.$watch('lightness', function (newValue, oldValue) {
318-
if (newValue !== undefined && newValue !== oldValue) {
317+
$scope.lightnessUpdate = function(oldValue) {
318+
if ($scope.lightness !== undefined && $scope.lightness !== oldValue) {
319319
$scope.log('Color Picker: LIGHTNESS - CHANGED');
320-
$scope.lightnessPos = (1 - (newValue / 100)) * 100;
320+
$scope.lightnessPos = (1 - ($scope.lightness / 100)) * 100;
321321

322322
if ($scope.lightnessPos < 0) {
323323
$scope.lightnessPos = 0;
@@ -327,6 +327,10 @@
327327

328328
$scope.update();
329329
}
330+
};
331+
332+
$scope.$watch('lightness', function (newValue, oldValue) {
333+
$scope.lightnessUpdate(oldValue);
330334
});
331335

332336

0 commit comments

Comments
 (0)