diff --git a/dist/ng-quick-date.js b/dist/ng-quick-date.js index f92cab6..193e23d 100644 --- a/dist/ng-quick-date.js +++ b/dist/ng-quick-date.js @@ -268,6 +268,7 @@ scope.$watch('calendarShown', function(newVal, oldVal) { var dateInput; if (newVal) { + setupCalendarView(); dateInput = angular.element(element[0].querySelector(".quickdate-date-input"))[0]; return dateInput.select(); } diff --git a/dist/ng-quick-date.min.js b/dist/ng-quick-date.min.js index c68026c..5e78cb2 100644 --- a/dist/ng-quick-date.min.js +++ b/dist/ng-quick-date.min.js @@ -1 +1 @@ -(function(){var a;a=angular.module("ngQuickDate",[]),a.provider("ngQuickDateDefaults",function(){return{options:{dateFormat:"M/d/yyyy",timeFormat:"h:mm a",labelFormat:null,placeholder:"Click to Set Date",hoverText:null,buttonIconHtml:null,closeButtonHtml:"×",nextLinkHtml:"Next →",prevLinkHtml:"← Prev",disableTimepicker:!1,disableClearButton:!1,defaultTime:null,dayAbbreviations:["Su","M","Tu","W","Th","F","Sa"],dateFilter:null,parseDateFunction:function(a){var b;return b=Date.parse(a),isNaN(b)?null:new Date(b)}},$get:function(){return this.options},set:function(a,b){var c,d,e;if("object"==typeof a){e=[];for(c in a)d=a[c],e.push(this.options[c]=d);return e}return this.options[a]=b}}}),a.directive("quickDatepicker",["ngQuickDateDefaults","$filter","$sce",function(a,b,c){return{restrict:"E",require:"?ngModel",scope:{dateFilter:"=?",onChange:"&",required:"@"},replace:!0,link:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r,s,t,u;return n=function(){var a;return r(),d.toggleCalendar(!1),d.weeks=[],d.inputDate=null,d.inputTime=null,d.invalid=!0,"string"==typeof f.initValue&&g.$setViewValue(f.initValue),d.defaultTime||(a=new Date(2013,0,1,12,0),d.datePlaceholder=b("date")(a,d.dateFormat),d.timePlaceholder=b("date")(a,d.timeFormat)),q(),p()},r=function(){var b,e;for(b in a)e=a[b],b.match(/[Hh]tml/)?d[b]=c.trustAsHtml(a[b]||""):!d[b]&&f[b]?d[b]=f[b]:d[b]||(d[b]=a[b]);return d.labelFormat||(d.labelFormat=d.dateFormat,d.disableTimepicker||(d.labelFormat+=" "+d.timeFormat)),f.iconClass&&f.iconClass.length?d.buttonIconHtml=c.trustAsHtml(""):void 0},i=!1,window.document.addEventListener("click",function(){return d.calendarShown&&!i&&(d.toggleCalendar(!1),d.$apply()),i=!1}),angular.element(e[0])[0].addEventListener("click",function(){return i=!0}),p=function(){var a;return a=g.$modelValue?o(g.$modelValue):null,t(),s(a),d.mainButtonStr=a?b("date")(a,d.labelFormat):d.placeholder,d.invalid=g.$invalid},s=function(a){return null!=a?(d.inputDate=b("date")(a,d.dateFormat),d.inputTime=b("date")(a,d.timeFormat)):(d.inputDate=null,d.inputTime=null)},q=function(a){var b;return null==a&&(a=null),b=null!=a?new Date(a):new Date,"Invalid Date"===b.toString()&&(b=new Date),b.setDate(1),d.calendarDate=new Date(b)},t=function(){var a,b,c,e,f,h,i,k,l,n,o,p,q,r;for(h=d.calendarDate.getDay(),e=m(d.calendarDate.getFullYear(),d.calendarDate.getMonth()),f=Math.ceil((h+e)/7),o=[],a=new Date(d.calendarDate),a.setDate(a.getDate()+-1*h),i=p=0,r=f-1;r>=0?r>=p:p>=r;i=r>=0?++p:--p)for(o.push([]),c=q=0;6>=q;c=++q)b=new Date(a),d.defaultTime&&(l=d.defaultTime.split(":"),b.setHours(l[0]||0),b.setMinutes(l[1]||0),b.setSeconds(l[2]||0)),k=g.$modelValue&&b&&j(b,g.$modelValue),n=j(b,new Date),o[i].push({date:b,selected:k,disabled:"function"==typeof d.dateFilter?!d.dateFilter(b):!1,other:b.getMonth()!==d.calendarDate.getMonth(),today:n}),a.setDate(a.getDate()+1);return d.weeks=o},g.$parsers.push(function(a){return d.required&&null==a?(g.$setValidity("required",!1),null):angular.isDate(a)?(g.$setValidity("required",!0),a):angular.isString(a)?(g.$setValidity("required",!0),d.parseDateFunction(a)):null}),g.$formatters.push(function(a){return angular.isDate(a)?a:angular.isString(a)?d.parseDateFunction(a):void 0}),h=function(a,c){return b("date")(a,c)},u=function(a){return"string"==typeof a?o(a):a},o=a.parseDateFunction,j=function(a,b,c){return null==c&&(c=!1),c?a-b===0:(a=u(a),b=u(b),a&&b&&a.getYear()===b.getYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate())},k=function(a,b){return a&&b?parseInt(a.getTime()/6e4)===parseInt(b.getTime()/6e4):!1},m=function(a,b){return[31,a%4===0&&a%100!==0||a%400===0?29:28,31,30,31,30,31,31,30,31,30,31][b]},l=function(a,b){var c,d,e,f,g,h;return g=c=d=h=f=null,e=function(){var a;return a=+new Date-h,g=b>a&&a>0?setTimeout(e,b-a):null},function(){return d=this,c=arguments,h=+new Date,g||(g=setTimeout(e,b),f=a.apply(d,c),d=c=null),f}},g.$render=function(){return q(g.$viewValue),p()},g.$viewChangeListeners.unshift(function(){return q(g.$viewValue),p(),d.onChange?d.onChange():void 0}),d.$watch("calendarShown",function(a){var b;return a?(b=angular.element(e[0].querySelector(".quickdate-date-input"))[0],b.select()):void 0}),d.toggleCalendar=l(function(a){return d.calendarShown=isFinite(a)?a:!d.calendarShown},150),d.selectDate=function(a,b){var c;return null==b&&(b=!0),c=!g.$viewValue&&a||g.$viewValue&&!a||a&&g.$viewValue&&a.getTime()!==g.$viewValue.getTime(),"function"!=typeof d.dateFilter||d.dateFilter(a)?(g.$setViewValue(a),b&&d.toggleCalendar(!1),!0):!1},d.selectDateFromInput=function(a){var b,c,e,f;null==a&&(a=!1);try{if(c=o(d.inputDate),!c)throw"Invalid Date";if(!d.disableTimepicker&&d.inputTime&&d.inputTime.length&&c){if(f=d.disableTimepicker?"00:00:00":d.inputTime,e=o(""+d.inputDate+" "+f),!e)throw"Invalid Time";c=e}if(!k(g.$viewValue,c)&&!d.selectDate(c,!1))throw"Invalid Date";return a&&d.toggleCalendar(!1),d.inputDateErr=!1,d.inputTimeErr=!1}catch(h){if(b=h,"Invalid Date"===b)return d.inputDateErr=!0;if("Invalid Time"===b)return d.inputTimeErr=!0}},d.onDateInputTab=function(){return d.disableTimepicker&&d.toggleCalendar(!1),!0},d.onTimeInputTab=function(){return d.toggleCalendar(!1),!0},d.nextMonth=function(){return q(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()+1))),p()},d.prevMonth=function(){return q(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()-1))),p()},d.clear=function(){return d.selectDate(null,!0)},n()},template:"
\n
{{mainButtonStr}}
\n
\n
\n
\n
\n \n \n
\n
\n \n \n
\n
\n
\n
\n {{calendarDate | date:'MMMM yyyy'}}\n
\n
\n \n \n \n \n \n \n \n \n \n \n \n
{{day}}
{{day.date | date:'d'}}
\n \n
\n
"}}]),a.directive("ngEnter",function(){return function(a,b,c){return b.bind("keydown keypress",function(b){return 13===b.which?(a.$apply(c.ngEnter),b.preventDefault()):void 0})}}),a.directive("onTab",function(){return{restrict:"A",link:function(a,b,c){return b.bind("keydown keypress",function(b){return 9!==b.which||b.shiftKey?void 0:a.$apply(c.onTab)})}}})}).call(this); \ No newline at end of file +(function(){var a;a=angular.module("ngQuickDate",[]),a.provider("ngQuickDateDefaults",function(){return{options:{dateFormat:"M/d/yyyy",timeFormat:"h:mm a",labelFormat:null,placeholder:"Click to Set Date",hoverText:null,buttonIconHtml:null,closeButtonHtml:"×",nextLinkHtml:"Next →",prevLinkHtml:"← Prev",disableTimepicker:!1,disableClearButton:!1,defaultTime:null,dayAbbreviations:["Su","M","Tu","W","Th","F","Sa"],dateFilter:null,parseDateFunction:function(a){var b;return b=Date.parse(a),isNaN(b)?null:new Date(b)}},$get:function(){return this.options},set:function(a,b){var c,d,e;if("object"==typeof a){e=[];for(c in a)d=a[c],e.push(this.options[c]=d);return e}return this.options[a]=b}}}),a.directive("quickDatepicker",["ngQuickDateDefaults","$filter","$sce",function(a,b,c){return{restrict:"E",require:"?ngModel",scope:{dateFilter:"=?",onChange:"&",required:"@"},replace:!0,link:function(d,e,f,g){var h,i,j,k,l,m,n,o,p,q,r,s,t,u;return n=function(){var a;return r(),d.toggleCalendar(!1),d.weeks=[],d.inputDate=null,d.inputTime=null,d.invalid=!0,"string"==typeof f.initValue&&g.$setViewValue(f.initValue),d.defaultTime||(a=new Date(2013,0,1,12,0),d.datePlaceholder=b("date")(a,d.dateFormat),d.timePlaceholder=b("date")(a,d.timeFormat)),q(),p()},r=function(){var b,e;for(b in a)e=a[b],b.match(/[Hh]tml/)?d[b]=c.trustAsHtml(a[b]||""):!d[b]&&f[b]?d[b]=f[b]:d[b]||(d[b]=a[b]);return d.labelFormat||(d.labelFormat=d.dateFormat,d.disableTimepicker||(d.labelFormat+=" "+d.timeFormat)),f.iconClass&&f.iconClass.length?d.buttonIconHtml=c.trustAsHtml(""):void 0},i=!1,window.document.addEventListener("click",function(){return d.calendarShown&&!i&&(d.toggleCalendar(!1),d.$apply()),i=!1}),angular.element(e[0])[0].addEventListener("click",function(){return i=!0}),p=function(){var a;return a=g.$modelValue?o(g.$modelValue):null,t(),s(a),d.mainButtonStr=a?b("date")(a,d.labelFormat):d.placeholder,d.invalid=g.$invalid},s=function(a){return null!=a?(d.inputDate=b("date")(a,d.dateFormat),d.inputTime=b("date")(a,d.timeFormat)):(d.inputDate=null,d.inputTime=null)},q=function(a){var b;return null==a&&(a=null),b=null!=a?new Date(a):new Date,"Invalid Date"===b.toString()&&(b=new Date),b.setDate(1),d.calendarDate=new Date(b)},t=function(){var a,b,c,e,f,h,i,k,l,n,o,p,q,r;for(h=d.calendarDate.getDay(),e=m(d.calendarDate.getFullYear(),d.calendarDate.getMonth()),f=Math.ceil((h+e)/7),o=[],a=new Date(d.calendarDate),a.setDate(a.getDate()+-1*h),i=p=0,r=f-1;r>=0?r>=p:p>=r;i=r>=0?++p:--p)for(o.push([]),c=q=0;6>=q;c=++q)b=new Date(a),d.defaultTime&&(l=d.defaultTime.split(":"),b.setHours(l[0]||0),b.setMinutes(l[1]||0),b.setSeconds(l[2]||0)),k=g.$modelValue&&b&&j(b,g.$modelValue),n=j(b,new Date),o[i].push({date:b,selected:k,disabled:"function"==typeof d.dateFilter?!d.dateFilter(b):!1,other:b.getMonth()!==d.calendarDate.getMonth(),today:n}),a.setDate(a.getDate()+1);return d.weeks=o},g.$parsers.push(function(a){return d.required&&null==a?(g.$setValidity("required",!1),null):angular.isDate(a)?(g.$setValidity("required",!0),a):angular.isString(a)?(g.$setValidity("required",!0),d.parseDateFunction(a)):null}),g.$formatters.push(function(a){return angular.isDate(a)?a:angular.isString(a)?d.parseDateFunction(a):void 0}),h=function(a,c){return b("date")(a,c)},u=function(a){return"string"==typeof a?o(a):a},o=a.parseDateFunction,j=function(a,b,c){return null==c&&(c=!1),c?a-b===0:(a=u(a),b=u(b),a&&b&&a.getYear()===b.getYear()&&a.getMonth()===b.getMonth()&&a.getDate()===b.getDate())},k=function(a,b){return a&&b?parseInt(a.getTime()/6e4)===parseInt(b.getTime()/6e4):!1},m=function(a,b){return[31,a%4===0&&a%100!==0||a%400===0?29:28,31,30,31,30,31,31,30,31,30,31][b]},l=function(a,b){var c,d,e,f,g,h;return g=c=d=h=f=null,e=function(){var a;return a=+new Date-h,g=b>a&&a>0?setTimeout(e,b-a):null},function(){return d=this,c=arguments,h=+new Date,g||(g=setTimeout(e,b),f=a.apply(d,c),d=c=null),f}},g.$render=function(){return q(g.$viewValue),p()},g.$viewChangeListeners.unshift(function(){return q(g.$viewValue),p(),d.onChange?d.onChange():void 0}),d.$watch("calendarShown",function(a){var b;return a?(t(),b=angular.element(e[0].querySelector(".quickdate-date-input"))[0],b.select()):void 0}),d.toggleCalendar=l(function(a){return d.calendarShown=isFinite(a)?a:!d.calendarShown},150),d.selectDate=function(a,b){var c;return null==b&&(b=!0),c=!g.$viewValue&&a||g.$viewValue&&!a||a&&g.$viewValue&&a.getTime()!==g.$viewValue.getTime(),"function"!=typeof d.dateFilter||d.dateFilter(a)?(g.$setViewValue(a),b&&d.toggleCalendar(!1),!0):!1},d.selectDateFromInput=function(a){var b,c,e,f;null==a&&(a=!1);try{if(c=o(d.inputDate),!c)throw"Invalid Date";if(!d.disableTimepicker&&d.inputTime&&d.inputTime.length&&c){if(f=d.disableTimepicker?"00:00:00":d.inputTime,e=o(""+d.inputDate+" "+f),!e)throw"Invalid Time";c=e}if(!k(g.$viewValue,c)&&!d.selectDate(c,!1))throw"Invalid Date";return a&&d.toggleCalendar(!1),d.inputDateErr=!1,d.inputTimeErr=!1}catch(h){if(b=h,"Invalid Date"===b)return d.inputDateErr=!0;if("Invalid Time"===b)return d.inputTimeErr=!0}},d.onDateInputTab=function(){return d.disableTimepicker&&d.toggleCalendar(!1),!0},d.onTimeInputTab=function(){return d.toggleCalendar(!1),!0},d.nextMonth=function(){return q(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()+1))),p()},d.prevMonth=function(){return q(new Date(new Date(d.calendarDate).setMonth(d.calendarDate.getMonth()-1))),p()},d.clear=function(){return d.selectDate(null,!0)},n()},template:"
\n
{{mainButtonStr}}
\n
\n
\n
\n
\n \n \n
\n
\n \n \n
\n
\n
\n
\n {{calendarDate | date:'MMMM yyyy'}}\n
\n
\n \n \n \n \n \n \n \n \n \n \n \n
{{day}}
{{day.date | date:'d'}}
\n \n
\n
"}}]),a.directive("ngEnter",function(){return function(a,b,c){return b.bind("keydown keypress",function(b){return 13===b.which?(a.$apply(c.ngEnter),b.preventDefault()):void 0})}}),a.directive("onTab",function(){return{restrict:"A",link:function(a,b,c){return b.bind("keydown keypress",function(b){return 9!==b.which||b.shiftKey?void 0:a.$apply(c.onTab)})}}})}).call(this); \ No newline at end of file diff --git a/src/ng-quick-date.coffee b/src/ng-quick-date.coffee index 952da85..0250661 100644 --- a/src/ng-quick-date.coffee +++ b/src/ng-quick-date.coffee @@ -247,7 +247,7 @@ app.directive "quickDatepicker", ['ngQuickDateDefaults', '$filter', '$sce', (ngQ # DATA WATCHES # ================================== - + # Called when the model is updated from outside the datepicker ngModelCtrl.$render = -> setCalendarDate(ngModelCtrl.$viewValue) @@ -264,6 +264,7 @@ app.directive "quickDatepicker", ['ngQuickDateDefaults', '$filter', '$sce', (ngQ # When the popup is toggled open, select the date input scope.$watch 'calendarShown', (newVal, oldVal) -> if newVal + setupCalendarView() dateInput = angular.element(element[0].querySelector(".quickdate-date-input"))[0] dateInput.select()