diff --git a/bower.json b/bower.json index 69cf48c..43cf733 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.2.1", + "version": "2.2.2", "homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo " diff --git a/datetime-picker.js b/datetime-picker.js index f3cbfc9..56241ad 100644 --- a/datetime-picker.js +++ b/datetime-picker.js @@ -325,6 +325,12 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo $timeout(function() { scope.showPicker = 'time'; }, 0); + + // in order to update the timePicker, we need to update the model reference! + // as found here https://angular-ui.github.io/bootstrap/#/timepicker + $timeout(function() { + scope.date = new Date(scope.date); + }, 100); } else { scope.close(false); } diff --git a/dist/datetime-picker.js b/dist/datetime-picker.js index 275962d..759e5b0 100644 --- a/dist/datetime-picker.js +++ b/dist/datetime-picker.js @@ -1,6 +1,6 @@ // https://github.com/Gillardo/bootstrap-ui-datetime-picker -// Version: 2.2.1 -// Released: 2016-03-03 +// Version: 2.2.2 +// Released: 2016-03-04 angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) .constant('uiDatetimePickerConfig', { dateFormat: 'yyyy-MM-dd HH:mm', @@ -10,6 +10,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo 'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss', 'month': 'yyyy-MM' }, + initialPicker: 'date', + reOpenDefault: false, enableDate: true, enableTime: true, buttonBar: { @@ -63,8 +65,19 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.enableDate = angular.isDefined(scope.enableDate) ? scope.enableDate : uiDatetimePickerConfig.enableDate; scope.enableTime = angular.isDefined(scope.enableTime) ? scope.enableTime : uiDatetimePickerConfig.enableTime; + // determine default picker + scope.initialPicker = angular.isDefined(attrs.initialPicker) ? attrs.initialPicker : (scope.enableDate ? uiDatetimePickerConfig.initialPicker : 'time'); + + // determine the picker to open when control is re-opened + scope.reOpenDefault = angular.isDefined(attrs.reOpenDefault) ? attrs.reOpenDefault : uiDatetimePickerConfig.reOpenDefault; + + // check if an illegal combination of options exists + if (scope.initialPicker == 'date' && !scope.enableDate) { + throw new Error("datetimePicker can't have initialPicker set to date and have enableDate set to false."); + } + // default picker view - scope.showPicker = scope.enableDate ? 'date' : 'time'; + scope.showPicker = !scope.enableDate ? 'time' : scope.initialPicker; var isHtml5DateInput = false; @@ -315,6 +328,12 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo $timeout(function() { scope.showPicker = 'time'; }, 0); + + // in order to update the timePicker, we need to update the model reference! + // as found here https://angular-ui.github.io/bootstrap/#/timepicker + $timeout(function() { + scope.date = new Date(scope.date); + }, 100); } else { scope.close(false); } @@ -397,7 +416,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo // if enableDate and enableTime are true, reopen the picker in date mode first if (scope.enableDate && scope.enableTime) - scope.showPicker = 'date'; + scope.showPicker = scope.reOpenDefault === false ? 'date' : scope.reOpenDefault; // if a on-close-fn has been defined, lets call it // we only call this if closePressed is defined! @@ -534,6 +553,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo isOpen: '=?', enableDate: '=?', enableTime: '=?', + initialPicker: '=?', + reOpenDefault: '=?', dateDisabled: '&', customClass: '&', whenClosed: '&' diff --git a/dist/datetime-picker.min.js b/dist/datetime-picker.min.js index a0a32f8..d2d313b 100644 --- a/dist/datetime-picker.min.js +++ b/dist/datetime-picker.min.js @@ -1,4 +1,4 @@ // https://github.com/Gillardo/bootstrap-ui-datetime-picker -// Version: 2.2.1 -// Released: 2016-03-03 -angular.module("ui.bootstrap.datetimepicker",["ui.bootstrap.dateparser","ui.bootstrap.position"]).constant("uiDatetimePickerConfig",{dateFormat:"yyyy-MM-dd HH:mm",defaultTime:"00:00:00",html5Types:{date:"yyyy-MM-dd","datetime-local":"yyyy-MM-ddTHH:mm:ss.sss",month:"yyyy-MM"},enableDate:!0,enableTime:!0,buttonBar:{show:!0,now:{show:!0,text:"Now"},today:{show:!0,text:"Today"},clear:{show:!0,text:"Clear"},date:{show:!0,text:"Date"},time:{show:!0,text:"Time"},close:{show:!0,text:"Close"}},closeOnDateSelection:!0,appendToBody:!1,altInputFormats:[],ngModelOptions:{}}).controller("DateTimePickerController",["$scope","$element","$attrs","$compile","$parse","$document","$timeout","$uibPosition","dateFilter","uibDateParser","uiDatetimePickerConfig","$rootScope",function(a,b,c,d,e,f,g,h,i,j,k,l){function m(c){var d=u[0],e=b[0].contains(c.target),f=void 0!==d.contains&&d.contains(c.target);!a.isOpen||e||f||a.$apply(function(){a.close(!1)})}function n(c){27===c.which&&a.isOpen?(c.preventDefault(),c.stopPropagation(),a.$apply(function(){a.close(!1)}),b[0].focus()):40!==c.which||a.isOpen||(c.preventDefault(),c.stopPropagation(),a.$apply(function(){a.isOpen=!0}))}function o(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function p(b){var c=j.parse(b,v,a.date);if(isNaN(c))for(var d=0;d
');a.ngModelOptions=angular.copy(t),a.ngModelOptions.timezone=null,l.attr({"ng-model":"date","ng-model-options":"ngModelOptions","ng-change":"dateSelection(date)"});var m=angular.element(l.children()[0]);if(h&&"month"===c.type&&(m.attr("datepicker-mode",'"month"'),m.attr("min-mode","month")),c.datepickerOptions){var w=a.$parent.$eval(c.datepickerOptions);w&&w.initDate&&(a.initDate=j.fromTimezone(w.initDate,t.timezone),m.attr("init-date","initDate"),delete w.initDate),angular.forEach(w,function(a,b){m.attr(o(b),a)})}angular.isDefined(c.datepickerMode)||(c.datepickerMode="day"),c.dateDisabled&&m.attr("date-disabled","dateDisabled({ date: date, mode: mode })"),angular.forEach(["formatDay","formatMonth","formatYear","formatDayHeader","formatDayTitle","formatMonthTitle","showWeeks","startingDay","yearRows","yearColumns"],function(a){angular.isDefined(c[a])&&m.attr(o(a),c[a])}),c.customClass&&m.attr("custom-class","customClass({ date: date, mode: mode })"),angular.forEach(["minMode","maxMode","datepickerMode","shortcutPropagation"],function(b){if(c[b]){var d=e(c[b]);if(x.push(a.$parent.$watch(d,function(c){a.watchData[b]=c})),m.attr(o(b),"watchData."+b),"datepickerMode"===b){var f=d.assign;x.push(a.$watch("watchData."+b,function(b,c){angular.isFunction(f)&&b!==c&&f(a.$parent,b)}))}}});var y=angular.element(l.children()[1]);if(c.timepickerOptions){var w=a.$parent.$eval(c.timepickerOptions);angular.forEach(w,function(b,c){a.watchData[c]=b,y.attr(o(c),"watchData."+c)})}angular.forEach(["minDate","maxDate","initDate"],function(b){if(c[b]){var d=e(c[b]);x.push(a.$parent.$watch(d,function(c){a.watchData[b]=c})),m.attr(o(b),"watchData."+b),"minDate"==b?y.attr("min","watchData.minDate"):"maxDate"==b&&y.attr("max","watchData.maxDate")}}),h?s.$formatters.push(function(b){return a.date=j.fromTimezone(b,t.timezone),b}):(s.$$parserName="datetime",s.$validators.datetime=r,s.$parsers.unshift(q),s.$formatters.push(function(b){return s.$isEmpty(b)?(a.date=b,b):(a.date=j.fromTimezone(b,t.timezone),v=v.replace(/M!/,"MM").replace(/d!/,"dd"),i(a.date,v))})),s.$viewChangeListeners.push(function(){a.date=p(s.$viewValue)}),b.bind("keydown",n),u=d(l)(a),l.remove(),z?f.find("body").append(u):b.after(u)},a.getText=function(b){return a.buttonBar[b].text||k.buttonBar[b].text},a.doShow=function(b){return angular.isDefined(a.buttonBar[b].show)?a.buttonBar[b].show:k.buttonBar[b].show},a.dateSelection=function(d){if(a.enableTime&&"time"===a.showPicker&&(d||null!=d)&&(angular.isDefined(a.date)&&null!=a.date||(a.date=new Date),d&&null!=d)){var e=new Date(a.date);e.setHours(d.getHours()),e.setMinutes(d.getMinutes()),e.setSeconds(d.getSeconds()),e.setMilliseconds(d.getMilliseconds()),d=e}if(angular.isDefined(d)){if(!a.date){var f=angular.isDefined(c.defaultTime)?c.defaultTime:k.defaultTime,h=new Date("2001-01-01 "+f);isNaN(h)||null==d||(d.setHours(h.getHours()),d.setMinutes(h.getMinutes()),d.setSeconds(h.getSeconds()),d.setMilliseconds(h.getMilliseconds()))}a.date=d}var e=a.date?i(a.date,v,t.timezone):null;b.val(e),s.$setViewValue(e),y&&"time"!=a.showPicker&&null!=e&&(a.enableTime?g(function(){a.showPicker="time"},0):a.close(!1))},a.keydown=function(c){27===c.which&&(a.close(!1),b[0].focus())},a.$watch("isOpen",function(c){if(a.dropdownStyle={display:c?"block":"none"},c){w.openDate=a.date;var d=z?h.offset(b):h.position(b);z?a.dropdownStyle.top=d.top+b.prop("offsetHeight")+"px":a.dropdownStyle.top=void 0,a.dropdownStyle.left=d.left+"px",g(function(){a.$broadcast("uib:datepicker.focus"),f.bind("click",m)},0,!1)}else f.unbind("click",m)}),a.isDisabled=function(b){return("today"===b||"now"===b)&&(b=new Date),a.watchData.minDate&&a.compare(b,a.watchData.minDate)<0||a.watchData.maxDate&&a.compare(b,a.watchData.maxDate)>0},a.compare=function(a,b){return new Date(a.getFullYear(),a.getMonth(),a.getDate())-new Date(b.getFullYear(),b.getMonth(),b.getDate())},a.select=function(b){var c=null;if("today"===b||"now"==b){var d=new Date;angular.isDate(a.date)?(c=new Date(a.date),c.setFullYear(d.getFullYear(),d.getMonth(),d.getDate()),c.setHours(d.getHours(),d.getMinutes(),d.getSeconds(),d.getMilliseconds())):c=d}a.dateSelection(c),"clear"==b&&a.close()},a.close=function(c){a.isOpen=!1,a.enableDate&&a.enableTime&&(a.showPicker="date"),angular.isDefined(c)&&a.whenClosed({args:{closePressed:c,openDate:w.openDate||null,closeDate:a.date}}),b[0].focus()},a.changePicker=function(b,c){b.preventDefault(),b.stopPropagation(),a.showPicker=c},a.$on("$destroy",function(){a.isOpen===!0&&(l.$$phase||a.$apply(function(){a.close()})),x.forEach(function(a){a()}),u.remove(),b.unbind("keydown",n),f.unbind("click",m)})}]).directive("datetimePicker",function(){return{restrict:"A",require:["ngModel","datetimePicker"],controller:"DateTimePickerController",scope:{isOpen:"=?",enableDate:"=?",enableTime:"=?",dateDisabled:"&",customClass:"&",whenClosed:"&"},link:function(a,b,c,d){var e=d[0],f=d[1];f.init(e)}}}).directive("datePickerWrap",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/date-picker.html"}}).directive("timePickerWrap",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/time-picker.html"}}),angular.module("ui.bootstrap.datetimepicker").run(["$templateCache",function(a){"use strict";a.put("template/date-picker.html",''),a.put("template/time-picker.html",'')}]); \ No newline at end of file +// Version: 2.2.2 +// Released: 2016-03-04 +angular.module("ui.bootstrap.datetimepicker",["ui.bootstrap.dateparser","ui.bootstrap.position"]).constant("uiDatetimePickerConfig",{dateFormat:"yyyy-MM-dd HH:mm",defaultTime:"00:00:00",html5Types:{date:"yyyy-MM-dd","datetime-local":"yyyy-MM-ddTHH:mm:ss.sss",month:"yyyy-MM"},initialPicker:"date",reOpenDefault:!1,enableDate:!0,enableTime:!0,buttonBar:{show:!0,now:{show:!0,text:"Now"},today:{show:!0,text:"Today"},clear:{show:!0,text:"Clear"},date:{show:!0,text:"Date"},time:{show:!0,text:"Time"},close:{show:!0,text:"Close"}},closeOnDateSelection:!0,appendToBody:!1,altInputFormats:[],ngModelOptions:{}}).controller("DateTimePickerController",["$scope","$element","$attrs","$compile","$parse","$document","$timeout","$uibPosition","dateFilter","uibDateParser","uiDatetimePickerConfig","$rootScope",function(a,b,c,d,e,f,g,h,i,j,k,l){function m(c){var d=u[0],e=b[0].contains(c.target),f=void 0!==d.contains&&d.contains(c.target);!a.isOpen||e||f||a.$apply(function(){a.close(!1)})}function n(c){27===c.which&&a.isOpen?(c.preventDefault(),c.stopPropagation(),a.$apply(function(){a.close(!1)}),b[0].focus()):40!==c.which||a.isOpen||(c.preventDefault(),c.stopPropagation(),a.$apply(function(){a.isOpen=!0}))}function o(a){return a.replace(/([A-Z])/g,function(a){return"-"+a.toLowerCase()})}function p(b){var c=j.parse(b,v,a.date);if(isNaN(c))for(var d=0;d
');a.ngModelOptions=angular.copy(t),a.ngModelOptions.timezone=null,l.attr({"ng-model":"date","ng-model-options":"ngModelOptions","ng-change":"dateSelection(date)"});var m=angular.element(l.children()[0]);if(h&&"month"===c.type&&(m.attr("datepicker-mode",'"month"'),m.attr("min-mode","month")),c.datepickerOptions){var w=a.$parent.$eval(c.datepickerOptions);w&&w.initDate&&(a.initDate=j.fromTimezone(w.initDate,t.timezone),m.attr("init-date","initDate"),delete w.initDate),angular.forEach(w,function(a,b){m.attr(o(b),a)})}angular.isDefined(c.datepickerMode)||(c.datepickerMode="day"),c.dateDisabled&&m.attr("date-disabled","dateDisabled({ date: date, mode: mode })"),angular.forEach(["formatDay","formatMonth","formatYear","formatDayHeader","formatDayTitle","formatMonthTitle","showWeeks","startingDay","yearRows","yearColumns"],function(a){angular.isDefined(c[a])&&m.attr(o(a),c[a])}),c.customClass&&m.attr("custom-class","customClass({ date: date, mode: mode })"),angular.forEach(["minMode","maxMode","datepickerMode","shortcutPropagation"],function(b){if(c[b]){var d=e(c[b]);if(x.push(a.$parent.$watch(d,function(c){a.watchData[b]=c})),m.attr(o(b),"watchData."+b),"datepickerMode"===b){var f=d.assign;x.push(a.$watch("watchData."+b,function(b,c){angular.isFunction(f)&&b!==c&&f(a.$parent,b)}))}}});var y=angular.element(l.children()[1]);if(c.timepickerOptions){var w=a.$parent.$eval(c.timepickerOptions);angular.forEach(w,function(b,c){a.watchData[c]=b,y.attr(o(c),"watchData."+c)})}angular.forEach(["minDate","maxDate","initDate"],function(b){if(c[b]){var d=e(c[b]);x.push(a.$parent.$watch(d,function(c){a.watchData[b]=c})),m.attr(o(b),"watchData."+b),"minDate"==b?y.attr("min","watchData.minDate"):"maxDate"==b&&y.attr("max","watchData.maxDate")}}),h?s.$formatters.push(function(b){return a.date=j.fromTimezone(b,t.timezone),b}):(s.$$parserName="datetime",s.$validators.datetime=r,s.$parsers.unshift(q),s.$formatters.push(function(b){return s.$isEmpty(b)?(a.date=b,b):(a.date=j.fromTimezone(b,t.timezone),v=v.replace(/M!/,"MM").replace(/d!/,"dd"),i(a.date,v))})),s.$viewChangeListeners.push(function(){a.date=p(s.$viewValue)}),b.bind("keydown",n),u=d(l)(a),l.remove(),z?f.find("body").append(u):b.after(u)},a.getText=function(b){return a.buttonBar[b].text||k.buttonBar[b].text},a.doShow=function(b){return angular.isDefined(a.buttonBar[b].show)?a.buttonBar[b].show:k.buttonBar[b].show},a.dateSelection=function(d){if(a.enableTime&&"time"===a.showPicker&&(d||null!=d)&&(angular.isDefined(a.date)&&null!=a.date||(a.date=new Date),d&&null!=d)){var e=new Date(a.date);e.setHours(d.getHours()),e.setMinutes(d.getMinutes()),e.setSeconds(d.getSeconds()),e.setMilliseconds(d.getMilliseconds()),d=e}if(angular.isDefined(d)){if(!a.date){var f=angular.isDefined(c.defaultTime)?c.defaultTime:k.defaultTime,h=new Date("2001-01-01 "+f);isNaN(h)||null==d||(d.setHours(h.getHours()),d.setMinutes(h.getMinutes()),d.setSeconds(h.getSeconds()),d.setMilliseconds(h.getMilliseconds()))}a.date=d}var e=a.date?i(a.date,v,t.timezone):null;b.val(e),s.$setViewValue(e),y&&"time"!=a.showPicker&&null!=e&&(a.enableTime?(g(function(){a.showPicker="time"},0),g(function(){a.date=new Date(a.date)},100)):a.close(!1))},a.keydown=function(c){27===c.which&&(a.close(!1),b[0].focus())},a.$watch("isOpen",function(c){if(a.dropdownStyle={display:c?"block":"none"},c){w.openDate=a.date;var d=z?h.offset(b):h.position(b);z?a.dropdownStyle.top=d.top+b.prop("offsetHeight")+"px":a.dropdownStyle.top=void 0,a.dropdownStyle.left=d.left+"px",g(function(){a.$broadcast("uib:datepicker.focus"),f.bind("click",m)},0,!1)}else f.unbind("click",m)}),a.isDisabled=function(b){return("today"===b||"now"===b)&&(b=new Date),a.watchData.minDate&&a.compare(b,a.watchData.minDate)<0||a.watchData.maxDate&&a.compare(b,a.watchData.maxDate)>0},a.compare=function(a,b){return new Date(a.getFullYear(),a.getMonth(),a.getDate())-new Date(b.getFullYear(),b.getMonth(),b.getDate())},a.select=function(b){var c=null;if("today"===b||"now"==b){var d=new Date;angular.isDate(a.date)?(c=new Date(a.date),c.setFullYear(d.getFullYear(),d.getMonth(),d.getDate()),c.setHours(d.getHours(),d.getMinutes(),d.getSeconds(),d.getMilliseconds())):c=d}a.dateSelection(c),"clear"==b&&a.close()},a.close=function(c){a.isOpen=!1,a.enableDate&&a.enableTime&&(a.showPicker=a.reOpenDefault===!1?"date":a.reOpenDefault),angular.isDefined(c)&&a.whenClosed({args:{closePressed:c,openDate:w.openDate||null,closeDate:a.date}}),b[0].focus()},a.changePicker=function(b,c){b.preventDefault(),b.stopPropagation(),a.showPicker=c},a.$on("$destroy",function(){a.isOpen===!0&&(l.$$phase||a.$apply(function(){a.close()})),x.forEach(function(a){a()}),u.remove(),b.unbind("keydown",n),f.unbind("click",m)})}]).directive("datetimePicker",function(){return{restrict:"A",require:["ngModel","datetimePicker"],controller:"DateTimePickerController",scope:{isOpen:"=?",enableDate:"=?",enableTime:"=?",initialPicker:"=?",reOpenDefault:"=?",dateDisabled:"&",customClass:"&",whenClosed:"&"},link:function(a,b,c,d){var e=d[0],f=d[1];f.init(e)}}}).directive("datePickerWrap",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/date-picker.html"}}).directive("timePickerWrap",function(){return{restrict:"EA",replace:!0,transclude:!0,templateUrl:"template/time-picker.html"}}),angular.module("ui.bootstrap.datetimepicker").run(["$templateCache",function(a){"use strict";a.put("template/date-picker.html",''),a.put("template/time-picker.html",'')}]); \ No newline at end of file diff --git a/package.json b/package.json index 06b984b..af8401e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.2.1", + "version": "2.2.2", "url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo "