Skip to content

Commit c1f118e

Browse files
committed
Bug - First change event was not firing if mouse drag
1 parent f32432d commit c1f118e

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/scripts/controller.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ export default class AngularColorPickerController {
259259
}
260260

261261
onMouseDown (event) {
262+
this.has_moused_moved = false;
263+
262264
// an element in this picker
263265
if (!this.options.disabled && this.find(event.target).length > 0) {
264266
// mouse event on color grid
@@ -284,17 +286,17 @@ export default class AngularColorPickerController {
284286
this.api.close(event);
285287
this.$scope.$apply();
286288
// mouse event on color grid
287-
} else if (this.colorMouse) {
289+
} else if (this.colorMouse && this.has_moused_moved) {
288290
this.colorUp(event);
289291
this.$scope.$apply();
290292
this.onChange(event);
291293
// mouse event on hue slider
292-
} else if (this.hueMouse) {
294+
} else if (this.hueMouse && this.has_moused_moved) {
293295
this.hueUp(event);
294296
this.$scope.$apply();
295297
this.onChange(event);
296298
// mouse event on opacity slider
297-
} else if (this.opacityMouse) {
299+
} else if (this.opacityMouse && this.has_moused_moved) {
298300
this.opacityUp(event);
299301
this.$scope.$apply();
300302
this.onChange(event);
@@ -304,50 +306,51 @@ export default class AngularColorPickerController {
304306
onMouseMove (event) {
305307
// mouse event on color grid
306308
if (this.colorMouse) {
309+
this.has_moused_moved = true;
307310
this.colorChange(event);
308311
this.$scope.$apply();
309312
// mouse event on hue slider
310313
} else if (this.hueMouse) {
314+
this.has_moused_moved = true;
311315
this.hueChange(event);
312316
this.$scope.$apply();
313317
// mouse event on opacity slider
314318
} else if (this.opacityMouse) {
319+
this.has_moused_moved = true;
315320
this.opacityChange(event);
316321
this.$scope.$apply();
317322
}
318323
}
319324

320325
onColorClick (event) {
321-
if (!this.options.disabled) {
326+
if (!this.options.disabled && !this.has_moused_moved) {
322327
this.colorChange(event);
328+
this.colorUp(event);
323329
this.$scope.$apply();
324330
this.onChange(event);
325331
}
326332
}
327333

328334
onHueClick (event) {
329-
if (!this.options.disabled) {
335+
if (!this.options.disabled && !this.has_moused_moved) {
330336
this.hueChange(event);
337+
this.hueUp(event);
331338
this.$scope.$apply();
332339
this.onChange(event);
333340
}
334341
}
335342

336343
onOpacityClick (event) {
337-
if (!this.options.disabled) {
344+
if (!this.options.disabled && !this.has_moused_moved) {
338345
this.opacityChange(event);
346+
this.opacityUp(event);
339347
this.$scope.$apply();
340348
this.onChange(event);
341349
}
342350
}
343351

344352
onChange (event) {
345-
// on first firing, set this so it doesn't fire twice
346-
if (!this.hasOwnProperty('onChangeValue')) {
347-
this.onChangeValue = this.ngModel;
348-
}
349-
350-
// this can be triggered by both click and mouseup, so don't fire twice
353+
// don't fire if it hasn't actually changed
351354
if (this.ngModel !== this.onChangeValue) {
352355
this.onChangeValue = this.ngModel;
353356

0 commit comments

Comments
 (0)