diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 88f9a9a3f0..d533b6ddce 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -771,50 +771,26 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $ this.init = function(_ngModel_) { ngModel = _ngModel_; ngModelOptions = _ngModel_.$options || datepickerConfig.ngModelOptions; - if (angular.isDefined($scope.datepickerOptions)) { - closeOnDateSelection = angular.isDefined($scope.datepickerOptions.closeOnDateSelection) ? - $scope.datepickerOptions.closeOnDateSelection : - datepickerPopupConfig.closeOnDateSelection; - appendToBody = angular.isDefined($scope.datepickerOptions.datepickerAppendToBody) ? - $scope.datepickerOptions.datepickerAppendToBody : - datepickerPopupConfig.datepickerAppendToBody; - onOpenFocus = angular.isDefined($scope.datepickerOptions.onOpenFocus) ? - $scope.datepickerOptions.onOpenFocus : - datepickerPopupConfig.onOpenFocus; - datepickerPopupTemplateUrl = angular.isDefined($scope.datepickerOptions.datepickerPopupTemplateUrl) ? - $scope.datepickerOptions.datepickerPopupTemplateUrl : - datepickerPopupConfig.datepickerPopupTemplateUrl; - datepickerTemplateUrl = angular.isDefined($scope.datepickerOptions.datepickerTemplateUrl) ? - $scope.datepickerOptions.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl; - altInputFormats = angular.isDefined($scope.datepickerOptions.altInputFormats) ? - $scope.datepickerOptions.altInputFormats : - datepickerPopupConfig.altInputFormats; - } else { - if (datepickerPopupAttributeWarning) { - $log.warn('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - } - - closeOnDateSelection = angular.isDefined($attrs.closeOnDateSelection) ? - $scope.$parent.$eval($attrs.closeOnDateSelection) : - datepickerPopupConfig.closeOnDateSelection; - appendToBody = angular.isDefined($attrs.datepickerAppendToBody) ? - $scope.$parent.$eval($attrs.datepickerAppendToBody) : - datepickerPopupConfig.appendToBody; - onOpenFocus = angular.isDefined($attrs.onOpenFocus) ? - $scope.$parent.$eval($attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus; - datepickerPopupTemplateUrl = angular.isDefined($attrs.datepickerPopupTemplateUrl) ? - $attrs.datepickerPopupTemplateUrl : - datepickerPopupConfig.datepickerPopupTemplateUrl; - datepickerTemplateUrl = angular.isDefined($attrs.datepickerTemplateUrl) ? - $attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl; - altInputFormats = angular.isDefined($attrs.altInputFormats) ? - $scope.$parent.$eval($attrs.altInputFormats) : - datepickerPopupConfig.altInputFormats; - - $scope.showButtonBar = angular.isDefined($attrs.showButtonBar) ? - $scope.$parent.$eval($attrs.showButtonBar) : - datepickerPopupConfig.showButtonBar; - } + closeOnDateSelection = angular.isDefined($attrs.closeOnDateSelection) ? + $scope.$parent.$eval($attrs.closeOnDateSelection) : + datepickerPopupConfig.closeOnDateSelection; + appendToBody = angular.isDefined($attrs.datepickerAppendToBody) ? + $scope.$parent.$eval($attrs.datepickerAppendToBody) : + datepickerPopupConfig.appendToBody; + onOpenFocus = angular.isDefined($attrs.onOpenFocus) ? + $scope.$parent.$eval($attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus; + datepickerPopupTemplateUrl = angular.isDefined($attrs.datepickerPopupTemplateUrl) ? + $attrs.datepickerPopupTemplateUrl : + datepickerPopupConfig.datepickerPopupTemplateUrl; + datepickerTemplateUrl = angular.isDefined($attrs.datepickerTemplateUrl) ? + $attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl; + altInputFormats = angular.isDefined($attrs.altInputFormats) ? + $scope.$parent.$eval($attrs.altInputFormats) : + datepickerPopupConfig.altInputFormats; + + $scope.showButtonBar = angular.isDefined($attrs.showButtonBar) ? + $scope.$parent.$eval($attrs.showButtonBar) : + datepickerPopupConfig.showButtonBar; if (datepickerPopupConfig.html5Types[$attrs.type]) { dateFormat = datepickerPopupConfig.html5Types[$attrs.type]; diff --git a/src/datepicker/docs/demo.html b/src/datepicker/docs/demo.html index e400c1ccb9..0d5cf1b9a3 100644 --- a/src/datepicker/docs/demo.html +++ b/src/datepicker/docs/demo.html @@ -15,33 +15,33 @@

Inline

- +

Popup

-
-

- - - - -

-
+
+

+ + + + +

+
-
-

- - - - -

-
+
+

+ + + + +

+
-
- -
+
+ +

diff --git a/src/datepicker/docs/demo.js b/src/datepicker/docs/demo.js index aac7f0b2d3..cf81c2bf80 100644 --- a/src/datepicker/docs/demo.js +++ b/src/datepicker/docs/demo.js @@ -8,17 +8,33 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($ $scope.dt = null; }; + $scope.inlineOptions = { + customClass: getDayClass, + minDate: new Date(), + showWeeks: true + }; + + $scope.dateOptions = { + dateDisabled: disabled, + formatYear: 'yy', + maxDate: new Date(2020, 5, 22), + minDate: new Date(), + startingDay: 1 + }; + // Disable weekend selection - $scope.disabled = function(date, mode) { + function disabled(data) { + var date = data.date, + mode = data.mode; return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6); - }; + } $scope.toggleMin = function() { - $scope.minDate = $scope.minDate ? null : new Date(); + $scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date(); + $scope.dateOptions.minDate = $scope.inlineOptions.minDate; }; $scope.toggleMin(); - $scope.maxDate = new Date(2020, 5, 22); $scope.open1 = function() { $scope.popup1.opened = true; @@ -32,11 +48,6 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($ $scope.dt = new Date(year, month, day); }; - $scope.dateOptions = { - formatYear: 'yy', - startingDay: 1 - }; - $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate']; $scope.format = $scope.formats[0]; $scope.altInputFormats = ['M!/d!/yyyy']; @@ -53,19 +64,20 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($ tomorrow.setDate(tomorrow.getDate() + 1); var afterTomorrow = new Date(); afterTomorrow.setDate(tomorrow.getDate() + 1); - $scope.events = - [ - { - date: tomorrow, - status: 'full' - }, - { - date: afterTomorrow, - status: 'partially' - } - ]; + $scope.events = [ + { + date: tomorrow, + status: 'full' + }, + { + date: afterTomorrow, + status: 'partially' + } + ]; - $scope.getDayClass = function(date, mode) { + function getDayClass(data) { + var date = data.date, + mode = data.mode; if (mode === 'day') { var dayToCheck = new Date(date).setHours(0,0,0,0); @@ -79,5 +91,5 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($ } return ''; - }; + } }); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index e20b02e885..01e9860e62 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -968,76 +968,6 @@ describe('datepicker', function() { expect($log.warn).not.toHaveBeenCalled(); }); - it('should log warning for closeOnDateSelection attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for closeOnDateSelection attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for appendToBody attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for appendToBody attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - it('should log warning for customClass attribute usage', function() { inject(function(_$log_, _$rootScope_, _$compile_) { $log = _$log_; @@ -1108,183 +1038,6 @@ describe('datepicker', function() { expect($log.warn).not.toHaveBeenCalled(); }); - it('should log warning for onOpenFocus attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for onOpenFocus attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for datepickerPopupTemplateUrl attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for datepickerPopupTemplateUrl attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for datepickerTemplateUrl attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for datepickerTemplateUrl attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for altInputFormats attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.formats = []; - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for altInputFormats attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - $scope.formats = []; - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - - it('should log warning for showButtonBar attribute usage', function() { - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).toHaveBeenCalledWith('uib-datepicker-popup attributes are deprecated and will be removed in UI Bootstrap 1.3, use datepicker-options attribute instead'); - }); - - it('should suppress warning for showButtonBar attribute usage', function() { - module(function($provide) { - $provide.value('uibDatepickerPopupAttributeWarning', false); - }); - inject(function(_$log_, _$rootScope_, _$compile_) { - $log = _$log_; - $scope = _$rootScope_.$new(); - $compile = _$compile_; - }); - - $scope.date = new Date(); - - spyOn($log, 'warn'); - element = $compile('
')($scope); - $scope.$digest(); - - expect($log.warn).not.toHaveBeenCalled(); - }); - it('should log warning for minMode attribute usage', function() { inject(function(_$log_, _$rootScope_, _$compile_) { $log = _$log_;