@@ -417,24 +417,39 @@ colorPicker.directive('colorPicker', ['$document', '$compile', 'ColorHelper', fu
417417 scope . colorPickerModel = initialValue ;
418418 scope . show = false ;
419419 updateFromString ( scope . colorPickerModel ) ;
420- $document . off ( 'mouseup' , mouseup ) ;
421420 $document . off ( 'mousedown' , mousedown ) ;
421+ angular . element ( window ) . off ( 'resize' , resize ) ;
422422 } ;
423423
424424 element . on ( 'click' , open ) ;
425- function open ( event ) {
426- var box ;
425+ function open ( event ) {
427426 initialValue = scope . colorPickerModel ;
428427 scope . $apply ( function ( ) {
429428 scope . show = true ;
429+ } ) ;
430+ scope . $apply ( function ( ) {
431+ scope . sAndLMax = { x : template [ 0 ] . getElementsByClassName ( "saturation-lightness" ) [ 0 ] . offsetWidth , y : template [ 0 ] . getElementsByClassName ( "saturation-lightness" ) [ 0 ] . offsetHeight } ;
432+ scope . hueMax = { x : template [ 0 ] . getElementsByClassName ( "hue" ) [ 0 ] . offsetWidth } ;
433+ scope . alphaMax = { x : template [ 0 ] . getElementsByClassName ( "alpha" ) [ 0 ] . offsetWidth } ;
434+ scope . update ( ) ;
430435 } ) ;
436+ setDialogPosition ( ) ;
437+ $document . on ( 'mousedown' , mousedown ) ;
438+ angular . element ( window ) . on ( 'resize' , resize ) ;
439+ }
440+
441+ function resize ( ) {
442+ setDialogPosition ( ) ;
443+ }
444+
445+ function setDialogPosition ( ) {
446+ var box ;
431447 if ( attr . colorPickerFixedPosition === 'true' ) {
432448 box = createBox ( element [ 0 ] , false ) ;
433449 template [ 0 ] . style . position = "fixed" ;
434450 } else {
435451 box = createBox ( element [ 0 ] , true ) ;
436452 }
437-
438453 if ( attr . colorPickerPosition === "left" ) {
439454 template [ 0 ] . style . top = box . top + 'px' ;
440455 template [ 0 ] . style . left = ( box . left - 252 ) + 'px' ;
@@ -449,17 +464,7 @@ colorPicker.directive('colorPicker', ['$document', '$compile', 'ColorHelper', fu
449464 template [ 0 ] . style . top = box . top + 'px' ;
450465 template [ 0 ] . style . left = ( box . left + box . width ) + 'px' ;
451466 }
452-
453- scope . $apply ( function ( ) {
454- scope . sAndLMax = { x : template [ 0 ] . getElementsByClassName ( "saturation-lightness" ) [ 0 ] . offsetWidth , y : template [ 0 ] . getElementsByClassName ( "saturation-lightness" ) [ 0 ] . offsetHeight } ;
455- scope . hueMax = { x : template [ 0 ] . getElementsByClassName ( "hue" ) [ 0 ] . offsetWidth } ;
456- scope . alphaMax = { x : template [ 0 ] . getElementsByClassName ( "alpha" ) [ 0 ] . offsetWidth } ;
457- scope . update ( ) ;
458- } ) ;
459-
460- $document . on ( 'mousedown' , mousedown ) ;
461- $document . on ( 'mouseup' , mouseup ) ;
462- }
467+ }
463468
464469 element . on ( '$destroy' , function ( ) {
465470 element . off ( 'click' , open ) ;
@@ -468,23 +473,12 @@ colorPicker.directive('colorPicker', ['$document', '$compile', 'ColorHelper', fu
468473 } ) ;
469474
470475 function mousedown ( event ) {
471- if ( event . target . tagName !== "INPUT" && event . target . tagName !== 'HTML' ) {
472- event . preventDefault ( ) ;
473- }
474- if ( template [ 0 ] === event . target || isDescendant ( template [ 0 ] , event . target ) || event . target . tagName === 'HTML' ) {
475- close = false ;
476- } else {
477- close = true ;
478- }
479- }
480-
481- function mouseup ( event ) {
482- if ( close && event . target !== element [ 0 ] && template [ 0 ] !== event . target && ! isDescendant ( template [ 0 ] , event . target ) ) {
476+ if ( event . target !== element [ 0 ] && template [ 0 ] !== event . target && ! isDescendant ( template [ 0 ] , event . target ) ) {
483477 scope . $apply ( function ( ) {
484478 scope . show = false ;
485479 } ) ;
486- $document . off ( 'mouseup' , mouseup ) ;
487480 $document . off ( 'mousedown' , mousedown ) ;
481+ angular . element ( window ) . off ( 'resize' , resize ) ;
488482 }
489483 }
490484
@@ -515,7 +509,7 @@ colorPicker.directive('text', [function () {
515509 scope : {
516510 action : '&'
517511 } ,
518- link : function ( scope , element , attr , ngModel ) {
512+ link : function ( scope , element , attr ) {
519513 element . on ( 'paste' , delayedUpdate ) ;
520514 element . on ( 'keyup' , update ) ;
521515 element . on ( 'change' , update ) ;
@@ -577,15 +571,16 @@ colorPicker.directive('slider', ['$document', '$window', function ($document, $w
577571 action : '&'
578572 } ,
579573 link : function ( scope , element , attr ) {
580- element . on ( 'mousedown' , mousedown ) ;
574+ element . on ( 'mousedown touchstart ' , mousedown ) ;
581575 function mousedown ( event ) {
582576 setCursor ( event ) ;
583- $document . on ( 'mousemove' , mousemove ) ;
577+ $document . on ( 'mousemove touchmove ' , mousemove ) ;
584578 }
585- $document . on ( 'mouseup' , function ( ) {
586- $document . off ( 'mousemove' , mousemove ) ;
579+ $document . on ( 'mouseup touchend ' , function ( ) {
580+ $document . off ( 'mousemove touchmove ' , mousemove ) ;
587581 } ) ;
588582 function mousemove ( event ) {
583+ event . preventDefault ( ) ;
589584 setCursor ( event ) ;
590585 }
591586
@@ -605,13 +600,13 @@ colorPicker.directive('slider', ['$document', '$window', function ($document, $w
605600 }
606601
607602 function getX ( event , element ) {
608- return event . pageX - element . getBoundingClientRect ( ) . left - $window . pageXOffset ;
603+ return ( event . pageX !== undefined ? event . pageX : event . touches [ 0 ] . pageX ) - element . getBoundingClientRect ( ) . left - $window . pageXOffset ;
609604 }
610605 function getY ( event , element ) {
611- return event . pageY - element . getBoundingClientRect ( ) . top - $window . pageYOffset ;
606+ return ( event . pageY !== undefined ? event . pageY : event . touches [ 0 ] . pageY ) - element . getBoundingClientRect ( ) . top - $window . pageYOffset ;
612607 }
613608 element . on ( '$destroy' , function ( ) {
614- element . off ( 'mousedown' , mousedown ) ;
609+ element . off ( 'mousedown touchend ' , mousedown ) ;
615610 } ) ;
616611 } } ;
617612 } ] ) ;
0 commit comments