@@ -18,7 +18,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
18
18
shortcutPropagation : false
19
19
} )
20
20
21
- . controller ( 'DatepickerController' , [ '$scope' , '$attrs' , '$parse' , '$interpolate' , '$timeout' , '$ log', 'dateFilter' , 'datepickerConfig' , function ( $scope , $attrs , $parse , $interpolate , $timeout , $log , dateFilter , datepickerConfig ) {
21
+ . controller ( 'DatepickerController' , [ '$scope' , '$attrs' , '$parse' , '$interpolate' , '$log' , 'dateFilter' , 'datepickerConfig' , function ( $scope , $attrs , $parse , $interpolate , $log , dateFilter , datepickerConfig ) {
22
22
var self = this ,
23
23
ngModelCtrl = { $setViewValue : angular . noop } ; // nullModelCtrl;
24
24
@@ -161,9 +161,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
161
161
$scope . keys = { 13 :'enter' , 32 :'space' , 33 :'pageup' , 34 :'pagedown' , 35 :'end' , 36 :'home' , 37 :'left' , 38 :'up' , 39 :'right' , 40 :'down' } ;
162
162
163
163
var focusElement = function ( ) {
164
- $timeout ( function ( ) {
165
- self . element [ 0 ] . focus ( ) ;
166
- } , 0 , false ) ;
164
+ self . element [ 0 ] . focus ( ) ;
167
165
} ;
168
166
169
167
// Listen for focus requests from popup directive
@@ -460,8 +458,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
460
458
showButtonBar : true
461
459
} )
462
460
463
- . directive ( 'datepickerPopup' , [ '$compile' , '$parse' , '$document' , '$position' , 'dateFilter' , 'dateParser' , 'datepickerPopupConfig' ,
464
- function ( $compile , $parse , $document , $position , dateFilter , dateParser , datepickerPopupConfig ) {
461
+ . directive ( 'datepickerPopup' , [ '$compile' , '$parse' , '$document' , '$position' , 'dateFilter' , 'dateParser' , 'datepickerPopupConfig' , '$timeout' ,
462
+ function ( $compile , $parse , $document , $position , dateFilter , dateParser , datepickerPopupConfig , $timeout ) {
465
463
return {
466
464
restrict : 'EA' ,
467
465
require : 'ngModel' ,
@@ -517,7 +515,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
517
515
var popupEl = angular . element ( '<div datepicker-popup-wrap><div datepicker></div></div>' ) ;
518
516
popupEl . attr ( {
519
517
'ng-model' : 'date' ,
520
- 'ng-change' : 'dateSelection()'
518
+ 'ng-change' : 'dateSelection(date )'
521
519
} ) ;
522
520
523
521
function cameltoDash ( string ) {
@@ -661,30 +659,41 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
661
659
}
662
660
} ;
663
661
664
- var keydown = function ( evt , noApply ) {
665
- scope . keydown ( evt ) ;
662
+ var inputKeydownBind = function ( evt ) {
663
+ if ( evt . which === 27 && scope . isOpen ) {
664
+ evt . preventDefault ( ) ;
665
+ evt . stopPropagation ( ) ;
666
+ scope . $apply ( function ( ) {
667
+ scope . isOpen = false ;
668
+ } ) ;
669
+ element [ 0 ] . focus ( ) ;
670
+ } else if ( evt . which === 40 && ! scope . isOpen ) {
671
+ evt . preventDefault ( ) ;
672
+ evt . stopPropagation ( ) ;
673
+ scope . $apply ( function ( ) {
674
+ scope . isOpen = true ;
675
+ } ) ;
676
+ }
666
677
} ;
667
- element . bind ( 'keydown' , keydown ) ;
678
+ element . bind ( 'keydown' , inputKeydownBind ) ;
668
679
669
680
scope . keydown = function ( evt ) {
670
681
if ( evt . which === 27 ) {
671
- evt . preventDefault ( ) ;
672
- if ( scope . isOpen ) {
673
- evt . stopPropagation ( ) ;
674
- }
675
- scope . close ( ) ;
676
- } else if ( evt . which === 40 && ! scope . isOpen ) {
677
- scope . isOpen = true ;
682
+ scope . isOpen = false ;
683
+ element [ 0 ] . focus ( ) ;
678
684
}
679
685
} ;
680
686
681
687
scope . $watch ( 'isOpen' , function ( value ) {
682
688
if ( value ) {
683
- scope . $broadcast ( 'datepicker.focus' ) ;
684
689
scope . position = appendToBody ? $position . offset ( element ) : $position . position ( element ) ;
685
690
scope . position . top = scope . position . top + element . prop ( 'offsetHeight' ) ;
686
691
687
692
$document . bind ( 'click' , documentClickBind ) ;
693
+
694
+ $timeout ( function ( ) {
695
+ scope . $broadcast ( 'datepicker.focus' ) ;
696
+ } , 0 , false ) ;
688
697
} else {
689
698
$document . unbind ( 'click' , documentClickBind ) ;
690
699
}
@@ -719,8 +728,14 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
719
728
}
720
729
721
730
scope . $on ( '$destroy' , function ( ) {
731
+ if ( scope . isOpen === true ) {
732
+ scope . $apply ( function ( ) {
733
+ scope . isOpen = false ;
734
+ } ) ;
735
+ }
736
+
722
737
$popup . remove ( ) ;
723
- element . unbind ( 'keydown' , keydown ) ;
738
+ element . unbind ( 'keydown' , inputKeydownBind ) ;
724
739
$document . unbind ( 'click' , documentClickBind ) ;
725
740
} ) ;
726
741
}
@@ -732,12 +747,6 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
732
747
restrict :'EA' ,
733
748
replace : true ,
734
749
transclude : true ,
735
- templateUrl : 'template/datepicker/popup.html' ,
736
- link :function ( scope , element , attrs ) {
737
- element . bind ( 'click' , function ( event ) {
738
- event . preventDefault ( ) ;
739
- event . stopPropagation ( ) ;
740
- } ) ;
741
- }
750
+ templateUrl : 'template/datepicker/popup.html'
742
751
} ;
743
752
} ) ;
0 commit comments