From 3d01d034ac84a0b98b58302063ad55e9a4fe3eba Mon Sep 17 00:00:00 2001 From: divecoke Date: Mon, 5 Mar 2018 09:53:49 +0200 Subject: [PATCH 1/7] prevMonth enabled --- src/js/angular-datepicker.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index 971dbc9..a763c6e 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -107,13 +107,13 @@ return [ '
', - '', + '', '{{px}}', '', '', '{{item}}', '', - '', + '', '{{nx}}', '', '
' @@ -661,13 +661,30 @@ } }; - $scope.setDatepickerDay = function setDatepickerDay(day) { + $scope.setDatepickerDay = function setDatepickerDay(day, type) { + if (type && $scope.anyDay !== 'true') { + return; + } if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { + if (type === 'previous') { + if ($scope.monthNumber !== 1) { + $scope.monthNumber--; + } else { + $scope.monthNumber = 12; + } + } else if (type === 'next') { + if ($scope.monthNumber !== 12) { + $scope.monthNumber++; + } else { + $scope.monthNumber = 1; + } + } + $scope.day = Number(day); $scope.selectedDay = $scope.day; $scope.selectedMonth = $scope.monthNumber; @@ -1033,7 +1050,8 @@ 'datepickerAppendTo': '@', 'datepickerToggle': '@', 'datepickerClass': '@', - 'datepickerShow': '@' + 'datepickerShow': '@', + 'anyDay': '@' }, 'link': linkingFunction }; From 1db54cce67cb14104f615cbe0dc13e6a4d38de63 Mon Sep 17 00:00:00 2001 From: divecoke Date: Mon, 5 Mar 2018 13:11:54 +0200 Subject: [PATCH 2/7] prod --- dist/angular-datepicker.js | 26 ++++++++++++++++++++++---- dist/angular-datepicker.min.js | 4 ++-- dist/angular-datepicker.sourcemap.map | 2 +- src/js/angular-datepicker.js | 4 ++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index 971dbc9..85f4256 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -107,13 +107,13 @@ return [ '' @@ -661,13 +661,30 @@ } }; - $scope.setDatepickerDay = function setDatepickerDay(day) { + $scope.setDatepickerDay = function setDatepickerDay(day, type) { + if (type && $scope.anyDay !== 'true') { + return; + } if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { + if (type === 'previous') { + if ($scope.monthNumber !== 1) { + $scope.monthNumber -= 1; + } else { + $scope.monthNumber = 12; + } + } else if (type === 'next') { + if ($scope.monthNumber !== 12) { + $scope.monthNumber += 1; + } else { + $scope.monthNumber = 1; + } + } + $scope.day = Number(day); $scope.selectedDay = $scope.day; $scope.selectedMonth = $scope.monthNumber; @@ -1033,7 +1050,8 @@ 'datepickerAppendTo': '@', 'datepickerToggle': '@', 'datepickerClass': '@', - 'datepickerShow': '@' + 'datepickerShow': '@', + 'anyDay': '@' }, 'link': linkingFunction }; diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 13c53aa..99ca765 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -4,9 +4,9 @@ * Released by 720kb.net under the MIT license * www.opensource.org/licenses/MIT * - * 2017-06-28 + * 2018-03-05 */ -!function(e,a){"use strict";var t=function(){if(a.userAgent&&(a.userAgent.match(/Android/i)||a.userAgent.match(/webOS/i)||a.userAgent.match(/iPhone/i)||a.userAgent.match(/iPad/i)||a.userAgent.match(/iPod/i)||a.userAgent.match(/BlackBerry/i)||a.userAgent.match(/Windows Phone/i)))return!0}(),n=function(e,a,n){return n&&(t=!1),t?['
','
','","
","
",'
','
','","
","
"]:['
','
','',e,"","
",'
',"{{month}} ",'',"","{{year}}","","","","
",'
','',a,"","
","
"]},i=function(e,a){return['
','",'
','',e,"",'',a,"","
","
"]},r=function(e,a,t){var r=['
',"
"],d=n(e,a,t),l=i(e,a),c=['
','
',"{{d}}","
","
"],o=['"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")},d=function(a,n,i,d,l,c){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@"},link:function(o,s,m){var u,b,h,y=m.selector,p=e.element(y?s[0].querySelector("."+y):s[0].children[0]),g=m.buttonPrev||'',M=m.buttonNext||'',k=m.dateFormat,f=o.$eval(o.dateDisabledDates),D=o.$eval(o.dateEnabledDates),v=o.$eval(o.dateDisabledWeekdays),N=new Date,S=!1,w=!1,x=void 0!==m.datepickerMobile&&"false"!==m.datepickerMobile,Y=i.DATETIME_FORMATS,T=r(g,M,x),_=function(){S||w||!u||o.hideCalendar()},L=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),s=new Date(a+"/"+e+"/"+l).getDay(),m=[],u=[];for(o.days=[],o.dateWeekStartDay=o.validateWeekDay(o.dateWeekStartDay),d=(o.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)o.days.push(t);if(c===o.dateWeekStartDay)o.prevMonthDays=[];else{for(i=c-o.dateWeekStartDay,c0}),t=a.match(m).filter(function(e){return null!==e.match(/^[a-zA-Z]+$/i)}),l=0;l-1||((t=e.className.split(" ")).push(a),e.className=t.join(" "))},remove:function(e,a){var t,n;if(-1!==e.className.indexOf(a)){for(n=e.className.split(" "),t=0;tNumber(e)&&!o.isSelectableMinYear(e))return;o.paginateYears(e),o.showYearsPagination=!1,c(function(){o.year=Number(e),L(o.monthNumber,o.year)},0)},o.hideCalendar=function(){u.classList?u.classList.remove("_720kb-datepicker-open"):O.remove(u,"_720kb-datepicker-open")},o.setDatepickerDay=function(e){o.isSelectableDay(o.monthNumber,o.year,e)&&o.isSelectableDate(o.monthNumber,o.year,e)&&o.isSelectableMaxDate(o.year+"/"+o.monthNumber+"/"+e)&&o.isSelectableMinDate(o.year+"/"+o.monthNumber+"/"+e)&&(o.day=Number(e),o.selectedDay=o.day,o.selectedMonth=o.monthNumber,o.selectedYear=o.year,H(),m.hasOwnProperty("dateRefocus")&&p[0].focus(),o.hideCalendar())},o.paginateYears=function(e){var a,n=[],i=10,r=10;for(o.paginationYears=[],t&&(i=50,r=50,o.dateMinLimit&&o.dateMaxLimit&&(i=(e=new Date(o.dateMaxLimit).getFullYear())-new Date(o.dateMinLimit).getFullYear(),r=1)),a=i;a>0;a-=1)n.push(Number(e)-a);for(a=0;a0)try{(N=k?E(p[0].value.toString(),k):new Date(p[0].value.toString())).getFullYear()&&!isNaN(N.getDay())&&!isNaN(N.getMonth())&&o.isSelectableDay(N.getMonth(),N.getFullYear(),N.getDay())&&o.isSelectableDate(N.getMonth(),N.getFullYear(),N.getDay())&&o.isSelectableMaxDate(N)&&o.isSelectableMinDate(N)&&o.$apply(function(){o.month=d("date")(N,"MMMM"),o.monthNumber=Number(d("date")(N,"MM")),o.day=Number(d("date")(N,"dd")),4===N.getFullYear().toString().length&&(o.year=Number(d("date")(N,"yyyy"))),L(o.monthNumber,o.year)})}catch(e){return e}}),o.dateMaxLimit&&n&&n.length&&!o.isSelectableMaxYear(Number(n[n.length-1])+1)?o.paginationYearsNextDisabled=!0:o.paginationYearsNextDisabled=!1,o.dateMinLimit&&n&&n.length&&!o.isSelectableMinYear(Number(n[0])-1)?o.paginationYearsPrevDisabled=!0:o.paginationYearsPrevDisabled=!1,o.paginationYears=n},o.isSelectableDay=function(e,a,t){var n=0;if(v&&v.length>0)for(n;n<=v.length;n+=1)if(v[n]===new Date(e+"/"+t+"/"+a).getDay())return!1;return!0},o.isSelectableDate=function(e,a,t){var n=0;if(f&&f.length>0)for(n;n<=f.length;n+=1)if(new Date(f[n]).getTime()===new Date(e+"/"+t+"/"+a).getTime())return!1;if(D){for(n;n<=D.length;n+=1)if(new Date(D[n]).getTime()===new Date(e+"/"+t+"/"+a).getTime())return!0;return!1}return!0},o.isSelectableMinDate=function(e){return!(o.dateMinLimit&&new Date(o.dateMinLimit)&&new Date(e).getTime()new Date(o.dateMaxLimit).getTime())},o.isSelectableMaxYear=function(e){return!(o.dateMaxLimit&&e>new Date(o.dateMaxLimit).getFullYear())},o.isSelectableMinYear=function(e){return!(o.dateMinLimit&&e6)&&(a=0),a},T=T.replace(/{{/g,l.startSymbol()).replace(/}}/g,l.endSymbol()),o.dateMonthTitle=o.dateMonthTitle||"Select month",o.dateYearTitle=o.dateYearTitle||"Select year",o.buttonNextTitle=o.buttonNextTitle||"Next",o.buttonPrevTitle=o.buttonPrevTitle||"Prev",o.month=d("date")(N,"MMMM"),o.monthNumber=Number(d("date")(N,"MM")),o.day=Number(d("date")(N,"dd")),o.dateWeekStartDay=o.validateWeekDay(o.dateWeekStartDay),o.dateMaxLimit?o.year=Number(d("date")(new Date(o.dateMaxLimit),"yyyy")):o.year=Number(d("date")(N,"yyyy")),o.months=Y.MONTH,o.daysInString=[],h=o.dateWeekStartDay;h<=o.dateWeekStartDay+6;h+=1)o.daysInString.push(h%7);o.daysInString=o.daysInString.map(function(e){return d("date")(new Date(new Date("06/08/2014").valueOf()+864e5*e),"EEE")}),o.datepickerAppendTo&&-1!==o.datepickerAppendTo.indexOf(".")?(o.datepickerID="datepicker-id-"+(new Date).getTime()+(Math.floor(6*Math.random())+8),e.element(document.getElementsByClassName(o.datepickerAppendTo.replace(".",""))[0]).append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):o.datepickerAppendTo&&-1!==o.datepickerAppendTo.indexOf("#")?(o.datepickerID="datepicker-id-"+(new Date).getTime()+(Math.floor(6*Math.random())+8),e.element(document.getElementById(o.datepickerAppendTo.replace("#",""))).append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):o.datepickerAppendTo&&"body"===o.datepickerAppendTo?(o.datepickerID="datepicker-id-"+((new Date).getTime()+(Math.floor(6*Math.random())+8)),e.element(document).find("body").append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):(p.after(n(e.element(T))(o)),u=s[0].querySelector("._720kb-datepicker-calendar")),function(){return!o.datepickerToggle||o.$eval(o.datepickerToggle)}()&&p.on("focus click focusin",function(){w=!0,S||w||!u?F():o.hideCalendar()}),p.on("focusout blur",function(){w=!1}),e.element(u).on("mouseenter",function(){S=!0}),e.element(u).on("mouseleave",function(){S=!1}),e.element(u).on("focusin",function(){S=!0}),e.element(a).on("click focus focusin",_),(o.dateMinLimit&&!o.isSelectableMinYear(o.year)||!o.isSelectableMinDate(o.year+"/"+o.monthNumber+"/"+o.day))&&$(),(o.dateMaxLimit&&!o.isSelectableMaxYear(o.year)||!o.isSelectableMaxDate(o.year+"/"+o.monthNumber+"/"+o.day))&&A(),o.paginateYears(o.year),L(o.monthNumber,o.year),o.checkVisibility=j,o.$on("$destroy",function(){I(),C(),B(),G(),z(),R(),p.off("focus click focusout blur"),e.element(u).off("mouseenter mouseleave focusin"),e.element(a).off("click focus focusin",_)})}}};e.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",d])}(angular,navigator); +!function(I,e){"use strict";var C=function(){if(e.userAgent&&(e.userAgent.match(/Android/i)||e.userAgent.match(/webOS/i)||e.userAgent.match(/iPhone/i)||e.userAgent.match(/iPad/i)||e.userAgent.match(/iPod/i)||e.userAgent.match(/BlackBerry/i)||e.userAgent.match(/Windows Phone/i)))return!0}(),B=function(e,a,t){var n,i,r=['
',"
"],d=(n=e,i=a,t&&(C=!1),C?['
','
','","
","
",'
','
','","
","
"]:['
','
','',n,"","
",'
',"{{month}} ",'',"","{{year}}","","","","
",'
','',i,"","
","
"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','
',"{{d}}","
","
"],o=['"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(W,E,H,O,F,j){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,n,i,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),y=new Date,h=!1,p=!1,g=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,k=H.DATETIME_FORMATS,M=B(l,c,g),D=function(){h||p||!a||u.hideCalendar()},f=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(i=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,j(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):Y(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){a&&"true"!==u.anyDay||u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:u.monthNumber=12:"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:u.monthNumber=1),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,w(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],n=10,i=10;for(u.paginationYears=[],C&&(i=n=50,u.dateMinLimit&&u.dateMaxLimit&&(n=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),i=1)),a=n;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e Date: Mon, 5 Mar 2018 14:04:23 +0200 Subject: [PATCH 3/7] Prod fixed disabled select --- dist/angular-datepicker.js | 4 ---- dist/angular-datepicker.min.js | 2 +- dist/angular-datepicker.sourcemap.map | 2 +- src/js/angular-datepicker.js | 4 ---- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index 85f4256..dcad76b 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -662,10 +662,6 @@ }; $scope.setDatepickerDay = function setDatepickerDay(day, type) { - if (type && $scope.anyDay !== 'true') { - return; - } - if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 99ca765..fad189c 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -8,5 +8,5 @@ */ -!function(I,e){"use strict";var C=function(){if(e.userAgent&&(e.userAgent.match(/Android/i)||e.userAgent.match(/webOS/i)||e.userAgent.match(/iPhone/i)||e.userAgent.match(/iPad/i)||e.userAgent.match(/iPod/i)||e.userAgent.match(/BlackBerry/i)||e.userAgent.match(/Windows Phone/i)))return!0}(),B=function(e,a,t){var n,i,r=['
',"
"],d=(n=e,i=a,t&&(C=!1),C?['
','
','","
","
",'
','
','","
","
"]:['
','
','',n,"","
",'
',"{{month}} ",'',"","{{year}}","","","","
",'
','',i,"","
","
"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','
',"{{d}}","
","
"],o=['"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(W,E,H,O,F,j){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,n,i,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),y=new Date,h=!1,p=!1,g=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,k=H.DATETIME_FORMATS,M=B(l,c,g),D=function(){h||p||!a||u.hideCalendar()},f=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(i=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,j(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):Y(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){a&&"true"!==u.anyDay||u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:u.monthNumber=12:"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:u.monthNumber=1),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,w(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],n=10,i=10;for(u.paginationYears=[],C&&(i=n=50,u.dateMinLimit&&u.dateMaxLimit&&(n=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),i=1)),a=n;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e',""],d=(n=e,i=a,t&&(C=!1),C?['
','
','","
","
",'
','
','","
","
"]:['
','
','',n,"","
",'
',"{{month}} ",'',"","{{year}}","","","","
",'
','',i,"","
","
"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','
',"{{d}}","
","
"],o=['"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(W,E,H,O,F,j){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,n,i,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,g=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,k=H.DATETIME_FORMATS,M=B(l,c,g),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(i=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,j(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):Y(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:u.monthNumber=12:"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:u.monthNumber=1),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,w(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],n=10,i=10;for(u.paginationYears=[],C&&(i=n=50,u.dateMinLimit&&u.dateMaxLimit&&(n=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),i=1)),a=n;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e Date: Wed, 7 Mar 2018 23:07:58 +0200 Subject: [PATCH 4/7] Added month selector --- dist/angular-datepicker.js | 1600 +++++++++++++------------ dist/angular-datepicker.min.js | 4 +- dist/angular-datepicker.sourcemap.map | 2 +- src/js/angular-datepicker.js | 1600 +++++++++++++------------ 4 files changed, 1617 insertions(+), 1589 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index dcad76b..60739eb 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -6,8 +6,8 @@ var A_DAY_IN_MILLISECONDS = 86400000 , isMobile = (function isMobile() { - if (navigator.userAgent && - (navigator.userAgent.match(/Android/i) || + if (navigator.userAgent && + (navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || @@ -15,435 +15,392 @@ navigator.userAgent.match(/BlackBerry/i) || navigator.userAgent.match(/Windows Phone/i))) { - return true; - } - }()) + return true; + } + }()) , generateMonthAndYearHeader = function generateMonthAndYearHeader(prevButton, nextButton, preventMobile) { - if (preventMobile) { + if (preventMobile) { - isMobile = false; - } + isMobile = false; + } - if (isMobile) { - - return [ - '
', - '
', - '', - '
', - '
', - '
', - '
', - '', - '
', - '
' - ]; - } + if (isMobile) { return [ '
', - '', - '
', - '{{month}} ', - '', - '', - '{{year}}', - '', - '', - '', - '
', - '', + '
', + '
', + '
', + '
', + '
', + '', + '', + '
', '
' ]; } + + return [ + '
', + '
', + "
", + "
", + '
', + '
', + "
", + "
", + '' + ]; + } , generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) { - return [ - '
', - '
', - '', - '{{y}}', - '', - '
', - '', - '
' - ]; - } + return ['
', '", '", "
"]; + } + + , generateMonthsPaginationHeader = function generateMonthsPaginationHeader() { + + return ['
', '", "
"]; + + } , generateDaysColumns = function generateDaysColumns() { - return [ + return [ '
', - '
', - '{{d}}', - '
', + '
', + '{{d}}', + '
', '
' - ]; - } + ]; + } , generateDays = function generateDays() { - - return [ - '' - ]; - } + return [ + '' + ]; + } , generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton, preventMobile) { - var toReturn = [ - '
', - '
' - ] + var toReturn = [ + '
', + '
' + ] , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile) , yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton) + , monthsPaginationHeader = generateMonthsPaginationHeader() , daysColumns = generateDaysColumns() , days = generateDays() , iterator = function iterator(aRow) { - toReturn.splice(toReturn.length - 1, 0, aRow); - }; + toReturn.splice(toReturn.length - 1, 0, aRow); + }; - monthAndYearHeader.forEach(iterator); - yearsPaginationHeader.forEach(iterator); - daysColumns.forEach(iterator); - days.forEach(iterator); + monthAndYearHeader.forEach(iterator); + yearsPaginationHeader.forEach(iterator); + monthsPaginationHeader.forEach(iterator); + daysColumns.forEach(iterator); + days.forEach(iterator); - return toReturn.join(''); - } + return toReturn.join(''); + } , datepickerDirective = function datepickerDirective($window, $compile, $locale, $filter, $interpolate, $timeout) { - var linkingFunction = function linkingFunction($scope, element, attr) { - - //get child input - var selector = attr.selector - , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0]) - , theCalendar - , defaultPrevButton = '' - , defaultNextButton = '' - , prevButton = attr.buttonPrev || defaultPrevButton - , nextButton = attr.buttonNext || defaultNextButton - , dateFormat = attr.dateFormat - //, dateMinLimit - //, dateMaxLimit - , dateDisabledDates = $scope.$eval($scope.dateDisabledDates) - , dateEnabledDates = $scope.$eval($scope.dateEnabledDates) - , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays) - , date = new Date() - , isMouseOn = false - , isMouseOnInput = false - , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false' - , datetime = $locale.DATETIME_FORMATS - , pageDatepickers - , hours24h = 86400000 - , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile) - , n - , onClickOnWindow = function onClickOnWindow() { - - if (!isMouseOn && - !isMouseOnInput && theCalendar) { - - $scope.hideCalendar(); - } + var linkingFunction = function linkingFunction($scope, element, attr) { + + //get child input + var selector = attr.selector + , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0]) + , theCalendar + , defaultPrevButton = '' + , defaultNextButton = '' + , prevButton = attr.buttonPrev || defaultPrevButton + , nextButton = attr.buttonNext || defaultNextButton + , dateFormat = attr.dateFormat + //, dateMinLimit + //, dateMaxLimit + , dateDisabledDates = $scope.$eval($scope.dateDisabledDates) + , dateEnabledDates = $scope.$eval($scope.dateEnabledDates) + , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays) + , date = new Date() + , isMouseOn = false + , isMouseOnInput = false + , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false' + , datetime = $locale.DATETIME_FORMATS + , pageDatepickers + , hours24h = 86400000 + , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile) + , n + , onClickOnWindow = function onClickOnWindow() { + + if (!isMouseOn && + !isMouseOnInput && theCalendar) { + + $scope.hideCalendar(); } - , setDaysInMonth = function setDaysInMonth(month, year) { + } + , setDaysInMonth = function setDaysInMonth(month, year) { - var i - , limitDate = new Date(year, month, 0).getDate() - , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay() - , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay() - , prevMonthDays = [] - , nextMonthDays = [] - , howManyNextDays - , howManyPreviousDays - , monthAlias - , dateWeekEndDay; - - $scope.days = []; - $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); - dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7; - - for (i = 1; i <= limitDate; i += 1) { - - $scope.days.push(i); - } + var i + , limitDate = new Date(year, month, 0).getDate() + , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay() + , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay() + , prevMonthDays = [] + , nextMonthDays = [] + , howManyNextDays + , howManyPreviousDays + , monthAlias + , dateWeekEndDay; + + $scope.days = []; + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); + dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7; + + for (i = 1; i <= limitDate; i += 1) { + + $scope.days.push(i); + } - //get previous month days if first day in month is not first day in week - if (firstDayMonthNumber === $scope.dateWeekStartDay) { + //get previous month days if first day in month is not first day in week + if (firstDayMonthNumber === $scope.dateWeekStartDay) { - //no need for it - $scope.prevMonthDays = []; - } else { + //no need for it + $scope.prevMonthDays = []; + } else { - howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; + howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; - if (firstDayMonthNumber < $scope.dateWeekStartDay) { + if (firstDayMonthNumber < $scope.dateWeekStartDay) { - howManyPreviousDays += 7; - } + howManyPreviousDays += 7; + } - //get previous month - if (Number(month) === 1) { + //get previous month + if (Number(month) === 1) { - monthAlias = 12; - } else { + monthAlias = 12; + } else { - monthAlias = month - 1; - } - //return previous month days - for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { + monthAlias = month - 1; + } + //return previous month days + for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { - prevMonthDays.push(i); - } - //attach previous month days - $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); + prevMonthDays.push(i); } + //attach previous month days + $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); + } - //get next month days if last day in month is not last day in week - if (lastDayMonthNumber === dateWeekEndDay) { - //no need for it - $scope.nextMonthDays = []; - } else { - howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; + //get next month days if last day in month is not last day in week + if (lastDayMonthNumber === dateWeekEndDay) { + //no need for it + $scope.nextMonthDays = []; + } else { + howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; - if (lastDayMonthNumber < $scope.dateWeekStartDay) { + if (lastDayMonthNumber < $scope.dateWeekStartDay) { - howManyNextDays -= 7; - } - //get previous month + howManyNextDays -= 7; + } + //get previous month - //return next month days - for (i = 1; i <= howManyNextDays; i += 1) { + //return next month days + for (i = 1; i <= howManyNextDays; i += 1) { - nextMonthDays.push(i); - } - //attach previous month days - $scope.nextMonthDays = nextMonthDays; + nextMonthDays.push(i); } + //attach previous month days + $scope.nextMonthDays = nextMonthDays; } - , resetToMinDate = function resetToMinDate() { + } + , resetToMinDate = function resetToMinDate() { - $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM'); - $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM')); - $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); - $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); + $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM'); + $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM')); + $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); + $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); - setDaysInMonth($scope.monthNumber, $scope.year); - } - , resetToMaxDate = function resetToMaxDate() { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , resetToMaxDate = function resetToMaxDate() { - $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM'); - $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM')); - $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd')); - $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy')); + $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM'); + $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM')); + $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd')); + $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy')); - setDaysInMonth($scope.monthNumber, $scope.year); - } - , prevYear = function prevYear() { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , prevYear = function prevYear() { - $scope.year = Number($scope.year) - 1; - } - , nextYear = function nextYear() { + $scope.year = Number($scope.year) - 1; + } + , nextYear = function nextYear() { - $scope.year = Number($scope.year) + 1; - } - , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { - - var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g + $scope.year = Number($scope.year) + 1; + } + , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { + + var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g ,formatDate,dateSplit, m, d, y, index, el, longName, shortName; - for (index = 0; index < datetime.MONTH.length; index += 1) { - longName = datetime.MONTH[index]; - shortName = datetime.SHORTMONTH[index]; + for (index = 0; index < datetime.MONTH.length; index += 1) { + longName = datetime.MONTH[index]; + shortName = datetime.SHORTMONTH[index]; - if (rawDate.indexOf(longName) !== -1) { - rawDate = rawDate.replace(longName, index + 1); - break; - } + if (rawDate.indexOf(longName) !== -1) { + rawDate = rawDate.replace(longName, index + 1); + break; + } - if (rawDate.indexOf(shortName) !== -1) { - rawDate = rawDate.replace(shortName, index + 1); - break; - } + if (rawDate.indexOf(shortName) !== -1) { + rawDate = rawDate.replace(shortName, index + 1); + break; } + } - dateSplit = rawDate - .split(/\D/) - .filter(function dateSplitFilter(item) { - return item.length > 0; - }); - - formatDate = dateFormatDefinition - .match(formattingTokens) - .filter(function fromatDateFilter(item) { - return item.match(/^[a-zA-Z]+$/i) !== null; - }); - - for (index = 0; index < formatDate.length; index += 1) { - el = formatDate[index]; - - switch (true) { - case el.indexOf('d') !== -1: { - d = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - case el.indexOf('M') !== -1: { - m = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - case el.indexOf('y') !== -1: { - y = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - default: { - break; - } + dateSplit = rawDate + .split(/\D/) + .filter(function dateSplitFilter(item) { + return item.length > 0; + }); + + formatDate = dateFormatDefinition + .match(formattingTokens) + .filter(function fromatDateFilter(item) { + return item.match(/^[a-zA-Z]+$/i) !== null; + }); + + for (index = 0; index < formatDate.length; index += 1) { + el = formatDate[index]; + + switch (true) { + case el.indexOf('d') !== -1: { + d = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + case el.indexOf('M') !== -1: { + m = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + case el.indexOf('y') !== -1: { + y = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + default: { + break; } } - - return new Date(y + '/' + m + '/' + d); } - , setInputValue = function setInputValue() { - - if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && - $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); + return new Date(y + '/' + m + '/' + d); + } + , setInputValue = function setInputValue() { - if (attr.dateFormat) { + if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && + $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - thisInput.val($filter('date')(modelDate, dateFormat)); - } else { + var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); - thisInput.val(modelDate); - } + if (attr.dateFormat) { - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; + thisInput.val($filter('date')(modelDate, dateFormat)); } else { - return false; + thisInput.val(modelDate); } - } - , classHelper = { - 'add': function add(ele, klass) { - var classes; - if (ele.className.indexOf(klass) > -1) { - - return; - } + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; + } else { - classes = ele.className.split(' '); - classes.push(klass); - ele.className = classes.join(' '); - }, - 'remove': function remove(ele, klass) { - var i - , classes; + return false; + } + } + , classHelper = { + 'add': function add(ele, klass) { + var classes; - if (ele.className.indexOf(klass) === -1) { + if (ele.className.indexOf(klass) > -1) { - return; - } + return; + } - classes = ele.className.split(' '); - for (i = 0; i < classes.length; i += 1) { + classes = ele.className.split(' '); + classes.push(klass); + ele.className = classes.join(' '); + }, + 'remove': function remove(ele, klass) { + var i + , classes; - if (classes[i] === klass) { + if (ele.className.indexOf(klass) === -1) { - classes = classes.slice(0, i).concat(classes.slice(i + 1)); - break; - } - } - ele.className = classes.join(' '); + return; } - } - , showCalendar = function showCalendar() { - //lets hide all the latest instances of datepicker - pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar'); - angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) { - if (pageDatepickers[key].classList) { + classes = ele.className.split(' '); + for (i = 0; i < classes.length; i += 1) { - pageDatepickers[key].classList.remove('_720kb-datepicker-open'); - } else { + if (classes[i] === klass) { - classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); + classes = classes.slice(0, i).concat(classes.slice(i + 1)); + break; } - }); + } + ele.className = classes.join(' '); + } + } + , showCalendar = function showCalendar() { + //lets hide all the latest instances of datepicker + pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar'); - if (theCalendar.classList) { + angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) { + if (pageDatepickers[key].classList) { - theCalendar.classList.add('_720kb-datepicker-open'); - if (dateFormat) { - date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); - } else { - date = new Date(thisInput[0].value.toString()); - } - $scope.selectedMonth = Number($filter('date')(date, 'MM')); - $scope.selectedDay = Number($filter('date')(date, 'dd')); - $scope.selectedYear = Number($filter('date')(date, 'yyyy')); + pageDatepickers[key].classList.remove('_720kb-datepicker-open'); } else { - classHelper.add(theCalendar, '_720kb-datepicker-open'); - } - $scope.today = new Date(); - $timeout(function timeoutForYears() { - if ($scope.selectedDay) { - $scope.year = $scope.selectedYear; - $scope.monthNumber = $scope.selectedMonth; - } else { - $scope.year = $scope.today.getFullYear(); - $scope.monthNumber = $scope.today.getMonth() + 1; - } - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - setDaysInMonth($scope.monthNumber, $scope.year); - }, 0); - } - , checkToggle = function checkToggle() { - if (!$scope.datepickerToggle) { - - return true; + classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); } + }); - return $scope.$eval($scope.datepickerToggle); - } - , checkVisibility = function checkVisibility() { - if (!$scope.datepickerShow) { + if (theCalendar.classList) { - return false; - } + theCalendar.classList.add('_720kb-datepicker-open'); if (dateFormat) { date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); } else { @@ -452,607 +409,664 @@ $scope.selectedMonth = Number($filter('date')(date, 'MM')); $scope.selectedDay = Number($filter('date')(date, 'dd')); $scope.selectedYear = Number($filter('date')(date, 'yyyy')); - return $scope.$eval($scope.datepickerShow); + } else { + + classHelper.add(theCalendar, '_720kb-datepicker-open'); } - , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { + $scope.today = new Date(); + $timeout(function timeoutForYears() { + if ($scope.selectedDay) { + $scope.year = $scope.selectedYear; + $scope.monthNumber = $scope.selectedMonth; + } else { + $scope.year = $scope.today.getFullYear(); + $scope.monthNumber = $scope.today.getMonth() + 1; + } + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + setDaysInMonth($scope.monthNumber, $scope.year); + }, 0); + } + , checkToggle = function checkToggle() { + if (!$scope.datepickerToggle) { - if (newValue && !isNaN(Date.parse(newValue))) { + return true; + } - date = new Date(newValue); + return $scope.$eval($scope.datepickerToggle); + } + , checkVisibility = function checkVisibility() { + if (!$scope.datepickerShow) { - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + return false; + } + if (dateFormat) { + date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); + } else { + date = new Date(thisInput[0].value.toString()); + } + $scope.selectedMonth = Number($filter('date')(date, 'MM')); + $scope.selectedDay = Number($filter('date')(date, 'dd')); + $scope.selectedYear = Number($filter('date')(date, 'yyyy')); + return $scope.$eval($scope.datepickerShow); + } + , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { - setDaysInMonth($scope.monthNumber, $scope.year); + if (newValue && !isNaN(Date.parse(newValue))) { - if ($scope.dateSetHidden !== 'true') { + date = new Date(newValue); + + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + + setDaysInMonth($scope.monthNumber, $scope.year); + + if ($scope.dateSetHidden !== 'true') { - setInputValue(); - } - } - }) - , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) { - if (newValue) { - resetToMinDate(); - } - }) - , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) { - if (newValue) { - resetToMaxDate(); - } - }) - , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) { - if (newValue) { setInputValue(); } - }) - , unregisterDateDisabledDatesWatcher = $scope.$watch('dateDisabledDates', function dateDisabledDatesWatcher(newValue) { - if (newValue) { - dateDisabledDates = $scope.$eval(newValue); - - if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { - thisInput.val(''); - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; - } + } + }) + , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) { + if (newValue) { + resetToMinDate(); + } + }) + , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) { + if (newValue) { + resetToMaxDate(); + } + }) + , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) { + if (newValue) { + setInputValue(); + } + }) + , unregisterDateDisabledDatesWatcher = $scope.$watch('dateDisabledDates', function dateDisabledDatesWatcher(newValue) { + if (newValue) { + dateDisabledDates = $scope.$eval(newValue); + + if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { + thisInput.val(''); + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; } - }) - , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) { - if (newValue) { - dateEnabledDates = $scope.$eval(newValue); - - if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { - thisInput.val(''); - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; - } + } + }) + , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) { + if (newValue) { + dateEnabledDates = $scope.$eval(newValue); + + if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { + thisInput.val(''); + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; } - }); + } + }); - $scope.nextMonth = function nextMonth() { + $scope.nextMonth = function nextMonth() { - if ($scope.monthNumber === 12) { + if ($scope.monthNumber === 12) { - $scope.monthNumber = 1; - //its happy new year - nextYear(); - } else { + $scope.monthNumber = 1; + //its happy new year + nextYear(); + } else { - $scope.monthNumber += 1; - } + $scope.monthNumber += 1; + } - //check if max date is ok - if ($scope.dateMaxLimit) { + //check if max date is ok + if ($scope.dateMaxLimit) { - if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { + if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { - resetToMaxDate(); - } + resetToMaxDate(); } + } - //set next month - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - //reinit days - setDaysInMonth($scope.monthNumber, $scope.year); - //deactivate selected day - $scope.day = undefined; - }; + //set next month + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + //reinit days + setDaysInMonth($scope.monthNumber, $scope.year); + //deactivate selected day + $scope.day = undefined; + }; - $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() { - var monthNumber = $scope.monthNumber - , year = $scope.year - , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month + $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() { + var monthNumber = $scope.monthNumber + , year = $scope.year + , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month - if (monthNumber === 1) { + if (monthNumber === 1) { - monthNumber = 12; - year = year - 1; - } else { + monthNumber = 12; + year = year - 1; + } else { - monthNumber -= 1; - } + monthNumber -= 1; + } - if ($scope.dateMinLimit) { - if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { + if ($scope.dateMinLimit) { + if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { - return false; - } + return false; } + } - return true; - }; + return true; + }; - $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { - var monthNumber = $scope.monthNumber - , year = $scope.year; + $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { + var monthNumber = $scope.monthNumber + , year = $scope.year; - if (monthNumber === 12) { + if (monthNumber === 12) { - monthNumber = 1; - year += 1; - } else { + monthNumber = 1; + year += 1; + } else { - monthNumber += 1; - } + monthNumber += 1; + } - if ($scope.dateMaxLimit) { - if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { + if ($scope.dateMaxLimit) { + if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { - return false; - } + return false; } + } - return true; - }; + return true; + }; - $scope.prevMonth = function managePrevMonth() { + $scope.prevMonth = function managePrevMonth() { - if ($scope.monthNumber === 1) { + if ($scope.monthNumber === 1) { - $scope.monthNumber = 12; - //its happy new year - prevYear(); - } else { + $scope.monthNumber = 12; + //its happy new year + prevYear(); + } else { - $scope.monthNumber -= 1; - } - //check if min date is ok - if ($scope.dateMinLimit) { + $scope.monthNumber -= 1; + } + //check if min date is ok + if ($scope.dateMinLimit) { - if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { + if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { - resetToMinDate(); - } + resetToMinDate(); } - //set next month - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - //reinit days - setDaysInMonth($scope.monthNumber, $scope.year); - //deactivate selected day + } + //set next month + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + //reinit days + setDaysInMonth($scope.monthNumber, $scope.year); + //deactivate selected day + $scope.day = undefined; + }; + + $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) { + + $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); + setDaysInMonth($scope.monthNumber, $scope.year); + setInputValue(); + }; + + $scope.setMonth = function setMonth(selectedMonthNumber) { + $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); + $scope.showMonthPagination = false; + $scope.month = selectedMonthNumber; + setDaysInMonth($scope.monthNumber, $scope.year); + }; + + $scope.setNewYear = function setNewYear(year) { + + //deactivate selected day + if (!isMobile) { $scope.day = undefined; - }; + } - $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) { + if ($scope.dateMaxLimit && + $scope.year < Number(year)) { - $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); - setDaysInMonth($scope.monthNumber, $scope.year); - setInputValue(); - }; + if (!$scope.isSelectableMaxYear(year)) { + + return; + } + } else if ($scope.dateMinLimit && + $scope.year > Number(year)) { - $scope.setNewYear = function setNewYear(year) { + if (!$scope.isSelectableMinYear(year)) { - //deactivate selected day - if (!isMobile) { - $scope.day = undefined; + return; } + } - if ($scope.dateMaxLimit && - $scope.year < Number(year)) { + $scope.paginateYears(year); + $scope.showYearsPagination = false; + $timeout(function timeoutForYears() { + $scope.year = Number(year); + setDaysInMonth($scope.monthNumber, $scope.year); + }, 0); + }; - if (!$scope.isSelectableMaxYear(year)) { + $scope.showMPagination = function showMPagination() { + $scope.showYearsPagination = false; + $scope.showMonthPagination = !$scope.showMonthPagination; + }; - return; - } - } else if ($scope.dateMinLimit && - $scope.year > Number(year)) { + $scope.showYPagination = function showYPagination() { + $scope.showMonthPagination = false; + $scope.showYearsPagination = !$scope.showYearsPagination; + }; - if (!$scope.isSelectableMinYear(year)) { + $scope.hideCalendar = function hideCalendar() { + if (theCalendar.classList) { + theCalendar.classList.remove('_720kb-datepicker-open'); + } else { - return; + classHelper.remove(theCalendar, '_720kb-datepicker-open'); + } + }; + + $scope.setDatepickerDay = function setDatepickerDay(day, type) { + if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && + $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && + $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && + $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { + + if (type === 'previous') { + if ($scope.monthNumber !== 1) { + $scope.monthNumber -= 1; + } else { + $scope.monthNumber = 12; + $scope.year -= 1; + } + } else if (type === 'next') { + if ($scope.monthNumber !== 12) { + $scope.monthNumber += 1; + } else { + $scope.monthNumber = 1; + $scope.year += 1; } } - $scope.paginateYears(year); - $scope.showYearsPagination = false; - $timeout(function timeoutForYears() { - $scope.year = Number(year); - setDaysInMonth($scope.monthNumber, $scope.year); - }, 0); - }; + $scope.day = Number(day); + $scope.selectedDay = $scope.day; + $scope.selectedMonth = $scope.monthNumber; + $scope.selectedYear = $scope.year; - $scope.hideCalendar = function hideCalendar() { - if (theCalendar.classList) { - theCalendar.classList.remove('_720kb-datepicker-open'); - } else { + setInputValue(); - classHelper.remove(theCalendar, '_720kb-datepicker-open'); + if (attr.hasOwnProperty('dateRefocus')) { + thisInput[0].focus(); } - }; - - $scope.setDatepickerDay = function setDatepickerDay(day, type) { - if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && - $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && - $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && - $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { - - if (type === 'previous') { - if ($scope.monthNumber !== 1) { - $scope.monthNumber -= 1; - } else { - $scope.monthNumber = 12; - } - } else if (type === 'next') { - if ($scope.monthNumber !== 12) { - $scope.monthNumber += 1; - } else { - $scope.monthNumber = 1; - } - } - $scope.day = Number(day); - $scope.selectedDay = $scope.day; - $scope.selectedMonth = $scope.monthNumber; - $scope.selectedYear = $scope.year; + $scope.hideCalendar(); + } + }; - setInputValue(); + $scope.paginateYears = function paginateYears(startingYear) { + var i + , theNewYears = [] + , daysToPrepend = 10 + , daysToAppend = 10; - if (attr.hasOwnProperty('dateRefocus')) { - thisInput[0].focus(); - } + $scope.paginationYears = []; + if (isMobile) { - $scope.hideCalendar(); + daysToPrepend = 50; + daysToAppend = 50; + if ( $scope.dateMinLimit && $scope.dateMaxLimit) { + + startingYear = new Date($scope.dateMaxLimit).getFullYear(); + daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); + daysToAppend = 1; } - }; + } - $scope.paginateYears = function paginateYears(startingYear) { - var i - , theNewYears = [] - , daysToPrepend = 10 - , daysToAppend = 10; + for (i = daysToPrepend; i > 0; i -= 1) { - $scope.paginationYears = []; - if (isMobile) { + theNewYears.push(Number(startingYear) - i); + } - daysToPrepend = 50; - daysToAppend = 50; - if ( $scope.dateMinLimit && $scope.dateMaxLimit) { + for (i = 0; i < daysToAppend; i += 1) { - startingYear = new Date($scope.dateMaxLimit).getFullYear(); - daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); - daysToAppend = 1; - } - } + theNewYears.push(Number(startingYear) + i); + } + //date typing in input date-typer + if ($scope.dateTyper === 'true') { - for (i = daysToPrepend; i > 0; i -= 1) { + thisInput.on('keyup blur', function onTyping() { - theNewYears.push(Number(startingYear) - i); - } + if (thisInput[0].value && + thisInput[0].value.length && + thisInput[0].value.length > 0) { - for (i = 0; i < daysToAppend; i += 1) { + try { + if (dateFormat) { + date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); + } else { + date = new Date(thisInput[0].value.toString()); + } - theNewYears.push(Number(startingYear) + i); - } - //date typing in input date-typer - if ($scope.dateTyper === 'true') { - - thisInput.on('keyup blur', function onTyping() { - - if (thisInput[0].value && - thisInput[0].value.length && - thisInput[0].value.length > 0) { - - try { - if (dateFormat) { - date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); - } else { - date = new Date(thisInput[0].value.toString()); - } - - if (date.getFullYear() && - !isNaN(date.getDay()) && - !isNaN(date.getMonth()) && - $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) && - $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) && - $scope.isSelectableMaxDate(date) && - $scope.isSelectableMinDate(date)) { - - $scope.$apply(function applyTyping() { - - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - - if (date.getFullYear().toString().length === 4) { - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like - } - setDaysInMonth($scope.monthNumber, $scope.year); - }); - } - } catch (e) { - - return e; + if (date.getFullYear() && + !isNaN(date.getDay()) && + !isNaN(date.getMonth()) && + $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) && + $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) && + $scope.isSelectableMaxDate(date) && + $scope.isSelectableMinDate(date)) { + + $scope.$apply(function applyTyping() { + + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + + if (date.getFullYear().toString().length === 4) { + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + } + setDaysInMonth($scope.monthNumber, $scope.year); + }); } + } catch (e) { + + return e; } - }); - } - //check range dates - if ($scope.dateMaxLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { + } + }); + } + //check range dates + if ($scope.dateMaxLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { - $scope.paginationYearsNextDisabled = true; - } else { + $scope.paginationYearsNextDisabled = true; + } else { - $scope.paginationYearsNextDisabled = false; - } + $scope.paginationYearsNextDisabled = false; + } - if ($scope.dateMinLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { + if ($scope.dateMinLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { - $scope.paginationYearsPrevDisabled = true; - } else { + $scope.paginationYearsPrevDisabled = true; + } else { - $scope.paginationYearsPrevDisabled = false; - } + $scope.paginationYearsPrevDisabled = false; + } - $scope.paginationYears = theNewYears; - }; + $scope.paginationYears = theNewYears; + }; - $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { - var i = 0; + $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { + var i = 0; - if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) { - for (i; i <= dateDisabledWeekdays.length; i += 1) { - if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) { - return false; - } + if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) { + for (i; i <= dateDisabledWeekdays.length; i += 1) { + if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) { + return false; } } + } - return true; - }; + return true; + }; - $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) { - var i = 0; + $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) { + var i = 0; - if (dateDisabledDates && - dateDisabledDates.length > 0) { + if (dateDisabledDates && + dateDisabledDates.length > 0) { - for (i; i <= dateDisabledDates.length; i += 1) { + for (i; i <= dateDisabledDates.length; i += 1) { - if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - return false; - } + return false; } } + } - if (dateEnabledDates) { + if (dateEnabledDates) { - for (i; i <= dateEnabledDates.length; i += 1) { + for (i; i <= dateEnabledDates.length; i += 1) { - if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - return true; - } + return true; } - - return false; } - return true; - }; + return false; + } - $scope.isSelectableMinDate = function isSelectableMinDate(aDate) { - //if current date - if (!!$scope.dateMinLimit && - !!new Date($scope.dateMinLimit) && - new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) { + return true; + }; - return false; - } + $scope.isSelectableMinDate = function isSelectableMinDate(aDate) { + //if current date + if (!!$scope.dateMinLimit && + !!new Date($scope.dateMinLimit) && + new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) { - return true; - }; + return false; + } - $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) { - //if current date - if (!!$scope.dateMaxLimit && - !!new Date($scope.dateMaxLimit) && - new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) { + return true; + }; - return false; - } + $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) { + //if current date + if (!!$scope.dateMaxLimit && + !!new Date($scope.dateMaxLimit) && + new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) { - return true; - }; + return false; + } - $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { - if (!!$scope.dateMaxLimit && - year > new Date($scope.dateMaxLimit).getFullYear()) { + return true; + }; - return false; - } + $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { + if (!!$scope.dateMaxLimit && + year > new Date($scope.dateMaxLimit).getFullYear()) { - return true; - }; + return false; + } - $scope.isSelectableMinYear = function isSelectableMinYear(year) { - if (!!$scope.dateMinLimit && - year < new Date($scope.dateMinLimit).getFullYear()) { + return true; + }; - return false; - } + $scope.isSelectableMinYear = function isSelectableMinYear(year) { + if (!!$scope.dateMinLimit && + year < new Date($scope.dateMinLimit).getFullYear()) { - return true; - }; + return false; + } - $scope.validateWeekDay = function isValidWeekDay(weekDay) { - var validWeekDay = Number(weekDay, 10); - // making sure that the given option is valid - if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) { + return true; + }; - validWeekDay = 0; - } - return validWeekDay; - }; - - // respect previously configured interpolation symbols. - htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol()); - $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month'; - $scope.dateYearTitle = $scope.dateYearTitle || 'Select year'; - $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next'; - $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev'; - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); + $scope.validateWeekDay = function isValidWeekDay(weekDay) { + var validWeekDay = Number(weekDay, 10); + // making sure that the given option is valid + if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) { - if ($scope.dateMaxLimit) { + validWeekDay = 0; + } + return validWeekDay; + }; - $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like - } else { + // respect previously configured interpolation symbols. + htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol()); + $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month'; + $scope.dateYearTitle = $scope.dateYearTitle || 'Select year'; + $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next'; + $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev'; + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like - } - $scope.months = datetime.MONTH; + if ($scope.dateMaxLimit) { - $scope.daysInString = []; - for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { + $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like + } else { - $scope.daysInString.push(n % 7); - } - $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + } + $scope.months = datetime.MONTH; - return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); - }); + $scope.daysInString = []; + for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { - //create the calendar holder and append where needed - if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('.') !== -1) { + $scope.daysInString.push(n % 7); + } + $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { - $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); - angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); + }); - theCalendar = angular.element(el)[0]; - })); - } else if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('#') !== -1) { + //create the calendar holder and append where needed + if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('.') !== -1) { - $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); - angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); + angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - theCalendar = angular.element(el)[0]; - })); - } else if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo === 'body') { - $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8)); - angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + theCalendar = angular.element(el)[0]; + })); + } else if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('#') !== -1) { - theCalendar = angular.element(el)[0]; - })); - } else { + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); + angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - thisInput.after($compile(angular.element(htmlTemplate))($scope)); - //get the calendar as element - theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); - } - //if datepicker-toggle="" is not present or true by default - if (checkToggle()) { + theCalendar = angular.element(el)[0]; + })); + } else if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo === 'body') { + $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8)); + angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - thisInput.on('focus click focusin', function onFocusAndClick() { + theCalendar = angular.element(el)[0]; + })); + } else { - isMouseOnInput = true; + thisInput.after($compile(angular.element(htmlTemplate))($scope)); + //get the calendar as element + theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); + } + //if datepicker-toggle="" is not present or true by default + if (checkToggle()) { - if (!isMouseOn && - !isMouseOnInput && theCalendar) { + thisInput.on('focus click focusin', function onFocusAndClick() { - $scope.hideCalendar(); - } else { + isMouseOnInput = true; - showCalendar(); - } - }); - } + if (!isMouseOn && + !isMouseOnInput && theCalendar) { - thisInput.on('focusout blur', function onBlurAndFocusOut() { + $scope.hideCalendar(); + } else { - isMouseOnInput = false; + showCalendar(); + } }); - //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed - angular.element(theCalendar).on('mouseenter', function onMouseEnter() { + } - isMouseOn = true; - }); + thisInput.on('focusout blur', function onBlurAndFocusOut() { - angular.element(theCalendar).on('mouseleave', function onMouseLeave() { + isMouseOnInput = false; + }); + //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed + angular.element(theCalendar).on('mouseenter', function onMouseEnter() { - isMouseOn = false; - }); + isMouseOn = true; + }); - angular.element(theCalendar).on('focusin', function onCalendarFocus() { + angular.element(theCalendar).on('mouseleave', function onMouseLeave() { - isMouseOn = true; - }); + isMouseOn = false; + }); - angular.element($window).on('click focus focusin', onClickOnWindow); + angular.element(theCalendar).on('focusin', function onCalendarFocus() { - //check always if given range of dates is ok - if ($scope.dateMinLimit && - !$scope.isSelectableMinYear($scope.year) || - !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { + isMouseOn = true; + }); - resetToMinDate(); - } + angular.element($window).on('click focus focusin', onClickOnWindow); - if ($scope.dateMaxLimit && - !$scope.isSelectableMaxYear($scope.year) || - !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { + //check always if given range of dates is ok + if ($scope.dateMinLimit && + !$scope.isSelectableMinYear($scope.year) || + !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - resetToMaxDate(); - } + resetToMinDate(); + } - //datepicker boot start - $scope.paginateYears($scope.year); + if ($scope.dateMaxLimit && + !$scope.isSelectableMaxYear($scope.year) || + !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - setDaysInMonth($scope.monthNumber, $scope.year); - $scope.checkVisibility = checkVisibility; - - $scope.$on('$destroy', function unregisterListener() { - - unregisterDataSetWatcher(); - unregisterDateMinLimitWatcher(); - unregisterDateMaxLimitWatcher(); - unregisterDateFormatWatcher(); - unregisterDateDisabledDatesWatcher(); - unregisterDateEnabledDatesWatcher(); - thisInput.off('focus click focusout blur'); - angular.element(theCalendar).off('mouseenter mouseleave focusin'); - angular.element($window).off('click focus focusin', onClickOnWindow); - }); - }; + resetToMaxDate(); + } - return { - 'restrict': 'AEC', - 'scope': { - 'dateSet': '@', - 'dateMinLimit': '@', - 'dateMaxLimit': '@', - 'dateMonthTitle': '@', - 'dateYearTitle': '@', - 'buttonNextTitle': '@', - 'buttonPrevTitle': '@', - 'dateDisabledDates': '@', - 'dateEnabledDates': '@', - 'dateDisabledWeekdays': '@', - 'dateSetHidden': '@', - 'dateTyper': '@', - 'dateWeekStartDay': '@', - 'datepickerAppendTo': '@', - 'datepickerToggle': '@', - 'datepickerClass': '@', - 'datepickerShow': '@', - 'anyDay': '@' - }, - 'link': linkingFunction - }; + //datepicker boot start + $scope.paginateYears($scope.year); + + setDaysInMonth($scope.monthNumber, $scope.year); + $scope.checkVisibility = checkVisibility; + + $scope.$on('$destroy', function unregisterListener() { + + unregisterDataSetWatcher(); + unregisterDateMinLimitWatcher(); + unregisterDateMaxLimitWatcher(); + unregisterDateFormatWatcher(); + unregisterDateDisabledDatesWatcher(); + unregisterDateEnabledDatesWatcher(); + thisInput.off('focus click focusout blur'); + angular.element(theCalendar).off('mouseenter mouseleave focusin'); + angular.element($window).off('click focus focusin', onClickOnWindow); + }); + }; + + return { + 'restrict': 'AEC', + 'scope': { + 'dateSet': '@', + 'dateMinLimit': '@', + 'dateMaxLimit': '@', + 'dateMonthTitle': '@', + 'dateYearTitle': '@', + 'buttonNextTitle': '@', + 'buttonPrevTitle': '@', + 'dateDisabledDates': '@', + 'dateEnabledDates': '@', + 'dateDisabledWeekdays': '@', + 'dateSetHidden': '@', + 'dateTyper': '@', + 'dateWeekStartDay': '@', + 'datepickerAppendTo': '@', + 'datepickerToggle': '@', + 'datepickerClass': '@', + 'datepickerShow': '@', + 'anyDay': '@' + }, + 'link': linkingFunction }; + }; angular.module('720kb.datepicker', []) - .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]); + .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]); }(angular, navigator)); diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index fad189c..4317f65 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -4,9 +4,9 @@ * Released by 720kb.net under the MIT license * www.opensource.org/licenses/MIT * - * 2018-03-05 + * 2018-03-07 */ -!function(I,e){"use strict";var C=function(){if(e.userAgent&&(e.userAgent.match(/Android/i)||e.userAgent.match(/webOS/i)||e.userAgent.match(/iPhone/i)||e.userAgent.match(/iPad/i)||e.userAgent.match(/iPod/i)||e.userAgent.match(/BlackBerry/i)||e.userAgent.match(/Windows Phone/i)))return!0}(),B=function(e,a,t){var n,i,r=['
',"
"],d=(n=e,i=a,t&&(C=!1),C?['
','
','","
","
",'
','
','","
","
"]:['
','
','',n,"","
",'
',"{{month}} ",'',"","{{year}}","","","","
",'
','',i,"","
","
"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','
',"{{d}}","
","
"],o=['"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(W,E,H,O,F,j){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,n,i,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,g=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,k=H.DATETIME_FORMATS,M=B(l,c,g),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(i=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,j(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):Y(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:u.monthNumber=12:"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:u.monthNumber=1),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,w(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],n=10,i=10;for(u.paginationYears=[],C&&(i=n=50,u.dateMinLimit&&u.dateMaxLimit&&(n=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),i=1)),a=n;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e',""],d=(i=e,n=a,t&&(C=!1),C?['
','
',"
","
",'
','
','","","
","
"]:['
','
',"
","
",'
','
',"
","
",'"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','","
"],o=['
','
',"{{d}}","
","
"],s=['"],m=function(e){r.splice(r.length-1,0,e)};return d.forEach(m),l.forEach(m),c.forEach(m),o.forEach(m),s.forEach(m),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(E,W,O,H,j,F){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,i,n,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,k=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,g=O.DATETIME_FORMATS,M=B(l,c,k),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,i,n,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(n=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,F(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.showMPagination=function(){u.showYearsPagination=!1,u.showMonthPagination=!u.showMonthPagination},u.showYPagination=function(){u.showMonthPagination=!1,u.showYearsPagination=!u.showYearsPagination},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):_(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:(u.monthNumber=12,u.year-=1):"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:(u.monthNumber=1,u.year+=1)),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,S(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],i=10,n=10;for(u.paginationYears=[],C&&(n=i=50,u.dateMinLimit&&u.dateMaxLimit&&(i=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),n=1)),a=i;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e', - '
', - '', - '
', - '', - '
', - '
', - '', - '
', - '
' - ]; - } + if (isMobile) { return [ '
', - '', - '
', - '{{month}} ', - '', - '', - '{{year}}', - '', - '', - '', - '
', - '', + '
', + '
', + '
', + '
', + '
', + '', + '', + '
', '
' ]; } + + return [ + '
', + '
', + "
", + "
", + '
', + '
', + "
", + "
", + '' + ]; + } , generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) { - return [ - '
', - '
', - '', - '{{y}}', - '', - '
', - '', - '
' - ]; - } + return ['
', '", '", "
"]; + } + + , generateMonthsPaginationHeader = function generateMonthsPaginationHeader() { + + return ['
', '", "
"]; + + } , generateDaysColumns = function generateDaysColumns() { - return [ + return [ '
', - '
', - '{{d}}', - '
', + '
', + '{{d}}', + '
', '
' - ]; - } + ]; + } , generateDays = function generateDays() { - - return [ - '' - ]; - } + return [ + '' + ]; + } , generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton, preventMobile) { - var toReturn = [ - '
', - '
' - ] + var toReturn = [ + '
', + '
' + ] , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile) , yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton) + , monthsPaginationHeader = generateMonthsPaginationHeader() , daysColumns = generateDaysColumns() , days = generateDays() , iterator = function iterator(aRow) { - toReturn.splice(toReturn.length - 1, 0, aRow); - }; + toReturn.splice(toReturn.length - 1, 0, aRow); + }; - monthAndYearHeader.forEach(iterator); - yearsPaginationHeader.forEach(iterator); - daysColumns.forEach(iterator); - days.forEach(iterator); + monthAndYearHeader.forEach(iterator); + yearsPaginationHeader.forEach(iterator); + monthsPaginationHeader.forEach(iterator); + daysColumns.forEach(iterator); + days.forEach(iterator); - return toReturn.join(''); - } + return toReturn.join(''); + } , datepickerDirective = function datepickerDirective($window, $compile, $locale, $filter, $interpolate, $timeout) { - var linkingFunction = function linkingFunction($scope, element, attr) { - - //get child input - var selector = attr.selector - , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0]) - , theCalendar - , defaultPrevButton = '' - , defaultNextButton = '' - , prevButton = attr.buttonPrev || defaultPrevButton - , nextButton = attr.buttonNext || defaultNextButton - , dateFormat = attr.dateFormat - //, dateMinLimit - //, dateMaxLimit - , dateDisabledDates = $scope.$eval($scope.dateDisabledDates) - , dateEnabledDates = $scope.$eval($scope.dateEnabledDates) - , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays) - , date = new Date() - , isMouseOn = false - , isMouseOnInput = false - , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false' - , datetime = $locale.DATETIME_FORMATS - , pageDatepickers - , hours24h = 86400000 - , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile) - , n - , onClickOnWindow = function onClickOnWindow() { - - if (!isMouseOn && - !isMouseOnInput && theCalendar) { - - $scope.hideCalendar(); - } + var linkingFunction = function linkingFunction($scope, element, attr) { + + //get child input + var selector = attr.selector + , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0]) + , theCalendar + , defaultPrevButton = '' + , defaultNextButton = '' + , prevButton = attr.buttonPrev || defaultPrevButton + , nextButton = attr.buttonNext || defaultNextButton + , dateFormat = attr.dateFormat + //, dateMinLimit + //, dateMaxLimit + , dateDisabledDates = $scope.$eval($scope.dateDisabledDates) + , dateEnabledDates = $scope.$eval($scope.dateEnabledDates) + , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays) + , date = new Date() + , isMouseOn = false + , isMouseOnInput = false + , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false' + , datetime = $locale.DATETIME_FORMATS + , pageDatepickers + , hours24h = 86400000 + , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile) + , n + , onClickOnWindow = function onClickOnWindow() { + + if (!isMouseOn && + !isMouseOnInput && theCalendar) { + + $scope.hideCalendar(); } - , setDaysInMonth = function setDaysInMonth(month, year) { + } + , setDaysInMonth = function setDaysInMonth(month, year) { - var i - , limitDate = new Date(year, month, 0).getDate() - , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay() - , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay() - , prevMonthDays = [] - , nextMonthDays = [] - , howManyNextDays - , howManyPreviousDays - , monthAlias - , dateWeekEndDay; - - $scope.days = []; - $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); - dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7; - - for (i = 1; i <= limitDate; i += 1) { - - $scope.days.push(i); - } + var i + , limitDate = new Date(year, month, 0).getDate() + , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay() + , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay() + , prevMonthDays = [] + , nextMonthDays = [] + , howManyNextDays + , howManyPreviousDays + , monthAlias + , dateWeekEndDay; + + $scope.days = []; + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); + dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7; + + for (i = 1; i <= limitDate; i += 1) { + + $scope.days.push(i); + } - //get previous month days if first day in month is not first day in week - if (firstDayMonthNumber === $scope.dateWeekStartDay) { + //get previous month days if first day in month is not first day in week + if (firstDayMonthNumber === $scope.dateWeekStartDay) { - //no need for it - $scope.prevMonthDays = []; - } else { + //no need for it + $scope.prevMonthDays = []; + } else { - howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; + howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; - if (firstDayMonthNumber < $scope.dateWeekStartDay) { + if (firstDayMonthNumber < $scope.dateWeekStartDay) { - howManyPreviousDays += 7; - } + howManyPreviousDays += 7; + } - //get previous month - if (Number(month) === 1) { + //get previous month + if (Number(month) === 1) { - monthAlias = 12; - } else { + monthAlias = 12; + } else { - monthAlias = month - 1; - } - //return previous month days - for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { + monthAlias = month - 1; + } + //return previous month days + for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { - prevMonthDays.push(i); - } - //attach previous month days - $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); + prevMonthDays.push(i); } + //attach previous month days + $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); + } - //get next month days if last day in month is not last day in week - if (lastDayMonthNumber === dateWeekEndDay) { - //no need for it - $scope.nextMonthDays = []; - } else { - howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; + //get next month days if last day in month is not last day in week + if (lastDayMonthNumber === dateWeekEndDay) { + //no need for it + $scope.nextMonthDays = []; + } else { + howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; - if (lastDayMonthNumber < $scope.dateWeekStartDay) { + if (lastDayMonthNumber < $scope.dateWeekStartDay) { - howManyNextDays -= 7; - } - //get previous month + howManyNextDays -= 7; + } + //get previous month - //return next month days - for (i = 1; i <= howManyNextDays; i += 1) { + //return next month days + for (i = 1; i <= howManyNextDays; i += 1) { - nextMonthDays.push(i); - } - //attach previous month days - $scope.nextMonthDays = nextMonthDays; + nextMonthDays.push(i); } + //attach previous month days + $scope.nextMonthDays = nextMonthDays; } - , resetToMinDate = function resetToMinDate() { + } + , resetToMinDate = function resetToMinDate() { - $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM'); - $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM')); - $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); - $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); + $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM'); + $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM')); + $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd')); + $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy')); - setDaysInMonth($scope.monthNumber, $scope.year); - } - , resetToMaxDate = function resetToMaxDate() { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , resetToMaxDate = function resetToMaxDate() { - $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM'); - $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM')); - $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd')); - $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy')); + $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM'); + $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM')); + $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd')); + $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy')); - setDaysInMonth($scope.monthNumber, $scope.year); - } - , prevYear = function prevYear() { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , prevYear = function prevYear() { - $scope.year = Number($scope.year) - 1; - } - , nextYear = function nextYear() { + $scope.year = Number($scope.year) - 1; + } + , nextYear = function nextYear() { - $scope.year = Number($scope.year) + 1; - } - , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { - - var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g + $scope.year = Number($scope.year) + 1; + } + , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { + + var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g ,formatDate,dateSplit, m, d, y, index, el, longName, shortName; - for (index = 0; index < datetime.MONTH.length; index += 1) { - longName = datetime.MONTH[index]; - shortName = datetime.SHORTMONTH[index]; + for (index = 0; index < datetime.MONTH.length; index += 1) { + longName = datetime.MONTH[index]; + shortName = datetime.SHORTMONTH[index]; - if (rawDate.indexOf(longName) !== -1) { - rawDate = rawDate.replace(longName, index + 1); - break; - } + if (rawDate.indexOf(longName) !== -1) { + rawDate = rawDate.replace(longName, index + 1); + break; + } - if (rawDate.indexOf(shortName) !== -1) { - rawDate = rawDate.replace(shortName, index + 1); - break; - } + if (rawDate.indexOf(shortName) !== -1) { + rawDate = rawDate.replace(shortName, index + 1); + break; } + } - dateSplit = rawDate - .split(/\D/) - .filter(function dateSplitFilter(item) { - return item.length > 0; - }); - - formatDate = dateFormatDefinition - .match(formattingTokens) - .filter(function fromatDateFilter(item) { - return item.match(/^[a-zA-Z]+$/i) !== null; - }); - - for (index = 0; index < formatDate.length; index += 1) { - el = formatDate[index]; - - switch (true) { - case el.indexOf('d') !== -1: { - d = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - case el.indexOf('M') !== -1: { - m = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - case el.indexOf('y') !== -1: { - y = dateSplit[index - (formatDate.length - dateSplit.length)]; - break; - } - default: { - break; - } + dateSplit = rawDate + .split(/\D/) + .filter(function dateSplitFilter(item) { + return item.length > 0; + }); + + formatDate = dateFormatDefinition + .match(formattingTokens) + .filter(function fromatDateFilter(item) { + return item.match(/^[a-zA-Z]+$/i) !== null; + }); + + for (index = 0; index < formatDate.length; index += 1) { + el = formatDate[index]; + + switch (true) { + case el.indexOf('d') !== -1: { + d = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + case el.indexOf('M') !== -1: { + m = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + case el.indexOf('y') !== -1: { + y = dateSplit[index - (formatDate.length - dateSplit.length)]; + break; + } + default: { + break; } } - - return new Date(y + '/' + m + '/' + d); } - , setInputValue = function setInputValue() { - - if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && - $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); + return new Date(y + '/' + m + '/' + d); + } + , setInputValue = function setInputValue() { - if (attr.dateFormat) { + if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && + $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - thisInput.val($filter('date')(modelDate, dateFormat)); - } else { + var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); - thisInput.val(modelDate); - } + if (attr.dateFormat) { - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; + thisInput.val($filter('date')(modelDate, dateFormat)); } else { - return false; + thisInput.val(modelDate); } - } - , classHelper = { - 'add': function add(ele, klass) { - var classes; - if (ele.className.indexOf(klass) > -1) { - - return; - } + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; + } else { - classes = ele.className.split(' '); - classes.push(klass); - ele.className = classes.join(' '); - }, - 'remove': function remove(ele, klass) { - var i - , classes; + return false; + } + } + , classHelper = { + 'add': function add(ele, klass) { + var classes; - if (ele.className.indexOf(klass) === -1) { + if (ele.className.indexOf(klass) > -1) { - return; - } + return; + } - classes = ele.className.split(' '); - for (i = 0; i < classes.length; i += 1) { + classes = ele.className.split(' '); + classes.push(klass); + ele.className = classes.join(' '); + }, + 'remove': function remove(ele, klass) { + var i + , classes; - if (classes[i] === klass) { + if (ele.className.indexOf(klass) === -1) { - classes = classes.slice(0, i).concat(classes.slice(i + 1)); - break; - } - } - ele.className = classes.join(' '); + return; } - } - , showCalendar = function showCalendar() { - //lets hide all the latest instances of datepicker - pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar'); - angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) { - if (pageDatepickers[key].classList) { + classes = ele.className.split(' '); + for (i = 0; i < classes.length; i += 1) { - pageDatepickers[key].classList.remove('_720kb-datepicker-open'); - } else { + if (classes[i] === klass) { - classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); + classes = classes.slice(0, i).concat(classes.slice(i + 1)); + break; } - }); + } + ele.className = classes.join(' '); + } + } + , showCalendar = function showCalendar() { + //lets hide all the latest instances of datepicker + pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar'); - if (theCalendar.classList) { + angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) { + if (pageDatepickers[key].classList) { - theCalendar.classList.add('_720kb-datepicker-open'); - if (dateFormat) { - date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); - } else { - date = new Date(thisInput[0].value.toString()); - } - $scope.selectedMonth = Number($filter('date')(date, 'MM')); - $scope.selectedDay = Number($filter('date')(date, 'dd')); - $scope.selectedYear = Number($filter('date')(date, 'yyyy')); + pageDatepickers[key].classList.remove('_720kb-datepicker-open'); } else { - classHelper.add(theCalendar, '_720kb-datepicker-open'); - } - $scope.today = new Date(); - $timeout(function timeoutForYears() { - if ($scope.selectedDay) { - $scope.year = $scope.selectedYear; - $scope.monthNumber = $scope.selectedMonth; - } else { - $scope.year = $scope.today.getFullYear(); - $scope.monthNumber = $scope.today.getMonth() + 1; - } - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - setDaysInMonth($scope.monthNumber, $scope.year); - }, 0); - } - , checkToggle = function checkToggle() { - if (!$scope.datepickerToggle) { - - return true; + classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); } + }); - return $scope.$eval($scope.datepickerToggle); - } - , checkVisibility = function checkVisibility() { - if (!$scope.datepickerShow) { + if (theCalendar.classList) { - return false; - } + theCalendar.classList.add('_720kb-datepicker-open'); if (dateFormat) { date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); } else { @@ -452,607 +409,664 @@ $scope.selectedMonth = Number($filter('date')(date, 'MM')); $scope.selectedDay = Number($filter('date')(date, 'dd')); $scope.selectedYear = Number($filter('date')(date, 'yyyy')); - return $scope.$eval($scope.datepickerShow); + } else { + + classHelper.add(theCalendar, '_720kb-datepicker-open'); } - , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { + $scope.today = new Date(); + $timeout(function timeoutForYears() { + if ($scope.selectedDay) { + $scope.year = $scope.selectedYear; + $scope.monthNumber = $scope.selectedMonth; + } else { + $scope.year = $scope.today.getFullYear(); + $scope.monthNumber = $scope.today.getMonth() + 1; + } + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + setDaysInMonth($scope.monthNumber, $scope.year); + }, 0); + } + , checkToggle = function checkToggle() { + if (!$scope.datepickerToggle) { - if (newValue && !isNaN(Date.parse(newValue))) { + return true; + } - date = new Date(newValue); + return $scope.$eval($scope.datepickerToggle); + } + , checkVisibility = function checkVisibility() { + if (!$scope.datepickerShow) { - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + return false; + } + if (dateFormat) { + date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); + } else { + date = new Date(thisInput[0].value.toString()); + } + $scope.selectedMonth = Number($filter('date')(date, 'MM')); + $scope.selectedDay = Number($filter('date')(date, 'dd')); + $scope.selectedYear = Number($filter('date')(date, 'yyyy')); + return $scope.$eval($scope.datepickerShow); + } + , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { - setDaysInMonth($scope.monthNumber, $scope.year); + if (newValue && !isNaN(Date.parse(newValue))) { - if ($scope.dateSetHidden !== 'true') { + date = new Date(newValue); + + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + + setDaysInMonth($scope.monthNumber, $scope.year); + + if ($scope.dateSetHidden !== 'true') { - setInputValue(); - } - } - }) - , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) { - if (newValue) { - resetToMinDate(); - } - }) - , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) { - if (newValue) { - resetToMaxDate(); - } - }) - , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) { - if (newValue) { setInputValue(); } - }) - , unregisterDateDisabledDatesWatcher = $scope.$watch('dateDisabledDates', function dateDisabledDatesWatcher(newValue) { - if (newValue) { - dateDisabledDates = $scope.$eval(newValue); - - if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { - thisInput.val(''); - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; - } + } + }) + , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) { + if (newValue) { + resetToMinDate(); + } + }) + , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) { + if (newValue) { + resetToMaxDate(); + } + }) + , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) { + if (newValue) { + setInputValue(); + } + }) + , unregisterDateDisabledDatesWatcher = $scope.$watch('dateDisabledDates', function dateDisabledDatesWatcher(newValue) { + if (newValue) { + dateDisabledDates = $scope.$eval(newValue); + + if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { + thisInput.val(''); + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; } - }) - , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) { - if (newValue) { - dateEnabledDates = $scope.$eval(newValue); - - if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { - thisInput.val(''); - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; - } + } + }) + , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) { + if (newValue) { + dateEnabledDates = $scope.$eval(newValue); + + if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) { + thisInput.val(''); + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; } - }); + } + }); - $scope.nextMonth = function nextMonth() { + $scope.nextMonth = function nextMonth() { - if ($scope.monthNumber === 12) { + if ($scope.monthNumber === 12) { - $scope.monthNumber = 1; - //its happy new year - nextYear(); - } else { + $scope.monthNumber = 1; + //its happy new year + nextYear(); + } else { - $scope.monthNumber += 1; - } + $scope.monthNumber += 1; + } - //check if max date is ok - if ($scope.dateMaxLimit) { + //check if max date is ok + if ($scope.dateMaxLimit) { - if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { + if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { - resetToMaxDate(); - } + resetToMaxDate(); } + } - //set next month - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - //reinit days - setDaysInMonth($scope.monthNumber, $scope.year); - //deactivate selected day - $scope.day = undefined; - }; + //set next month + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + //reinit days + setDaysInMonth($scope.monthNumber, $scope.year); + //deactivate selected day + $scope.day = undefined; + }; - $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() { - var monthNumber = $scope.monthNumber - , year = $scope.year - , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month + $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() { + var monthNumber = $scope.monthNumber + , year = $scope.year + , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month - if (monthNumber === 1) { + if (monthNumber === 1) { - monthNumber = 12; - year = year - 1; - } else { + monthNumber = 12; + year = year - 1; + } else { - monthNumber -= 1; - } + monthNumber -= 1; + } - if ($scope.dateMinLimit) { - if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { + if ($scope.dateMinLimit) { + if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { - return false; - } + return false; } + } - return true; - }; + return true; + }; - $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { - var monthNumber = $scope.monthNumber - , year = $scope.year; + $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { + var monthNumber = $scope.monthNumber + , year = $scope.year; - if (monthNumber === 12) { + if (monthNumber === 12) { - monthNumber = 1; - year += 1; - } else { + monthNumber = 1; + year += 1; + } else { - monthNumber += 1; - } + monthNumber += 1; + } - if ($scope.dateMaxLimit) { - if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { + if ($scope.dateMaxLimit) { + if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { - return false; - } + return false; } + } - return true; - }; + return true; + }; - $scope.prevMonth = function managePrevMonth() { + $scope.prevMonth = function managePrevMonth() { - if ($scope.monthNumber === 1) { + if ($scope.monthNumber === 1) { - $scope.monthNumber = 12; - //its happy new year - prevYear(); - } else { + $scope.monthNumber = 12; + //its happy new year + prevYear(); + } else { - $scope.monthNumber -= 1; - } - //check if min date is ok - if ($scope.dateMinLimit) { + $scope.monthNumber -= 1; + } + //check if min date is ok + if ($scope.dateMinLimit) { - if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { + if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { - resetToMinDate(); - } + resetToMinDate(); } - //set next month - $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); - //reinit days - setDaysInMonth($scope.monthNumber, $scope.year); - //deactivate selected day + } + //set next month + $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM'); + //reinit days + setDaysInMonth($scope.monthNumber, $scope.year); + //deactivate selected day + $scope.day = undefined; + }; + + $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) { + + $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); + setDaysInMonth($scope.monthNumber, $scope.year); + setInputValue(); + }; + + $scope.setMonth = function setMonth(selectedMonthNumber) { + $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); + $scope.showMonthPagination = false; + $scope.month = selectedMonthNumber; + setDaysInMonth($scope.monthNumber, $scope.year); + }; + + $scope.setNewYear = function setNewYear(year) { + + //deactivate selected day + if (!isMobile) { $scope.day = undefined; - }; + } - $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) { + if ($scope.dateMaxLimit && + $scope.year < Number(year)) { - $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); - setDaysInMonth($scope.monthNumber, $scope.year); - setInputValue(); - }; + if (!$scope.isSelectableMaxYear(year)) { + + return; + } + } else if ($scope.dateMinLimit && + $scope.year > Number(year)) { - $scope.setNewYear = function setNewYear(year) { + if (!$scope.isSelectableMinYear(year)) { - //deactivate selected day - if (!isMobile) { - $scope.day = undefined; + return; } + } - if ($scope.dateMaxLimit && - $scope.year < Number(year)) { + $scope.paginateYears(year); + $scope.showYearsPagination = false; + $timeout(function timeoutForYears() { + $scope.year = Number(year); + setDaysInMonth($scope.monthNumber, $scope.year); + }, 0); + }; - if (!$scope.isSelectableMaxYear(year)) { + $scope.showMPagination = function showMPagination() { + $scope.showYearsPagination = false; + $scope.showMonthPagination = !$scope.showMonthPagination; + }; - return; - } - } else if ($scope.dateMinLimit && - $scope.year > Number(year)) { + $scope.showYPagination = function showYPagination() { + $scope.showMonthPagination = false; + $scope.showYearsPagination = !$scope.showYearsPagination; + }; - if (!$scope.isSelectableMinYear(year)) { + $scope.hideCalendar = function hideCalendar() { + if (theCalendar.classList) { + theCalendar.classList.remove('_720kb-datepicker-open'); + } else { - return; + classHelper.remove(theCalendar, '_720kb-datepicker-open'); + } + }; + + $scope.setDatepickerDay = function setDatepickerDay(day, type) { + if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && + $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && + $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && + $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { + + if (type === 'previous') { + if ($scope.monthNumber !== 1) { + $scope.monthNumber -= 1; + } else { + $scope.monthNumber = 12; + $scope.year -= 1; + } + } else if (type === 'next') { + if ($scope.monthNumber !== 12) { + $scope.monthNumber += 1; + } else { + $scope.monthNumber = 1; + $scope.year += 1; } } - $scope.paginateYears(year); - $scope.showYearsPagination = false; - $timeout(function timeoutForYears() { - $scope.year = Number(year); - setDaysInMonth($scope.monthNumber, $scope.year); - }, 0); - }; + $scope.day = Number(day); + $scope.selectedDay = $scope.day; + $scope.selectedMonth = $scope.monthNumber; + $scope.selectedYear = $scope.year; - $scope.hideCalendar = function hideCalendar() { - if (theCalendar.classList) { - theCalendar.classList.remove('_720kb-datepicker-open'); - } else { + setInputValue(); - classHelper.remove(theCalendar, '_720kb-datepicker-open'); + if (attr.hasOwnProperty('dateRefocus')) { + thisInput[0].focus(); } - }; - - $scope.setDatepickerDay = function setDatepickerDay(day, type) { - if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) && - $scope.isSelectableDate($scope.monthNumber, $scope.year, day) && - $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) && - $scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) { - - if (type === 'previous') { - if ($scope.monthNumber !== 1) { - $scope.monthNumber -= 1; - } else { - $scope.monthNumber = 12; - } - } else if (type === 'next') { - if ($scope.monthNumber !== 12) { - $scope.monthNumber += 1; - } else { - $scope.monthNumber = 1; - } - } - $scope.day = Number(day); - $scope.selectedDay = $scope.day; - $scope.selectedMonth = $scope.monthNumber; - $scope.selectedYear = $scope.year; + $scope.hideCalendar(); + } + }; - setInputValue(); + $scope.paginateYears = function paginateYears(startingYear) { + var i + , theNewYears = [] + , daysToPrepend = 10 + , daysToAppend = 10; - if (attr.hasOwnProperty('dateRefocus')) { - thisInput[0].focus(); - } + $scope.paginationYears = []; + if (isMobile) { - $scope.hideCalendar(); + daysToPrepend = 50; + daysToAppend = 50; + if ( $scope.dateMinLimit && $scope.dateMaxLimit) { + + startingYear = new Date($scope.dateMaxLimit).getFullYear(); + daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); + daysToAppend = 1; } - }; + } - $scope.paginateYears = function paginateYears(startingYear) { - var i - , theNewYears = [] - , daysToPrepend = 10 - , daysToAppend = 10; + for (i = daysToPrepend; i > 0; i -= 1) { - $scope.paginationYears = []; - if (isMobile) { + theNewYears.push(Number(startingYear) - i); + } - daysToPrepend = 50; - daysToAppend = 50; - if ( $scope.dateMinLimit && $scope.dateMaxLimit) { + for (i = 0; i < daysToAppend; i += 1) { - startingYear = new Date($scope.dateMaxLimit).getFullYear(); - daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); - daysToAppend = 1; - } - } + theNewYears.push(Number(startingYear) + i); + } + //date typing in input date-typer + if ($scope.dateTyper === 'true') { - for (i = daysToPrepend; i > 0; i -= 1) { + thisInput.on('keyup blur', function onTyping() { - theNewYears.push(Number(startingYear) - i); - } + if (thisInput[0].value && + thisInput[0].value.length && + thisInput[0].value.length > 0) { - for (i = 0; i < daysToAppend; i += 1) { + try { + if (dateFormat) { + date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); + } else { + date = new Date(thisInput[0].value.toString()); + } - theNewYears.push(Number(startingYear) + i); - } - //date typing in input date-typer - if ($scope.dateTyper === 'true') { - - thisInput.on('keyup blur', function onTyping() { - - if (thisInput[0].value && - thisInput[0].value.length && - thisInput[0].value.length > 0) { - - try { - if (dateFormat) { - date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); - } else { - date = new Date(thisInput[0].value.toString()); - } - - if (date.getFullYear() && - !isNaN(date.getDay()) && - !isNaN(date.getMonth()) && - $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) && - $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) && - $scope.isSelectableMaxDate(date) && - $scope.isSelectableMinDate(date)) { - - $scope.$apply(function applyTyping() { - - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - - if (date.getFullYear().toString().length === 4) { - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like - } - setDaysInMonth($scope.monthNumber, $scope.year); - }); - } - } catch (e) { - - return e; + if (date.getFullYear() && + !isNaN(date.getDay()) && + !isNaN(date.getMonth()) && + $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) && + $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) && + $scope.isSelectableMaxDate(date) && + $scope.isSelectableMinDate(date)) { + + $scope.$apply(function applyTyping() { + + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + + if (date.getFullYear().toString().length === 4) { + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + } + setDaysInMonth($scope.monthNumber, $scope.year); + }); } + } catch (e) { + + return e; } - }); - } - //check range dates - if ($scope.dateMaxLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { + } + }); + } + //check range dates + if ($scope.dateMaxLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { - $scope.paginationYearsNextDisabled = true; - } else { + $scope.paginationYearsNextDisabled = true; + } else { - $scope.paginationYearsNextDisabled = false; - } + $scope.paginationYearsNextDisabled = false; + } - if ($scope.dateMinLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { + if ($scope.dateMinLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { - $scope.paginationYearsPrevDisabled = true; - } else { + $scope.paginationYearsPrevDisabled = true; + } else { - $scope.paginationYearsPrevDisabled = false; - } + $scope.paginationYearsPrevDisabled = false; + } - $scope.paginationYears = theNewYears; - }; + $scope.paginationYears = theNewYears; + }; - $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { - var i = 0; + $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { + var i = 0; - if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) { - for (i; i <= dateDisabledWeekdays.length; i += 1) { - if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) { - return false; - } + if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) { + for (i; i <= dateDisabledWeekdays.length; i += 1) { + if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) { + return false; } } + } - return true; - }; + return true; + }; - $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) { - var i = 0; + $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) { + var i = 0; - if (dateDisabledDates && - dateDisabledDates.length > 0) { + if (dateDisabledDates && + dateDisabledDates.length > 0) { - for (i; i <= dateDisabledDates.length; i += 1) { + for (i; i <= dateDisabledDates.length; i += 1) { - if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - return false; - } + return false; } } + } - if (dateEnabledDates) { + if (dateEnabledDates) { - for (i; i <= dateEnabledDates.length; i += 1) { + for (i; i <= dateEnabledDates.length; i += 1) { - if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - return true; - } + return true; } - - return false; } - return true; - }; + return false; + } - $scope.isSelectableMinDate = function isSelectableMinDate(aDate) { - //if current date - if (!!$scope.dateMinLimit && - !!new Date($scope.dateMinLimit) && - new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) { + return true; + }; - return false; - } + $scope.isSelectableMinDate = function isSelectableMinDate(aDate) { + //if current date + if (!!$scope.dateMinLimit && + !!new Date($scope.dateMinLimit) && + new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) { - return true; - }; + return false; + } - $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) { - //if current date - if (!!$scope.dateMaxLimit && - !!new Date($scope.dateMaxLimit) && - new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) { + return true; + }; - return false; - } + $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) { + //if current date + if (!!$scope.dateMaxLimit && + !!new Date($scope.dateMaxLimit) && + new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) { - return true; - }; + return false; + } - $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { - if (!!$scope.dateMaxLimit && - year > new Date($scope.dateMaxLimit).getFullYear()) { + return true; + }; - return false; - } + $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { + if (!!$scope.dateMaxLimit && + year > new Date($scope.dateMaxLimit).getFullYear()) { - return true; - }; + return false; + } - $scope.isSelectableMinYear = function isSelectableMinYear(year) { - if (!!$scope.dateMinLimit && - year < new Date($scope.dateMinLimit).getFullYear()) { + return true; + }; - return false; - } + $scope.isSelectableMinYear = function isSelectableMinYear(year) { + if (!!$scope.dateMinLimit && + year < new Date($scope.dateMinLimit).getFullYear()) { - return true; - }; + return false; + } - $scope.validateWeekDay = function isValidWeekDay(weekDay) { - var validWeekDay = Number(weekDay, 10); - // making sure that the given option is valid - if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) { + return true; + }; - validWeekDay = 0; - } - return validWeekDay; - }; - - // respect previously configured interpolation symbols. - htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol()); - $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month'; - $scope.dateYearTitle = $scope.dateYearTitle || 'Select year'; - $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next'; - $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev'; - $scope.month = $filter('date')(date, 'MMMM');//december-November like - $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like - $scope.day = Number($filter('date')(date, 'dd')); //01-31 like - $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); + $scope.validateWeekDay = function isValidWeekDay(weekDay) { + var validWeekDay = Number(weekDay, 10); + // making sure that the given option is valid + if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) { - if ($scope.dateMaxLimit) { + validWeekDay = 0; + } + return validWeekDay; + }; - $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like - } else { + // respect previously configured interpolation symbols. + htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol()); + $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month'; + $scope.dateYearTitle = $scope.dateYearTitle || 'Select year'; + $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next'; + $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev'; + $scope.month = $filter('date')(date, 'MMMM');//december-November like + $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like + $scope.day = Number($filter('date')(date, 'dd')); //01-31 like + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like - } - $scope.months = datetime.MONTH; + if ($scope.dateMaxLimit) { - $scope.daysInString = []; - for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { + $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like + } else { - $scope.daysInString.push(n % 7); - } - $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + } + $scope.months = datetime.MONTH; - return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); - }); + $scope.daysInString = []; + for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { - //create the calendar holder and append where needed - if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('.') !== -1) { + $scope.daysInString.push(n % 7); + } + $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { - $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); - angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); + }); - theCalendar = angular.element(el)[0]; - })); - } else if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('#') !== -1) { + //create the calendar holder and append where needed + if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('.') !== -1) { - $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); - angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); + angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - theCalendar = angular.element(el)[0]; - })); - } else if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo === 'body') { - $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8)); - angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { + theCalendar = angular.element(el)[0]; + })); + } else if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('#') !== -1) { - theCalendar = angular.element(el)[0]; - })); - } else { + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); + angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - thisInput.after($compile(angular.element(htmlTemplate))($scope)); - //get the calendar as element - theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); - } - //if datepicker-toggle="" is not present or true by default - if (checkToggle()) { + theCalendar = angular.element(el)[0]; + })); + } else if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo === 'body') { + $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8)); + angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { - thisInput.on('focus click focusin', function onFocusAndClick() { + theCalendar = angular.element(el)[0]; + })); + } else { - isMouseOnInput = true; + thisInput.after($compile(angular.element(htmlTemplate))($scope)); + //get the calendar as element + theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); + } + //if datepicker-toggle="" is not present or true by default + if (checkToggle()) { - if (!isMouseOn && - !isMouseOnInput && theCalendar) { + thisInput.on('focus click focusin', function onFocusAndClick() { - $scope.hideCalendar(); - } else { + isMouseOnInput = true; - showCalendar(); - } - }); - } + if (!isMouseOn && + !isMouseOnInput && theCalendar) { - thisInput.on('focusout blur', function onBlurAndFocusOut() { + $scope.hideCalendar(); + } else { - isMouseOnInput = false; + showCalendar(); + } }); - //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed - angular.element(theCalendar).on('mouseenter', function onMouseEnter() { + } - isMouseOn = true; - }); + thisInput.on('focusout blur', function onBlurAndFocusOut() { - angular.element(theCalendar).on('mouseleave', function onMouseLeave() { + isMouseOnInput = false; + }); + //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed + angular.element(theCalendar).on('mouseenter', function onMouseEnter() { - isMouseOn = false; - }); + isMouseOn = true; + }); - angular.element(theCalendar).on('focusin', function onCalendarFocus() { + angular.element(theCalendar).on('mouseleave', function onMouseLeave() { - isMouseOn = true; - }); + isMouseOn = false; + }); - angular.element($window).on('click focus focusin', onClickOnWindow); + angular.element(theCalendar).on('focusin', function onCalendarFocus() { - //check always if given range of dates is ok - if ($scope.dateMinLimit && - !$scope.isSelectableMinYear($scope.year) || - !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { + isMouseOn = true; + }); - resetToMinDate(); - } + angular.element($window).on('click focus focusin', onClickOnWindow); - if ($scope.dateMaxLimit && - !$scope.isSelectableMaxYear($scope.year) || - !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { + //check always if given range of dates is ok + if ($scope.dateMinLimit && + !$scope.isSelectableMinYear($scope.year) || + !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - resetToMaxDate(); - } + resetToMinDate(); + } - //datepicker boot start - $scope.paginateYears($scope.year); + if ($scope.dateMaxLimit && + !$scope.isSelectableMaxYear($scope.year) || + !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - setDaysInMonth($scope.monthNumber, $scope.year); - $scope.checkVisibility = checkVisibility; - - $scope.$on('$destroy', function unregisterListener() { - - unregisterDataSetWatcher(); - unregisterDateMinLimitWatcher(); - unregisterDateMaxLimitWatcher(); - unregisterDateFormatWatcher(); - unregisterDateDisabledDatesWatcher(); - unregisterDateEnabledDatesWatcher(); - thisInput.off('focus click focusout blur'); - angular.element(theCalendar).off('mouseenter mouseleave focusin'); - angular.element($window).off('click focus focusin', onClickOnWindow); - }); - }; + resetToMaxDate(); + } - return { - 'restrict': 'AEC', - 'scope': { - 'dateSet': '@', - 'dateMinLimit': '@', - 'dateMaxLimit': '@', - 'dateMonthTitle': '@', - 'dateYearTitle': '@', - 'buttonNextTitle': '@', - 'buttonPrevTitle': '@', - 'dateDisabledDates': '@', - 'dateEnabledDates': '@', - 'dateDisabledWeekdays': '@', - 'dateSetHidden': '@', - 'dateTyper': '@', - 'dateWeekStartDay': '@', - 'datepickerAppendTo': '@', - 'datepickerToggle': '@', - 'datepickerClass': '@', - 'datepickerShow': '@', - 'anyDay': '@' - }, - 'link': linkingFunction - }; + //datepicker boot start + $scope.paginateYears($scope.year); + + setDaysInMonth($scope.monthNumber, $scope.year); + $scope.checkVisibility = checkVisibility; + + $scope.$on('$destroy', function unregisterListener() { + + unregisterDataSetWatcher(); + unregisterDateMinLimitWatcher(); + unregisterDateMaxLimitWatcher(); + unregisterDateFormatWatcher(); + unregisterDateDisabledDatesWatcher(); + unregisterDateEnabledDatesWatcher(); + thisInput.off('focus click focusout blur'); + angular.element(theCalendar).off('mouseenter mouseleave focusin'); + angular.element($window).off('click focus focusin', onClickOnWindow); + }); + }; + + return { + 'restrict': 'AEC', + 'scope': { + 'dateSet': '@', + 'dateMinLimit': '@', + 'dateMaxLimit': '@', + 'dateMonthTitle': '@', + 'dateYearTitle': '@', + 'buttonNextTitle': '@', + 'buttonPrevTitle': '@', + 'dateDisabledDates': '@', + 'dateEnabledDates': '@', + 'dateDisabledWeekdays': '@', + 'dateSetHidden': '@', + 'dateTyper': '@', + 'dateWeekStartDay': '@', + 'datepickerAppendTo': '@', + 'datepickerToggle': '@', + 'datepickerClass': '@', + 'datepickerShow': '@', + 'anyDay': '@' + }, + 'link': linkingFunction }; + }; angular.module('720kb.datepicker', []) - .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]); + .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]); }(angular, navigator)); From 734eb0af808f1e74cce605e5ae02d124d1988fb0 Mon Sep 17 00:00:00 2001 From: divecoke Date: Tue, 13 Mar 2018 08:37:48 +0200 Subject: [PATCH 5/7] Fixed styling of prev/next month days --- dist/angular-datepicker.js | 4 ++-- dist/angular-datepicker.min.js | 4 ++-- dist/angular-datepicker.sourcemap.map | 2 +- src/js/angular-datepicker.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index 60739eb..1c85cef 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -100,13 +100,13 @@ , generateDays = function generateDays() { return [ '' diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 4317f65..051c793 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -4,9 +4,9 @@ * Released by 720kb.net under the MIT license * www.opensource.org/licenses/MIT * - * 2018-03-07 + * 2018-03-13 */ -!function(I,e){"use strict";var C=function(){if(e.userAgent&&(e.userAgent.match(/Android/i)||e.userAgent.match(/webOS/i)||e.userAgent.match(/iPhone/i)||e.userAgent.match(/iPad/i)||e.userAgent.match(/iPod/i)||e.userAgent.match(/BlackBerry/i)||e.userAgent.match(/Windows Phone/i)))return!0}(),B=function(e,a,t){var i,n,r=['
',"
"],d=(i=e,n=a,t&&(C=!1),C?['
','
',"
","
",'
','
','","","
","
"]:['
','
',"
","
",'
','
',"
","
",'"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','","
"],o=['
','
',"{{d}}","
","
"],s=['"],m=function(e){r.splice(r.length-1,0,e)};return d.forEach(m),l.forEach(m),c.forEach(m),o.forEach(m),s.forEach(m),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(E,W,O,H,j,F){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,i,n,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,k=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,g=O.DATETIME_FORMATS,M=B(l,c,k),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,i,n,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(n=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,F(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.showMPagination=function(){u.showYearsPagination=!1,u.showMonthPagination=!u.showMonthPagination},u.showYPagination=function(){u.showMonthPagination=!1,u.showYearsPagination=!u.showYearsPagination},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):_(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:(u.monthNumber=12,u.year-=1):"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:(u.monthNumber=1,u.year+=1)),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,S(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],i=10,n=10;for(u.paginationYears=[],C&&(n=i=50,u.dateMinLimit&&u.dateMaxLimit&&(i=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),n=1)),a=i;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e',""],d=(i=e,n=a,t&&(C=!1),C?['
','
',"
","
",'
','
','","","
","
"]:['
','
',"
","
",'
','
',"
","
",'"]),l=['
','",'
','',e,"",'',a,"","
","
"],c=['
','","
"],o=['
','
',"{{d}}","
","
"],s=['"],m=function(e){r.splice(r.length-1,0,e)};return d.forEach(m),l.forEach(m),c.forEach(m),o.forEach(m),s.forEach(m),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(E,W,O,H,j,F){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,i,n,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'',c=t.buttonNext||'',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,k=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,g=O.DATETIME_FORMATS,M=B(l,c,k),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,i,n,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(n=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,F(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.showMPagination=function(){u.showYearsPagination=!1,u.showMonthPagination=!u.showMonthPagination},u.showYPagination=function(){u.showMonthPagination=!1,u.showYearsPagination=!u.showYearsPagination},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):_(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:(u.monthNumber=12,u.year-=1):"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:(u.monthNumber=1,u.year+=1)),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,S(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],i=10,n=10;for(u.paginationYears=[],C&&(n=i=50,u.dateMinLimit&&u.dateMaxLimit&&(i=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),n=1)),a=i;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&e', - '', + '', '{{px}}', '', '', '{{item}}', '', - '', + '', '{{nx}}', '', '' From 012747f244ce4a771e7c8f0ae9cd22aa22ee23e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernestas=20Tir=C5=ABnas?= Date: Mon, 9 Apr 2018 11:06:15 +0300 Subject: [PATCH 6/7] Changed datepicker --- src/css/angular-datepicker.css | 359 +++++++++++++++++++++++---------- src/js/angular-datepicker.js | 45 ++--- 2 files changed, 270 insertions(+), 134 deletions(-) diff --git a/src/css/angular-datepicker.css b/src/css/angular-datepicker.css index 4a26ee9..b03c86f 100644 --- a/src/css/angular-datepicker.css +++ b/src/css/angular-datepicker.css @@ -1,27 +1,41 @@ -datepicker a, [datepicker] a, .datepicker a{ - color:inherit; - text-decoration:none; -} -datepicker a:hover, [datepicker] a:hover, .datepicker a:hover{ - text-decoration:none; -} -datepicker select, datepicker select:focus, datepicker select:hover, -.datepicker select, .datepicker select:focus, .datepicker select:hover, -[datepicker] select, [datepicker] select:focus, [datepicker] select:hover{ - width:100%; - overflow: hidden; - background:none; - color:#fff; - background-color: #138EFA; - border-radius:2px; - border: 0; - margin-top:5px; -} -datepicker, .datepicker, [datepicker], -._720kb-datepicker-calendar-header, +.datepicker a, +[datepicker] a, +datepicker a { + color: inherit; + text-decoration: none +} + +.datepicker a:hover, +[datepicker] a:hover, +datepicker a:hover { + text-decoration: none +} + +.datepicker select, +.datepicker select:focus, +.datepicker select:hover, +[datepicker] select, +[datepicker] select:focus, +[datepicker] select:hover, +datepicker select, +datepicker select:focus, +datepicker select:hover { + width: 100%; + overflow: hidden; + background: #138EFA; + color: #fff; + border-radius: 2px; + border: 0; + margin-top: 5px +} + ._720kb-datepicker-calendar-body, ._720kb-datepicker-calendar-days-header, -._720kb-datepicker-calendar-years-pagination-pages { +._720kb-datepicker-calendar-header, +._720kb-datepicker-calendar-years-pagination-pages, +.datepicker, +[datepicker], +datepicker { font-family: Helvetica Neue, Arial, sans-serif; font-size: 13.5px; -webkit-box-sizing: border-box; @@ -32,53 +46,56 @@ datepicker, .datepicker, [datepicker], margin: 0 auto; float: left; clear: right; - position: relative; + position: relative } + ._720kb-datepicker-calendar { - background: white; + background: #fff; color: #333; position: absolute; z-index: 999; min-width: 220px; - margin: 0 auto; - width: 101%; - -webkit-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset; - -moz-box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset; - box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset; + margin: 0 auto 0 -.5%; + -webkit-box-shadow: 0 0 0 1px rgba(0, 0, 0, .1) inset; + -moz-box-shadow: 0 0 0 1px rgba(0, 0, 0, .1) inset; visibility: hidden; - overflow:hidden; - margin-left:-0.5%; - padding: 0 0 2% 0; -webkit-border-radius: 3px; -moz-border-radius: 3px; - border-radius: 3px; + border-radius: 3px } -._720kb-datepicker-calendar._720kb-datepicker-open,._720kb-datepicker-calendar._720kb-datepicker-forced-to-open { - visibility: visible; + +._720kb-datepicker-calendar._720kb-datepicker-forced-to-open, +._720kb-datepicker-calendar._720kb-datepicker-open { + visibility: visible } + ._720kb-datepicker-calendar-header { text-align: center; font-size: 15px; - line-height: 40px; + line-height: 40px } + ._720kb-datepicker-calendar-header:nth-child(odd) { - background: #138EFA; + background: #138EFA } + ._720kb-datepicker-calendar-header:nth-child(even) { - background: #7BC6FC; + background: #7BC6FC } + ._720kb-datepicker-calendar-header-left, ._720kb-datepicker-calendar-header-middle, ._720kb-datepicker-calendar-header-right { width: 15%; - float: left; + float: left } + ._720kb-datepicker-calendar-header-middle { - width: 70%; + width: 70% } ._720kb-datepicker-calendar-header-closed-pagination::after { - content: " \25BE"; + content: " \25BE" } ._720kb-datepicker-calendar-header-opened-pagination::after { @@ -86,124 +103,250 @@ datepicker, .datepicker, [datepicker], margin-left: 4px; position: relative; bottom: -3px; - display:inline-block; + display: inline-block; -webkit-transform: rotate(180deg); -moz-transform: rotate(180deg); -o-transform: rotate(180deg); -ms-transform: rotate(180deg); - transform: rotate(180deg); + transform: rotate(180deg) } + ._720kb-datepicker-calendar-body { width: 96%; margin: 2%; - text-align: center; + text-align: center } + ._720kb-datepicker-calendar-day { cursor: pointer; - font-size: 12.5px; width: 12.2%; - margin:5px 1%; + margin: 5px 1%; padding: 1.5% 0; float: left; -webkit-border-radius: 1px; - -moz-border-radius: 1px; - border-radius: 1px; + -moz-border-radius: 1px } -._720kb-datepicker-calendar-day:hover, -._720kb-datepicker-calendar-day._720kb-datepicker-active { - background: rgba(0, 0, 0, 0.03); + +._720kb-datepicker-calendar-day._720kb-datepicker-active, +._720kb-datepicker-calendar-day:hover { + background: rgba(0, 0, 0, .03) } -._720kb-datepicker-calendar-header a, ._720kb-datepicker-calendar-header a:hover { - text-decoration:none; - padding:3% 9% 4% 9%; + +._720kb-datepicker-calendar-header a, +._720kb-datepicker-calendar-header a:hover { + text-decoration: none; + padding: 3% 9% 4%; font-size: 13.5px; - color:rgba(0, 0, 0, 0.55); - font-weight: bold; + color: rgba(0, 0, 0, .55); + font-weight: 700; -webkit-border-radius: 3px; -moz-border-radius: 3px; - border-radius: 3px; + border-radius: 3px } + ._720kb-datepicker-calendar-header a:hover { - color:rgba(0, 0, 0, 0.9); - background: rgba(255, 255, 255, 0.45); + color: rgba(0, 0, 0, .9); + background: rgba(255, 255, 255, .45) } + ._720kb-datepicker-calendar-month { - color:#fff; + color: #fff } -._720kb-datepicker-calendar-month span { - font-size: 13px; - color:rgba(0, 0, 0, 0.4); -} -._720kb-datepicker-calendar-month a span i { + +._720kb-datepicker-calendar-month a span i { font-style: normal; - font-size:15px; + font-size: 15px } -._720kb-datepicker-calendar-month a, ._720kb-datepicker-calendar-month a:hover { + +._720kb-datepicker-calendar-month a, +._720kb-datepicker-calendar-month a:hover { padding: 3px; - margin-left:1%; + margin-left: 1% } -._720kb-datepicker-calendar-years-pagination{ - padding:2% 0 0 0; - float:left; + +._720kb-datepicker-calendar-years-pagination { + float: left; clear: right; - width: 100%; + width: 100% } -._720kb-datepicker-calendar-years-pagination a, ._720kb-datepicker-calendar-years-pagination a:hover { - font-size:12px; - padding:0 7px; - font-weight: normal; - margin:3px 1% 0 1%; + +._720kb-datepicker-calendar-years-pagination a, +._720kb-datepicker-calendar-years-pagination a:hover { + font-size: 12px; + padding: 0 7px; + font-weight: 400; + margin: 3px 1% 0; line-height: 20px; - display: inline-block; + display: inline-block } + ._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-active { - color:rgba(0, 0, 0, 0.9); + color: rgba(0, 0, 0, .9); font-weight: 500; - background: rgba(255, 255, 255, 0.45); + background: rgba(255, 255, 255, .45) } -._720kb-datepicker-calendar-years-pagination-pages a,._720kb-datepicker-calendar-years-pagination-pages a:hover{ - padding:5px 10px; + +._720kb-datepicker-calendar-years-pagination-pages a, +._720kb-datepicker-calendar-years-pagination-pages a:hover { + padding: 5px 10px } -._720kb-datepicker-calendar-days-header{ + +._720kb-datepicker-calendar-days-header { max-width: 100%; - margin:0 auto; - padding:0 2% 0 2%; - background: rgba(19, 142, 250, 0.08); - border-bottom:1px solid rgba(0,0,0,0.02); + margin: 0 auto; + padding: 0 2% } -._720kb-datepicker-calendar-days-header div{ + +._720kb-datepicker-calendar-days-header div { width: 14.18%; font-weight: 500; font-size: 11.5px; - padding:10px 0; - float:left; + padding: 10px 0; + float: left; text-align: center; - color:rgba(0,0,0,0.7); + color: rgba(0, 0, 0, .7) } -._720kb-datepicker-calendar-days -._720kb-datepicker-default-button{ + +._720kb-datepicker-calendar-days ._720kb-datepicker-default-button { font-size: 18.5px; position: relative; - bottom:-0.5px; + bottom: -.5px } -._720kb-datepicker-default-button{ - padding:0 4.5px; + +._720kb-datepicker-default-button { + padding: 0 4.5px } -._720kb-datepicker-calendar-header-middle._720kb-datepicker-mobile-item{ - width:95%; - float:none; - margin:0 auto; + +._720kb-datepicker-calendar-header-middle._720kb-datepicker-mobile-item { + width: 95%; + float: none; + margin: 0 auto } -._720kb-datepicker-item-hidden{ - visibility:hidden; + +._720kb-datepicker-item-hidden { + visibility: hidden } + ._720kb-datepicker-calendar-day._720kb-datepicker-disabled, ._720kb-datepicker-calendar-day._720kb-datepicker-disabled:hover, -._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-disabled, -._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-disabled:hover, ._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-active._720kb-datepicker-disabled, -._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-active._720kb-datepicker-disabled:hover{ - color:rgba(0,0,0,0.2); - background: rgba(25,2,0,0.02); - cursor: default; +._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-active._720kb-datepicker-disabled:hover, +._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-disabled, +._720kb-datepicker-calendar-years-pagination a._720kb-datepicker-disabled:hover { + color: rgba(0, 0, 0, .2); + background: rgba(25, 2, 0, .02); + cursor: default +} + +._720kb-datepicker-calendar { + width: 300px; + padding: 20px; + border: 1px solid #E5E5E5!important; + box-shadow: 0 5px 12px 0 rgba(193, 193, 193, .5); + font-family: Montserrat, sans-serif!important; + overflow: visible!important; + margin-top: 45px +} + +._720kb-datepicker-calendar _720kb-datepicker-open { + overflow: auto!important +} + +._720kb-datepicker-calendar::before { + content: ''; + position: absolute; + width: 10px; + height: 10px; + background: #fff; + border-top: 1px solid #DFE3E9; + border-left: 1px solid #DFE3E9; + -webkit-transform: rotate(45deg); + transform: rotate(45deg); + top: -6px; + left: 46px +} + +._720kb-datepicker-calendar-header { + background: #fff!important; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-years-pagination { + padding: 0; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-years-pagination>a, +._720kb-datepicker-calendar-years-pagination>a:hover { + border: 1px solid #EAEAEA; + border-radius: 3px; + font-size: 12px; + line-height: 14px; + padding: 7px 14px; + font-family: Montserrat, sans-serif!important } + +._720kb-datepicker-calendar-years-pagination>a { + background-color: #F5F6FA!important; + color: #202020!important; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-years-pagination>a:hover { + background-color: #F95A4F!important; + color: #fff!important +} + +._720kb-datepicker-calendar-years-pagination>a._720kb-datepicker-active { + background-color: #FE3429!important; + color: #fff!important; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-month span { + font-size: 16px; + color: #000; + font-weight: 700; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-header-left>a, +._720kb-datepicker-calendar-header-right>a { + font-size: 9px!important; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-days-header { + background: 0 0!important; + border-bottom: none!important; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-days-header>div { + color: #2C3135!important; + font-size: 14px; + font-family: Montserrat, sans-serif!important +} + +._720kb-datepicker-calendar-day { + font-family: Montserrat, sans-serif!important; + font-size: 14px!important; + color: #2C3135!important; + border-radius: 3px!important +} + +._720kb-datepicker-calendar-day: hover { + background: #F1F4F8!important; + border-radius: 3px!important +} + +._720kb-datepicker-active { + background: #FE3429!important; + color: #fff!important +} + +._720kb-datepicker-today { + border-radius: 3px!important; + color: #F95A4F!important; + background: #fff!important +} \ No newline at end of file diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index 1c85cef..e94f2a5 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -54,20 +54,14 @@ "", '
', '", '', '
', '', @@ -79,13 +73,15 @@ } , generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) { - return ['"]; - } - - , generateMonthsPaginationHeader = function generateMonthsPaginationHeader() { - - return ['
', '", "
"]; - + return [ + '
', + '
', + '', + "{{y}}", + "", + "
", + "
" + ]; } , generateDaysColumns = function generateDaysColumns() { @@ -118,19 +114,16 @@ '
', '
' ] - , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile) , yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton) - , monthsPaginationHeader = generateMonthsPaginationHeader() + , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile) , daysColumns = generateDaysColumns() , days = generateDays() , iterator = function iterator(aRow) { toReturn.splice(toReturn.length - 1, 0, aRow); }; - - monthAndYearHeader.forEach(iterator); yearsPaginationHeader.forEach(iterator); - monthsPaginationHeader.forEach(iterator); + monthAndYearHeader.forEach(iterator); daysColumns.forEach(iterator); days.forEach(iterator); @@ -266,11 +259,11 @@ } , prevYear = function prevYear() { - $scope.year = Number($scope.year) - 1; + $scope.year = $scope.setNewYear(Number($scope.year) - 1); } , nextYear = function nextYear() { - $scope.year = Number($scope.year) + 1; + $scope.year = $scope.setNewYear(Number($scope.year) + 1); } , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) { @@ -713,8 +706,8 @@ $scope.paginateYears = function paginateYears(startingYear) { var i , theNewYears = [] - , daysToPrepend = 10 - , daysToAppend = 10; + , daysToPrepend = 2 + , daysToAppend = 2; $scope.paginationYears = []; if (isMobile) { From dd3de2404c61a8f21fe5880e308cb3b67bb2908a Mon Sep 17 00:00:00 2001 From: Anton Sumilov Date: Mon, 9 Nov 2020 15:38:10 +0200 Subject: [PATCH 7/7] Updated year pagination --- src/css/angular-datepicker.css | 2 +- src/js/angular-datepicker.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/css/angular-datepicker.css b/src/css/angular-datepicker.css index b03c86f..55aa47a 100644 --- a/src/css/angular-datepicker.css +++ b/src/css/angular-datepicker.css @@ -282,7 +282,7 @@ datepicker { border-radius: 3px; font-size: 12px; line-height: 14px; - padding: 7px 14px; + padding: 7px 10px; font-family: Montserrat, sans-serif!important } diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index e94f2a5..24a5e8c 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -76,8 +76,9 @@ return [ '" @@ -706,8 +707,8 @@ $scope.paginateYears = function paginateYears(startingYear) { var i , theNewYears = [] - , daysToPrepend = 2 - , daysToAppend = 2; + , daysToPrepend = 1 + , daysToAppend = 4; $scope.paginationYears = []; if (isMobile) {