@@ -75,6 +75,14 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
75
75
this . activeDate = new Date ( ) ;
76
76
}
77
77
78
+ $scope . disabled = angular . isDefined ( $attrs . disabled ) || false ;
79
+ if ( angular . isDefined ( $attrs . ngDisabled ) ) {
80
+ $scope . $parent . $watch ( $parse ( $attrs . ngDisabled ) , function ( disabled ) {
81
+ $scope . disabled = disabled ;
82
+ self . refreshView ( ) ;
83
+ } ) ;
84
+ }
85
+
78
86
$scope . isActive = function ( dateObject ) {
79
87
if ( self . compare ( dateObject . date , self . activeDate ) === 0 ) {
80
88
$scope . activeDateId = dateObject . uid ;
@@ -127,7 +135,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
127
135
} ;
128
136
129
137
this . isDisabled = function ( date ) {
130
- return ( ( this . minDate && this . compare ( date , this . minDate ) < 0 ) || ( this . maxDate && this . compare ( date , this . maxDate ) > 0 ) || ( $attrs . dateDisabled && $scope . dateDisabled ( { date : date , mode : $scope . datepickerMode } ) ) ) ;
138
+ return $scope . disabled || ( ( this . minDate && this . compare ( date , this . minDate ) < 0 ) || ( this . maxDate && this . compare ( date , this . maxDate ) > 0 ) || ( $attrs . dateDisabled && $scope . dateDisabled ( { date : date , mode : $scope . datepickerMode } ) ) ) ;
131
139
} ;
132
140
133
141
this . customClass = function ( date ) {
@@ -185,7 +193,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
185
193
$scope . keydown = function ( evt ) {
186
194
var key = $scope . keys [ evt . which ] ;
187
195
188
- if ( ! key || evt . shiftKey || evt . altKey ) {
196
+ if ( ! key || evt . shiftKey || evt . altKey || $scope . disabled ) {
189
197
return ;
190
198
}
191
199
@@ -626,6 +634,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
626
634
}
627
635
}
628
636
} ) ;
637
+
629
638
if ( attrs . dateDisabled ) {
630
639
datepickerEl . attr ( 'date-disabled' , 'dateDisabled({ date: date, mode: mode })' ) ;
631
640
}
@@ -743,17 +752,28 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
743
752
element [ 0 ] . focus ( ) ;
744
753
} ;
745
754
755
+ scope . disabled = angular . isDefined ( attrs . disabled ) || false ;
756
+ if ( attrs . ngDisabled ) {
757
+ scope . $parent . $watch ( $parse ( attrs . ngDisabled ) , function ( disabled ) {
758
+ scope . disabled = disabled ;
759
+ } ) ;
760
+ }
761
+
746
762
scope . $watch ( 'isOpen' , function ( value ) {
747
763
if ( value ) {
748
- scope . position = appendToBody ? $position . offset ( element ) : $position . position ( element ) ;
749
- scope . position . top = scope . position . top + element . prop ( 'offsetHeight' ) ;
764
+ if ( ! scope . disabled ) {
765
+ scope . position = appendToBody ? $position . offset ( element ) : $position . position ( element ) ;
766
+ scope . position . top = scope . position . top + element . prop ( 'offsetHeight' ) ;
750
767
751
- $timeout ( function ( ) {
752
- if ( onOpenFocus ) {
753
- scope . $broadcast ( 'uib:datepicker.focus' ) ;
754
- }
755
- $document . bind ( 'click' , documentClickBind ) ;
756
- } , 0 , false ) ;
768
+ $timeout ( function ( ) {
769
+ if ( onOpenFocus ) {
770
+ scope . $broadcast ( 'uib:datepicker.focus' ) ;
771
+ }
772
+ $document . bind ( 'click' , documentClickBind ) ;
773
+ } , 0 , false ) ;
774
+ } else {
775
+ scope . isOpen = false ;
776
+ }
757
777
} else {
758
778
$document . unbind ( 'click' , documentClickBind ) ;
759
779
}
@@ -808,6 +828,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
808
828
}
809
829
810
830
function documentClickBind ( event ) {
831
+ if ( ! scope . isOpen && scope . disabled ) {
832
+ return ;
833
+ }
834
+
811
835
var popup = $popup [ 0 ] ;
812
836
var dpContainsTarget = element [ 0 ] . contains ( event . target ) ;
813
837
// The popup node may not be an element node
0 commit comments