diff --git a/bower.json b/bower.json index 43cf733..d13ece6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.2.2", + "version": "2.2.3", "homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo " diff --git a/datetime-picker.js b/datetime-picker.js index 56241ad..bdb3b76 100644 --- a/datetime-picker.js +++ b/datetime-picker.js @@ -321,16 +321,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo if (scope.showPicker != 'time' && date != null) { // if time is enabled, swap to timePicker if (scope.enableTime) { - // need to delay this, else timePicker never shown - $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); + scope.open('time'); } else { scope.close(false); } @@ -368,6 +359,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.$broadcast('uib:datepicker.focus'); $document.bind('click', documentClickBind); }, 0, false); + + scope.open(scope.showPicker); } else { $document.unbind('click', documentClickBind); } @@ -408,6 +401,24 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.close(); }; + scope.open = function (picker, evt) { + if (angular.isDefined(evt)) { + evt.preventDefault(); + evt.stopPropagation(); + } + + // need to delay this, else timePicker never shown + $timeout(function() { + scope.showPicker = picker; + }, 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); + }, 50); + }; + scope.close = function (closePressed) { scope.isOpen = false; @@ -423,13 +434,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo element[0].focus(); }; - scope.changePicker = function (evt, picker) { - evt.preventDefault(); - evt.stopPropagation(); - - scope.showPicker = picker; - }; - scope.$on('$destroy', function () { if (scope.isOpen === true) { if (!$rootScope.$$phase) { diff --git a/dist/datetime-picker.js b/dist/datetime-picker.js index 759e5b0..7df5943 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.2 -// Released: 2016-03-04 +// Version: 2.2.3 +// Released: 2016-03-11 angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) .constant('uiDatetimePickerConfig', { dateFormat: 'yyyy-MM-dd HH:mm', @@ -324,16 +324,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo if (scope.showPicker != 'time' && date != null) { // if time is enabled, swap to timePicker if (scope.enableTime) { - // need to delay this, else timePicker never shown - $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); + scope.open('time'); } else { scope.close(false); } @@ -371,6 +362,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.$broadcast('uib:datepicker.focus'); $document.bind('click', documentClickBind); }, 0, false); + + scope.open(scope.showPicker); } else { $document.unbind('click', documentClickBind); } @@ -411,6 +404,24 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo scope.close(); }; + scope.open = function (picker, evt) { + if (angular.isDefined(evt)) { + evt.preventDefault(); + evt.stopPropagation(); + } + + // need to delay this, else timePicker never shown + $timeout(function() { + scope.showPicker = picker; + }, 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); + }, 50); + }; + scope.close = function (closePressed) { scope.isOpen = false; @@ -426,13 +437,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo element[0].focus(); }; - scope.changePicker = function (evt, picker) { - evt.preventDefault(); - evt.stopPropagation(); - - scope.showPicker = picker; - }; - scope.$on('$destroy', function () { if (scope.isOpen === true) { if (!$rootScope.$$phase) { @@ -588,12 +592,12 @@ angular.module('ui.bootstrap.datetimepicker').run(['$templateCache', function($t 'use strict'; $templateCache.put('template/date-picker.html', - "" + "" ); $templateCache.put('template/time-picker.html', - "" + "" ); }]); diff --git a/dist/datetime-picker.min.js b/dist/datetime-picker.min.js index d2d313b..1c71266 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.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 +// Version: 2.2.3 +// Released: 2016-03-11 +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,g=new Date("2001-01-01 "+f);isNaN(g)||null==d||(d.setHours(g.getHours()),d.setMinutes(g.getMinutes()),d.setSeconds(g.getSeconds()),d.setMilliseconds(g.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?a.open("time"):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),a.open(a.showPicker)}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.open=function(b,c){angular.isDefined(c)&&(c.preventDefault(),c.stopPropagation()),g(function(){a.showPicker=b},0),g(function(){a.date=new Date(a.date)},50)},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.$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/dist/datetime-picker.tpls.js b/dist/datetime-picker.tpls.js index 0f0790c..17a7a6f 100644 --- a/dist/datetime-picker.tpls.js +++ b/dist/datetime-picker.tpls.js @@ -2,12 +2,12 @@ angular.module('ui.bootstrap.datetimepicker').run(['$templateCache', function($t 'use strict'; $templateCache.put('template/date-picker.html', - "
" + "
" ); $templateCache.put('template/time-picker.html', - "
" + "
" ); }]); diff --git a/package.json b/package.json index af8401e..b816598 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.2.2", + "version": "2.2.3", "url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo " diff --git a/template/date-picker.html b/template/date-picker.html index 8a702d8..9282eee 100644 --- a/template/date-picker.html +++ b/template/date-picker.html @@ -8,7 +8,7 @@ - + diff --git a/template/time-picker.html b/template/time-picker.html index b715e4f..815c043 100644 --- a/template/time-picker.html +++ b/template/time-picker.html @@ -8,7 +8,7 @@ - +