11/*!
2- * angularjs-color-picker v0.7.0
2+ * angularjs-color-picker v0.7.1
33 * https://github.com/ruhley/angular-color-picker/
44 *
55 * Copyright 2015 ruhley
66 *
7- * 2015-12-10 09:23:22
7+ * 2015-12-14 08:26:03
88 *
99 */
1010if ( typeof module !== "undefined" && typeof exports !== "undefined" && module . exports === exports ) {
@@ -38,6 +38,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
3838 templateUrl : 'template/color-picker/directive.html' ,
3939 link : function ( $scope , element , attrs , control ) {
4040 $scope . init = function ( ) {
41+ // if no color provided
4142 if ( $scope . ngModel === undefined ) {
4243 $scope . hue = 0 ;
4344 $scope . saturation = 0 ;
@@ -54,68 +55,66 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
5455 }
5556 }
5657
58+ // set default config settings
5759 $scope . initConfig ( ) ;
5860
61+ // setup mouse events
5962 $document . on ( 'mousedown' , $scope . onMouseDown ) ;
6063 $document . on ( 'mouseup' , $scope . onMouseUp ) ;
6164 $document . on ( 'mousemove' , $scope . onMouseMove ) ;
6265 } ;
6366
6467 $scope . onMouseDown = function ( event ) {
65- // not an element in this picker
66- if ( $scope . find ( event . target ) . length === 0 ) {
67- return false ;
68- }
69-
70- if ( event . target . classList . contains ( 'color-picker-grid-inner' ) || event . target . classList . contains ( 'color-picker-picker' ) || event . target . parentNode . classList . contains ( 'color-picker-picker' ) ) {
71- $scope . colorDown ( event ) ;
72- $scope . $apply ( ) ;
73- } else if ( event . target . classList . contains ( 'color-picker-hue' ) || event . target . parentNode . classList . contains ( 'color-picker-hue' ) ) {
74- $scope . hueDown ( event ) ;
75- $scope . $apply ( ) ;
76- } else if ( event . target . classList . contains ( 'color-picker-opacity' ) || event . target . parentNode . classList . contains ( 'color-picker-opacity' ) ) {
77- $scope . opacityDown ( event ) ;
78- $scope . $apply ( ) ;
79- }
80- } ;
81-
82- $scope . onMouseUp = function ( event ) {
83- if ( ! $scope . colorMouse && ! $scope . hueMouse && ! $scope . opacityMouse ) {
84- if ( $scope . find ( event . target ) . length === 0 ) {
85- $scope . log ( 'Color Picker: Document Click Event' ) ;
86- $scope . hide ( ) ;
68+ // an element in this picker
69+ if ( $scope . find ( event . target ) . length > 0 ) {
70+ // mouse event on color grid
71+ if ( event . target . classList . contains ( 'color-picker-grid-inner' ) || event . target . classList . contains ( 'color-picker-picker' ) || event . target . parentNode . classList . contains ( 'color-picker-picker' ) ) {
72+ $scope . colorDown ( event ) ;
73+ $scope . $apply ( ) ;
74+ // mouse event on hue slider
75+ } else if ( event . target . classList . contains ( 'color-picker-hue' ) || event . target . parentNode . classList . contains ( 'color-picker-hue' ) ) {
76+ $scope . hueDown ( event ) ;
77+ $scope . $apply ( ) ;
78+ // mouse event on opacity slider
79+ } else if ( event . target . classList . contains ( 'color-picker-opacity' ) || event . target . parentNode . classList . contains ( 'color-picker-opacity' ) ) {
80+ $scope . opacityDown ( event ) ;
8781 $scope . $apply ( ) ;
8882 }
8983 }
84+ } ;
9085
91- if ( $scope . colorMouse ) {
86+ $scope . onMouseUp = function ( event ) {
87+ // no current mouse events and not an element in the picker
88+ if ( ! $scope . colorMouse && ! $scope . hueMouse && ! $scope . opacityMouse && $scope . find ( event . target ) . length === 0 ) {
89+ $scope . log ( 'Color Picker: Document Click Event' ) ;
90+ $scope . hide ( ) ;
91+ $scope . $apply ( ) ;
92+ // mouse event on color grid
93+ } else if ( $scope . colorMouse ) {
9294 $scope . colorUp ( event ) ;
9395 $scope . $apply ( ) ;
94- }
95-
96- if ( $scope . hueMouse ) {
96+ // mouse event on hue slider
97+ } else if ( $scope . hueMouse ) {
9798 $scope . hueUp ( event ) ;
9899 $scope . $apply ( ) ;
99- }
100-
101- if ( $scope . opacityMouse ) {
100+ // mouse event on opacity slider
101+ } else if ( $scope . opacityMouse ) {
102102 $scope . opacityUp ( event ) ;
103103 $scope . $apply ( ) ;
104104 }
105105 } ;
106106
107107 $scope . onMouseMove = function ( event ) {
108+ // mouse event on color grid
108109 if ( $scope . colorMouse ) {
109110 $scope . colorChange ( event ) ;
110111 $scope . $apply ( ) ;
111- }
112-
113- if ( $scope . hueMouse ) {
112+ // mouse event on hue slider
113+ } else if ( $scope . hueMouse ) {
114114 $scope . hueChange ( event ) ;
115115 $scope . $apply ( ) ;
116- }
117-
118- if ( $scope . opacityMouse ) {
116+ // mouse event on opacity slider
117+ } else if ( $scope . opacityMouse ) {
119118 $scope . opacityChange ( event ) ;
120119 $scope . $apply ( ) ;
121120 }
0 commit comments