diff --git a/angularjs-datetime-picker.js b/angularjs-datetime-picker.js index e86247d..caed390 100644 --- a/angularjs-datetime-picker.js +++ b/angularjs-datetime-picker.js @@ -231,8 +231,8 @@ var year = scope.year || today.getFullYear(); var month = scope.month ? (scope.month-1) : today.getMonth(); var day = scope.day || today.getDate(); - var hour = scope.hour || today.getHours(); - var minute = scope.minute || today.getMinutes(); + var hour = scope.hour == 0 ? 0 : (scope.hour || today.getHours()); + var minute = scope.minute == 0 ? 0 : (scope.minute || today.getMinutes()); scope.selectedDate = new Date(year, month, day, hour, minute, 0); } scope.inputHour = scope.selectedDate.getHours(); diff --git a/angularjs-datetime-picker.min.js b/angularjs-datetime-picker.min.js index fe3a6bc..8875c26 100644 --- a/angularjs-datetime-picker.min.js +++ b/angularjs-datetime-picker.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("angularjs-datetime-picker",[]);var e=function(e){"string"==typeof e&&(e=new Date(e));var t=new Date(e.getFullYear(),0,1),a=new Date(e.getFullYear(),6,1),n=Math.max(t.getTimezoneOffset(),a.getTimezoneOffset()),l=e.getTimezoneOffset()=0?"-":"+";return r+("0"+i/60).slice(-2)+":"+("0"+i%60).slice(-2)},t=function(e,t,a){var n=a("DatetimePickerCtrl");return{open:function(e){n.openDatetimePicker(e)},close:function(){n.closeDatetimePicker()}}};t.$inject=["$compile","$document","$controller"],angular.module("angularjs-datetime-picker").factory("DatetimePicker",t);var a=function(e,t){var a,n=this,l=function(e){e&&e.remove(),t[0].body.removeEventListener("click",n.closeDatetimePicker)};this.openDatetimePicker=function(n){this.closeDatetimePicker();var l=angular.element("
");n.dateFormat&&l.attr("date-format",n.dateFormat),n.ngModel&&l.attr("ng-model",n.ngModel),n.year&&l.attr("year",parseInt(n.year)),n.month&&l.attr("month",parseInt(n.month)),n.day&&l.attr("day",parseInt(n.day)),n.hour&&l.attr("hour",parseInt(n.hour)),n.minute&&l.attr("minute",parseInt(n.minute)),(""===n.dateOnly||n.dateOnly===!0)&&l.attr("date-only","true"),"false"===n.closeOnSelect&&l.attr("close-on-select","false");var i=n.triggerEl;n.scope=n.scope||angular.element(i).scope(),a=e(l)(n.scope)[0],a.triggerEl=n.triggerEl,t[0].body.appendChild(a);var r=i.getBoundingClientRect();n.scope.$apply();var o=a.getBoundingClientRect();a.style.position="absolute",a.style.left=r.width>o.width?r.left+r.width-o.width+window.scrollX+"px":r.left+window.scrollX+"px",a.style.top=r.top<300||window.innerHeight-r.bottom>300?r.bottom+window.scrollY+"px":r.top-o.height+window.scrollY+"px",t[0].body.addEventListener("click",this.closeDatetimePicker)},this.closeDatetimePicker=function(e){var a=e&&e.target,n=t[0].querySelector("div[datetime-picker-popup]");e&&a?a.hasAttribute("datetime-picker")||n&&n.contains(a)||l(n):l(n)}};a.$inject=["$compile","$document"],angular.module("angularjs-datetime-picker").controller("DatetimePickerCtrl",a);var n=['
','
',' ',' {{months[mv.month].shortName}} {{mv.year}}',' ',"
",'
','
{{::dayOfWeek.firstLetter}}
','
{{::day}}
','
'," {{::day}}","
",'
{{::day}}
',"
",'
',' {{("0"+inputHour).slice(-2)}} : {{("0"+inputMinute).slice(-2)}}
',' ',' ',"
","
"].join("\n"),l=function(t,a){var l,i,r,o,d=function(){l=[],i=[],r=[],o=0;for(var e=1;31>=e;e++)l.push(e);for(var e=0;12>e;e++)i.push({fullName:t.DATETIME_FORMATS.MONTH[e],shortName:t.DATETIME_FORMATS.SHORTMONTH[e]});for(var e=0;7>e;e++){var a=t.DATETIME_FORMATS.DAY[(e+o)%7];r.push({fullName:a,firstLetter:a.substr(0,1)})}o=0},s=function(e,t){t>11?e++:0>t&&e--,t=(t+12)%12;var a=new Date(e,t,1),n=new Date(e,t+1,0),i=new Date(e,t,0),r=n.getDate(),d=i.getDate(),s=a.getDay(),c=(s-o+7)%7||7,u=l.slice(0,42-(c+r));return u.length>7&&(u=u.slice(0,u.length-7)),{year:e,month:t,days:l.slice(0,r),leadingDays:l.slice(-c-(31-d),d),trailingDays:u}},c=function(t,n,l,o){d();var c=l.dateFormat||"short";t.months=i,t.daysOfWeek=r,t.inputHour,t.inputMinute,t.dateOnly===!0&&(n[0].querySelector("#adp-time").style.display="none"),t.$applyAsync(function(){if(o.triggerEl=angular.element(n[0].triggerEl),l.ngModel){var i=""+o.triggerEl.scope().$eval(l.ngModel);if(i){i.match(/[0-9]{2}:/)||(i+=" 00:00:00"),i=i.replace(/([0-9]{2}-[0-9]{2})-([0-9]{4})/,"$2-$1"),i=i.replace(/([\/-][0-9]{2,4})\ ([0-9]{2}\:[0-9]{2}\:)/,"$1T$2"),i=i.replace(/EDT|EST|CDT|CST|MDT|PDT|PST|UT|GMT/g,""),i=i.replace(/\s*\(\)\s*/,""),i=i.replace(/[\-\+][0-9]{2}:?[0-9]{2}$/,""),i+=e(i);var r=new Date(i);t.selectedDate=new Date(r.getFullYear(),r.getMonth(),r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds())}}if(!t.selectedDate||isNaN(t.selectedDate.getTime())){var d=new Date,c=t.year||d.getFullYear(),u=t.month?t.month-1:d.getMonth(),m=t.day||d.getDate(),g=t.hour||d.getHours(),p=t.minute||d.getMinutes();t.selectedDate=new Date(c,u,m,g,p,0)}t.inputHour=t.selectedDate.getHours(),t.inputMinute=t.selectedDate.getMinutes(),t.mv=s(t.selectedDate.getFullYear(),t.selectedDate.getMonth()),t.today=a(new Date,"yyyy-M-d"),t.selectedDay=t.mv.year==t.selectedDate.getFullYear()&&t.mv.month==t.selectedDate.getMonth()?t.selectedDate.getDate():null}),t.addMonth=function(e){t.mv=s(t.mv.year,t.mv.month+e)},t.setDate=function(e){var a=angular.element(e.target)[0];-1!==a.className.indexOf("selectable")&&(t.updateNgModel(parseInt(a.innerHTML)),t.closeOnSelect!==!1&&o.closeDatetimePicker())},t.updateNgModel=function(e){if(e=e?e:t.selectedDate.getDate(),t.selectedDate=new Date(t.mv.year,t.mv.month,e,t.inputHour,t.inputMinute,0),t.selectedDay=t.selectedDate.getDate(),l.ngModel){var n,i=o.triggerEl.scope();n=i.$eval(l.ngModel)&&"Date"===i.$eval(l.ngModel).constructor.name?new Date(a(t.selectedDate,c)):a(t.selectedDate,c),i.$eval(l.ngModel+"= date",{date:n})}},t.$on("$destroy",o.closeDatetimePicker)};return{restrict:"A",template:n,controller:"DatetimePickerCtrl",replace:!0,scope:{year:"=",month:"=",day:"=",hour:"=",minute:"=",dateOnly:"=",closeOnSelect:"="},link:c}};l.$inject=["$locale","dateFilter"],angular.module("angularjs-datetime-picker").directive("datetimePickerPopup",l);var i=function(e,t){return{require:"ngModel",link:function(e,a,n,l){e.$watch(n.ngModel,function(e){if(e&&""!=e){var t=new Date(e);l.$setValidity("date",t?!0:!1);var a=new Date;n.hasOwnProperty("futureOnly")&&l.$setValidity("future-only",a>t?!1:!0)}}),a[0].addEventListener("click",function(){t.open({triggerEl:a[0],dateFormat:n.dateFormat,ngModel:n.ngModel,year:n.year,month:n.month,day:n.day,hour:n.hour,minute:n.minute,dateOnly:n.dateOnly,futureOnly:n.futureOnly,closeOnSelect:n.closeOnSelect})})}}};i.$inject=["$parse","DatetimePicker"],angular.module("angularjs-datetime-picker").directive("datetimePicker",i)}(); \ No newline at end of file +(function(){angular.module("angularjs-datetime-picker",[]);var c=function(h){(typeof h=="string")&&(h=new Date(h));var g=new Date(h.getFullYear(),0,1);var m=new Date(h.getFullYear(),6,1);var j=Math.max(g.getTimezoneOffset(),m.getTimezoneOffset());var i=h.getTimezoneOffset()=0?"-":"+";return k+("0"+(l/60)).slice(-2)+":"+("0"+(l%60)).slice(-2)};var f=function(h,j,g){var i=g("DatetimePickerCtrl");return{open:function(k){i.openDatetimePicker(k)},close:function(){i.closeDatetimePicker()}}};f.$inject=["$compile","$document","$controller"];angular.module("angularjs-datetime-picker").factory("DatetimePicker",f);var e=function(h,j){var g;var k=this;var i=function(l){l&&l.remove();j[0].body.removeEventListener("click",k.closeDatetimePicker)};this.openDatetimePicker=function(l){this.closeDatetimePicker();var p=angular.element("
");l.dateFormat&&p.attr("date-format",l.dateFormat);l.ngModel&&p.attr("ng-model",l.ngModel);l.year&&p.attr("year",parseInt(l.year));l.month&&p.attr("month",parseInt(l.month));l.day&&p.attr("day",parseInt(l.day));l.hour&&p.attr("hour",parseInt(l.hour));l.minute&&p.attr("minute",parseInt(l.minute));if(l.dateOnly===""||l.dateOnly===true){p.attr("date-only","true")}if(l.closeOnSelect==="false"){p.attr("close-on-select","false")}var m=l.triggerEl;l.scope=l.scope||angular.element(m).scope();g=h(p)(l.scope)[0];g.triggerEl=l.triggerEl;j[0].body.appendChild(g);var o=m.getBoundingClientRect();l.scope.$apply();var n=g.getBoundingClientRect();g.style.position="absolute";if(o.width>n.width){g.style.left=(o.left+o.width-n.width+window.scrollX)+"px"}else{g.style.left=(o.left+window.scrollX)+"px"}if(o.top<300||window.innerHeight-o.bottom>300){g.style.top=(o.bottom+window.scrollY)+"px"}else{g.style.top=(o.top-n.height+window.scrollY)+"px"}j[0].body.addEventListener("click",this.closeDatetimePicker)};this.closeDatetimePicker=function(l){var m=l&&l.target;var n=j[0].querySelector("div[datetime-picker-popup]");if(l&&m){if(m.hasAttribute("datetime-picker")){}else{if(n&&n.contains(m)){}else{i(n)}}}else{i(n)}}};e.$inject=["$compile","$document"];angular.module("angularjs-datetime-picker").controller("DatetimePickerCtrl",e);var b=['
','
',' ',' {{months[mv.month].shortName}} {{mv.year}}',' ',"
",'
','
{{::dayOfWeek.firstLetter}}
','
{{::day}}
','
'," {{::day}}","
",'
{{::day}}
',"
",'
',' {{("0"+inputHour).slice(-2)}} : {{("0"+inputMinute).slice(-2)}}
',' ',' ',"
","
"].join("\n");var a=function(k,l){var o,j,n,g;var h=function(){o=[],j=[];n=[],g=0;for(var q=1;q<=31;q++){o.push(q)}for(var q=0;q<12;q++){j.push({fullName:k.DATETIME_FORMATS.MONTH[q],shortName:k.DATETIME_FORMATS.SHORTMONTH[q]})}for(var q=0;q<7;q++){var p=k.DATETIME_FORMATS.DAY[(q+g)%7];n.push({fullName:p,firstLetter:p.substr(0,1)})}g=0};var i=function(v,s){if(s>11){v++}else{if(s<0){v--}}s=(s+12)%12;var w=new Date(v,s,1),y=new Date(v,s+1,0),t=new Date(v,s,0),p=y.getDate(),x=t.getDate(),r=w.getDay(),q=(r-g+7)%7||7,u=o.slice(0,6*7-(q+p));if(u.length>7){u=u.slice(0,u.length-7)}return{year:v,month:s,days:o.slice(0,p),leadingDays:o.slice(-q-(31-x),x),trailingDays:u}};var m=function(s,r,q,t){h();var p=q.dateFormat||"short";s.months=j;s.daysOfWeek=n;s.inputHour;s.inputMinute;if(s.dateOnly===true){r[0].querySelector("#adp-time").style.display="none"}s.$applyAsync(function(){t.triggerEl=angular.element(r[0].triggerEl);if(q.ngModel){var x=""+t.triggerEl.scope().$eval(q.ngModel);if(x){if(!x.match(/[0-9]{2}:/)){x+=" 00:00:00"}x=x.replace(/([0-9]{2}-[0-9]{2})-([0-9]{4})/,"$2-$1");x=x.replace(/([\/-][0-9]{2,4})\ ([0-9]{2}\:[0-9]{2}\:)/,"$1T$2");x=x.replace(/EDT|EST|CDT|CST|MDT|PDT|PST|UT|GMT/g,"");x=x.replace(/\s*\(\)\s*/,"");x=x.replace(/[\-\+][0-9]{2}:?[0-9]{2}$/,"");x+=c(x);var B=new Date(x);s.selectedDate=new Date(B.getFullYear(),B.getMonth(),B.getDate(),B.getHours(),B.getMinutes(),B.getSeconds())}}if(!s.selectedDate||isNaN(s.selectedDate.getTime())){var w=new Date();var y=s.year||w.getFullYear();var z=s.month?(s.month-1):w.getMonth();var v=s.day||w.getDate();var u=s.hour==0?0:(s.hour||w.getHours());var A=s.minute==0?0:(s.minute||w.getMinutes());s.selectedDate=new Date(y,z,v,u,A,0)}s.inputHour=s.selectedDate.getHours();s.inputMinute=s.selectedDate.getMinutes();s.mv=i(s.selectedDate.getFullYear(),s.selectedDate.getMonth());s.today=l(new Date(),"yyyy-M-d");if(s.mv.year==s.selectedDate.getFullYear()&&s.mv.month==s.selectedDate.getMonth()){s.selectedDay=s.selectedDate.getDate()}else{s.selectedDay=null}});s.addMonth=function(u){s.mv=i(s.mv.year,s.mv.month+u)};s.setDate=function(u){var v=angular.element(u.target)[0];if(v.className.indexOf("selectable")!==-1){s.updateNgModel(parseInt(v.innerHTML));if(s.closeOnSelect!==false){t.closeDatetimePicker()}}};s.updateNgModel=function(u){u=u?u:s.selectedDate.getDate();s.selectedDate=new Date(s.mv.year,s.mv.month,u,s.inputHour,s.inputMinute,0);s.selectedDay=s.selectedDate.getDate();if(q.ngModel){var w=t.triggerEl.scope(),v;if(w.$eval(q.ngModel)&&w.$eval(q.ngModel).constructor.name==="Date"){v=new Date(l(s.selectedDate,p))}else{v=l(s.selectedDate,p)}w.$eval(q.ngModel+"= date",{date:v})}};s.$on("$destroy",t.closeDatetimePicker)};return{restrict:"A",template:b,controller:"DatetimePickerCtrl",replace:true,scope:{year:"=",month:"=",day:"=",hour:"=",minute:"=",dateOnly:"=",closeOnSelect:"="},link:m}};a.$inject=["$locale","dateFilter"];angular.module("angularjs-datetime-picker").directive("datetimePickerPopup",a);var d=function(g,h){return{require:"ngModel",link:function(k,j,i,l){k.$watch(i.ngModel,function(o){if(!o||o==""){return}var n=new Date(o);l.$setValidity("date",!n?false:true);var m=new Date();if(i.hasOwnProperty("futureOnly")){l.$setValidity("future-only",n