11/*!
2- * angular-color-picker v0.6.7
2+ * angular-color-picker v0.6.8
33 * https://github.com/ruhley/angular-color-picker/
44 *
55 * Copyright 2015 ruhley
66 *
7- * 2015-09-17 08:24:38
7+ * 2015-09-28 08:53:52
88 *
99 */
1010if ( typeof module !== "undefined" && typeof exports !== "undefined" && module . exports === exports ) {
@@ -57,7 +57,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
5757
5858 $document . on ( 'click' , function ( evt ) {
5959 if ( $scope . find ( evt . target ) . length === 0 ) {
60- $scope . log ( 'Color Picker: Document Hide Event' ) ;
60+ $scope . log ( 'Color Picker: Document Click Event' ) ;
6161 $scope . hide ( ) ;
6262 }
6363 } ) ;
@@ -93,11 +93,11 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
9393 $scope . lightnessUpdate ( ) ;
9494 } ;
9595
96- $scope . hide = function ( apply ) {
96+ $scope . hide = function ( ) {
9797 $scope . log ( 'Color Picker: Hide Event' ) ;
98- $scope . visible = false ;
9998
100- if ( apply !== false ) {
99+ if ( $scope . visible ) {
100+ $scope . visible = false ;
101101 $scope . $apply ( ) ;
102102 }
103103 } ;
@@ -227,7 +227,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
227227 if ( $scope . hueMouse || forceRun ) {
228228 $scope . log ( 'Color Picker: HUE - MOUSE CHANGE' ) ;
229229 var el = $scope . find ( '.color-picker-hue' ) ;
230- $scope . hue = ( 1 - ( ( evt . pageY - $scope . offset ( el , 'top' ) ) / el . prop ( 'offsetHeight' ) ) ) * 360 ;
230+ $scope . hue = ( 1 - ( ( evt . pageY - $scope . offset ( el ) . top ) / el . prop ( 'offsetHeight' ) ) ) * 360 ;
231231 }
232232 } ;
233233
@@ -268,7 +268,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
268268 if ( $scope . opacityMouse || forceRun ) {
269269 $scope . log ( 'Color Picker: OPACITY - MOUSE CHANGE' ) ;
270270 var el = $scope . find ( '.color-picker-opacity' ) ;
271- $scope . opacity = ( 1 - ( ( evt . pageY - $scope . offset ( el , 'top' ) ) / el . prop ( 'offsetHeight' ) ) ) * 100 ;
271+ $scope . opacity = ( 1 - ( ( evt . pageY - $scope . offset ( el ) . top ) / el . prop ( 'offsetHeight' ) ) ) * 100 ;
272272 }
273273 } ;
274274
@@ -308,8 +308,10 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
308308 if ( $scope . colorMouse || forceRun ) {
309309 $scope . log ( 'Color Picker: COLOR - MOUSE CHANGE' ) ;
310310 var el = $scope . find ( '.color-picker-grid-inner' ) ;
311- $scope . saturation = ( ( evt . pageX - $scope . offset ( el , 'left' ) ) / el . prop ( 'offsetWidth' ) ) * 100 ;
312- $scope . lightness = ( 1 - ( ( evt . pageY - $scope . offset ( el , 'top' ) ) / el . prop ( 'offsetHeight' ) ) ) * 100 ;
311+ var offset = $scope . offset ( el ) ;
312+
313+ $scope . saturation = ( ( evt . pageX - offset . left ) / el . prop ( 'offsetWidth' ) ) * 100 ;
314+ $scope . lightness = ( 1 - ( ( evt . pageY - offset . top ) / el . prop ( 'offsetHeight' ) ) ) * 100 ;
313315 }
314316 } ;
315317
@@ -356,7 +358,7 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
356358 // HELPER FUNCTIONS
357359 //---------------------------
358360 $scope . log = function ( ) {
359- //console.log.apply(console, arguments);
361+ // console.log.apply(console, arguments);
360362 } ;
361363
362364 // taken and modified from jQuery's find
@@ -380,50 +382,61 @@ if (typeof module !== "undefined" && typeof exports !== "undefined" && module.ex
380382 results = context . querySelectorAll ( selector ) ;
381383
382384 } else {
383- if ( $scope . contains ( context , selector ) ) {
385+ if ( context . contains ( selector ) ) {
384386 results . push ( selector ) ;
385387 }
386388 }
387389
388390 return angular . element ( results ) ;
389391 } ;
390392
391- $scope . contains = function ( a , b ) {
392- if ( b ) {
393- while ( ( b = b . parentNode ) ) {
394- if ( b === a ) {
395- return true ;
396- }
393+ // taken and modified from jQuery's offset
394+ $scope . offset = function ( el ) {
395+ var docElem , win , rect , doc , elem = el [ 0 ] ;
396+
397+ if ( ! elem ) {
398+ return ;
399+ }
400+
401+ // Support: IE<=11+
402+ // Running getBoundingClientRect on a
403+ // disconnected node in IE throws an error
404+ if ( ! elem . getClientRects ( ) . length ) {
405+ return { top : 0 , left : 0 } ;
406+ }
407+
408+ rect = elem . getBoundingClientRect ( ) ;
409+
410+ // Make sure element is not hidden (display: none)
411+ if ( rect . width || rect . height ) {
412+ doc = elem . ownerDocument ;
413+ win = doc !== null && doc === doc . window ? doc : doc . nodeType === 9 && doc . defaultView ;
414+ docElem = doc . documentElement ;
415+
416+ // hack for small chrome screens not position the clicks properly when the page is scrolled
417+ if ( window . chrome && screen . width <= 768 ) {
418+ return {
419+ top : rect . top - docElem . clientTop ,
420+ left : rect . left - docElem . clientLeft
421+ } ;
397422 }
398- }
399-
400- return false ;
401- } ;
402-
403- $scope . offset = function ( el , type ) {
404- var offset ,
405- x = 0 ,
406- y = 0 ,
407- body = document . documentElement || document . body ;
408423
409- if ( el . length === 0 ) {
410- return null ;
411- }
412-
413- x = el [ 0 ] . getBoundingClientRect ( ) . left + ( window . pageXOffset || body . scrollLeft ) ;
414- y = el [ 0 ] . getBoundingClientRect ( ) . top + ( window . pageYOffset || body . scrollTop ) ;
415-
416- offset = { left : x , top :y } ;
424+ return {
425+ top : rect . top + win . pageYOffset - docElem . clientTop ,
426+ left : rect . left + win . pageXOffset - docElem . clientLeft
427+ } ;
428+ }
417429
418- if ( type !== undefined ) {
419- return offset [ type ] ;
420- }
421430
422- return offset ;
431+ return rect ;
423432 } ;
424433
425434
426435 $scope . init ( ) ;
436+
437+ $scope . $on ( '$destroy' , function ( ) {
438+ $document . off ( 'click' ) ;
439+ } ) ;
427440 }
428441 } ;
429442 } ;
0 commit comments