From 865d67644cd408d7a4b678b92c80d525327b3478 Mon Sep 17 00:00:00 2001 From: Gillardo Date: Thu, 7 Apr 2016 11:47:37 +0100 Subject: [PATCH] Fixed #111 --- bower.json | 2 +- datetime-picker.js | 11 +++++------ dist/datetime-picker.js | 13 ++++++------- dist/datetime-picker.min.js | 4 ++-- package.json | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/bower.json b/bower.json index 335801a..39e63e6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.3.0", + "version": "2.3.1", "homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo " diff --git a/datetime-picker.js b/datetime-picker.js index 69dcffd..3999f15 100644 --- a/datetime-picker.js +++ b/datetime-picker.js @@ -370,9 +370,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo } $scope.dateSelection(date); - - if (opt == 'clear') - $scope.close(); }; $scope.open = function (picker, evt) { @@ -388,9 +385,11 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo // 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); + if (picker == 'time') { + $timeout(function() { + $scope.date = parseDateString(ngModel.$viewValue); + }, 50); + } }; $scope.close = function (closePressed) { diff --git a/dist/datetime-picker.js b/dist/datetime-picker.js index 18bf876..13d717b 100644 --- a/dist/datetime-picker.js +++ b/dist/datetime-picker.js @@ -1,5 +1,5 @@ // https://github.com/Gillardo/bootstrap-ui-datetime-picker -// Version: 2.3.0 +// Version: 2.3.1 // Released: 2016-04-07 angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position']) .constant('uiDatetimePickerConfig', { @@ -373,9 +373,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo } $scope.dateSelection(date); - - if (opt == 'clear') - $scope.close(); }; $scope.open = function (picker, evt) { @@ -391,9 +388,11 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo // 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); + if (picker == 'time') { + $timeout(function() { + $scope.date = parseDateString(ngModel.$viewValue); + }, 50); + } }; $scope.close = function (closePressed) { diff --git a/dist/datetime-picker.min.js b/dist/datetime-picker.min.js index 9dee632..b01c4a6 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.3.0 +// Version: 2.3.1 // Released: 2016-04-07 -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=v[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,w,a.date);if(isNaN(c))for(var d=0;da.datepickerOptions.maxDate?!1:!0}function s(a,b){var d=a||b;return c.ngRequired||c.required||d?(angular.isNumber(d)&&(d=new Date(d)),d?angular.isDate(d)&&!isNaN(d)?r(d):angular.isDate(new Date(d))&&!isNaN(new Date(d).valueOf())?r(new Date(d)):angular.isString(d)?!isNaN(p(b))&&r(p(viewVialue)):!1:!0):!0}var t,u,v,w=k.dateFormat,x={},y=[],z=angular.isDefined(c.closeOnDateSelection)?a.$parent.$eval(c.closeOnDateSelection):k.closeOnDateSelection,A=angular.isDefined(c.datepickerAppendToBody)?a.$parent.$eval(c.datepickerAppendToBody):k.appendToBody,B=angular.isDefined(c.altInputFormats)?a.$parent.$eval(c.altInputFormats):k.altInputFormats;this.init=function(e){if(t=e,u=t.$options||k.ngModelOptions,a.buttonBar=angular.isDefined(c.buttonBar)?a.$parent.$eval(c.buttonBar):k.buttonBar,a.enableDate=angular.isDefined(a.enableDate)?a.enableDate:k.enableDate,a.enableTime=angular.isDefined(a.enableTime)?a.enableTime:k.enableTime,a.initialPicker=angular.isDefined(c.initialPicker)?c.initialPicker:a.enableDate?k.initialPicker:"time",a.reOpenDefault=angular.isDefined(c.reOpenDefault)?c.reOpenDefault:k.reOpenDefault,"date"==a.initialPicker&&!a.enableDate)throw new Error("datetimePicker can't have initialPicker set to date and have enableDate set to false.");a.showPicker=a.enableDate?a.initialPicker:"time";var g=!1;if(k.html5Types[c.type]?(w=k.html5Types[c.type],g=!0):(w=c.datetimePicker||k.dateFormat,c.$observe("datetimePicker",function(a){var b=a||k.dateFormat;if(b!==w&&(w=b,t.$modelValue=null,!w))throw new Error("datetimePicker must have a date format specified.")})),!w)throw new Error("datetimePicker must have a date format specified.");var h=angular.element('
');u?(timezone=u.timezone,a.ngModelOptions=angular.copy(u),a.ngModelOptions.timezone=null,a.ngModelOptions.updateOnDefault===!0&&(a.ngModelOptions.updateOn=a.ngModelOptions.updateOn?a.ngModelOptions.updateOn+" default":"default"),h.attr("ng-model-options","ngModelOptions")):timezone=null,h.attr({"ng-model":"date","ng-change":"dateSelection(date)"});var i=angular.element(h.children()[0]);a.datepickerOptions||(a.datepickerOptions={}),g&&"month"===c.type&&(a.datepickerOptions.datepickerMode="month",a.datepickerOptions.minMode="month"),i.attr("datepicker-options","datepickerOptions"),angular.isDefined(a.datepickerOptions.datepickerMode)||(a.datepickerOptions.datepickerMode="day");var l=angular.element(h.children()[1]);a.timepickerOptions||(a.timepickerOptions={});for(var m in a.timepickerOptions)l.attr(o(m),"timepickerOptions."+m);angular.forEach(["minDate","maxDate","initDate"],function(b){a.datepickerOptions[b]&&("minDate"==b?l.attr("min","datepickerOptions.minDate"):"maxDate"==b&&l.attr("max","datepickerOptions.maxDate"))}),g?t.$formatters.push(function(b){return a.date=j.fromTimezone(b,u.timezone),b}):(t.$$parserName="datetime",t.$validators.datetime=s,t.$parsers.unshift(q),t.$formatters.push(function(b){return t.$isEmpty(b)?(a.date=b,b):(a.date=j.fromTimezone(b,u.timezone),w=w.replace(/M!/,"MM").replace(/d!/,"dd"),j.filter(a.date,w))})),t.$viewChangeListeners.push(function(){a.date=p(t.$viewValue)}),b.bind("keydown",n),v=d(h)(a),h.remove(),A?f.find("body").append(v):b.after(v)},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,w,u.timezone):null;b.val(e),t.$setViewValue(e),z&&"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){x.openDate=a.date;var d=A?h.offset(b):h.position(b);A?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){("today"===b||"now"===b)&&(b=j.fromTimezone(new Date,timezone));var c={};return angular.forEach(["minDate","maxDate"],function(b){a.datepickerOptions[b]?angular.isDate(a.datepickerOptions[b])?c[b]=j.fromTimezone(new Date(a.datepickerOptions[b]),timezone):c[b]=new Date(i(a.datepickerOptions[b],"medium")):c[b]=null}),a.datepickerOptions&&c.minDate&&a.compare(b,c.minDate)<0||c.maxDate&&a.compare(b,c.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:x.openDate||null,closeDate:a.date}}),b[0].focus()},a.$on("$destroy",function(){a.isOpen===!0&&(l.$$phase||a.$apply(function(){a.close()})),y.forEach(function(a){a()}),v.remove(),b.unbind("keydown",n),f.unbind("click",m)})}]).directive("datetimePicker",function(){return{restrict:"A",require:["ngModel","datetimePicker"],controller:"DateTimePickerController",scope:{isOpen:"=?",datepickerOptions:"=?",timepickerOptions:"=?",enableDate:"=?",enableTime:"=?",initialPicker:"=?",reOpenDefault:"=?",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 +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=v[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,w,a.date);if(isNaN(c))for(var d=0;da.datepickerOptions.maxDate?!1:!0}function s(a,b){var d=a||b;return c.ngRequired||c.required||d?(angular.isNumber(d)&&(d=new Date(d)),d?angular.isDate(d)&&!isNaN(d)?r(d):angular.isDate(new Date(d))&&!isNaN(new Date(d).valueOf())?r(new Date(d)):angular.isString(d)?!isNaN(p(b))&&r(p(viewVialue)):!1:!0):!0}var t,u,v,w=k.dateFormat,x={},y=[],z=angular.isDefined(c.closeOnDateSelection)?a.$parent.$eval(c.closeOnDateSelection):k.closeOnDateSelection,A=angular.isDefined(c.datepickerAppendToBody)?a.$parent.$eval(c.datepickerAppendToBody):k.appendToBody,B=angular.isDefined(c.altInputFormats)?a.$parent.$eval(c.altInputFormats):k.altInputFormats;this.init=function(e){if(t=e,u=t.$options||k.ngModelOptions,a.buttonBar=angular.isDefined(c.buttonBar)?a.$parent.$eval(c.buttonBar):k.buttonBar,a.enableDate=angular.isDefined(a.enableDate)?a.enableDate:k.enableDate,a.enableTime=angular.isDefined(a.enableTime)?a.enableTime:k.enableTime,a.initialPicker=angular.isDefined(c.initialPicker)?c.initialPicker:a.enableDate?k.initialPicker:"time",a.reOpenDefault=angular.isDefined(c.reOpenDefault)?c.reOpenDefault:k.reOpenDefault,"date"==a.initialPicker&&!a.enableDate)throw new Error("datetimePicker can't have initialPicker set to date and have enableDate set to false.");a.showPicker=a.enableDate?a.initialPicker:"time";var g=!1;if(k.html5Types[c.type]?(w=k.html5Types[c.type],g=!0):(w=c.datetimePicker||k.dateFormat,c.$observe("datetimePicker",function(a){var b=a||k.dateFormat;if(b!==w&&(w=b,t.$modelValue=null,!w))throw new Error("datetimePicker must have a date format specified.")})),!w)throw new Error("datetimePicker must have a date format specified.");var h=angular.element('
');u?(timezone=u.timezone,a.ngModelOptions=angular.copy(u),a.ngModelOptions.timezone=null,a.ngModelOptions.updateOnDefault===!0&&(a.ngModelOptions.updateOn=a.ngModelOptions.updateOn?a.ngModelOptions.updateOn+" default":"default"),h.attr("ng-model-options","ngModelOptions")):timezone=null,h.attr({"ng-model":"date","ng-change":"dateSelection(date)"});var i=angular.element(h.children()[0]);a.datepickerOptions||(a.datepickerOptions={}),g&&"month"===c.type&&(a.datepickerOptions.datepickerMode="month",a.datepickerOptions.minMode="month"),i.attr("datepicker-options","datepickerOptions"),angular.isDefined(a.datepickerOptions.datepickerMode)||(a.datepickerOptions.datepickerMode="day");var l=angular.element(h.children()[1]);a.timepickerOptions||(a.timepickerOptions={});for(var m in a.timepickerOptions)l.attr(o(m),"timepickerOptions."+m);angular.forEach(["minDate","maxDate","initDate"],function(b){a.datepickerOptions[b]&&("minDate"==b?l.attr("min","datepickerOptions.minDate"):"maxDate"==b&&l.attr("max","datepickerOptions.maxDate"))}),g?t.$formatters.push(function(b){return a.date=j.fromTimezone(b,u.timezone),b}):(t.$$parserName="datetime",t.$validators.datetime=s,t.$parsers.unshift(q),t.$formatters.push(function(b){return t.$isEmpty(b)?(a.date=b,b):(a.date=j.fromTimezone(b,u.timezone),w=w.replace(/M!/,"MM").replace(/d!/,"dd"),j.filter(a.date,w))})),t.$viewChangeListeners.push(function(){a.date=p(t.$viewValue)}),b.bind("keydown",n),v=d(h)(a),h.remove(),A?f.find("body").append(v):b.after(v)},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,w,u.timezone):null;b.val(e),t.$setViewValue(e),z&&"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){x.openDate=a.date;var d=A?h.offset(b):h.position(b);A?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){("today"===b||"now"===b)&&(b=j.fromTimezone(new Date,timezone));var c={};return angular.forEach(["minDate","maxDate"],function(b){a.datepickerOptions[b]?angular.isDate(a.datepickerOptions[b])?c[b]=j.fromTimezone(new Date(a.datepickerOptions[b]),timezone):c[b]=new Date(i(a.datepickerOptions[b],"medium")):c[b]=null}),a.datepickerOptions&&c.minDate&&a.compare(b,c.minDate)<0||c.maxDate&&a.compare(b,c.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)},a.open=function(b,c){angular.isDefined(c)&&(c.preventDefault(),c.stopPropagation()),g(function(){a.showPicker=b},0),"time"==b&&g(function(){a.date=p(t.$viewValue)},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:x.openDate||null,closeDate:a.date}}),b[0].focus()},a.$on("$destroy",function(){a.isOpen===!0&&(l.$$phase||a.$apply(function(){a.close()})),y.forEach(function(a){a()}),v.remove(),b.unbind("keydown",n),f.unbind("click",m)})}]).directive("datetimePicker",function(){return{restrict:"A",require:["ngModel","datetimePicker"],controller:"DateTimePickerController",scope:{isOpen:"=?",datepickerOptions:"=?",timepickerOptions:"=?",enableDate:"=?",enableTime:"=?",initialPicker:"=?",reOpenDefault:"=?",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 e1cd68b..3a86384 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bootstrap-ui-datetime-picker", - "version": "2.3.0", + "version": "2.3.1", "url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker", "authors": [ "Gillardo "