From 727b6cfdc358a1560cce7fe49fdd0410b89cb11f Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Wed, 4 Nov 2015 11:31:24 -0800 Subject: [PATCH 01/22] Update demo * Setting timezone for date-range directive --- README.md | 2 +- app/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 050f72a..635b590 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Usage Example -[Live demo](https://rawgithub.com/g00fy-/angular-datepicker/master/app/index.html) +[Live demo](https://rawgithub.com/DanTalash/angular-datepicker/master/app/index.html) ## New features diff --git a/app/index.html b/app/index.html index b69a0c8..471dda6 100644 --- a/app/index.html +++ b/app/index.html @@ -87,7 +87,7 @@
Min + max ({{demoForm.pickerBothDates.$error.min ? 'Min: invalid, ' : 'Min:

Range

-
+
From 58c53ef041acdda36d53bf074137ace75519e616 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Wed, 4 Nov 2015 11:38:40 -0800 Subject: [PATCH 02/22] Revert "Update demo" This reverts commit 727b6cfdc358a1560cce7fe49fdd0410b89cb11f. --- README.md | 2 +- app/index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 635b590..050f72a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Usage Example -[Live demo](https://rawgithub.com/DanTalash/angular-datepicker/master/app/index.html) +[Live demo](https://rawgithub.com/g00fy-/angular-datepicker/master/app/index.html) ## New features diff --git a/app/index.html b/app/index.html index 471dda6..b69a0c8 100644 --- a/app/index.html +++ b/app/index.html @@ -87,7 +87,7 @@
Min + max ({{demoForm.pickerBothDates.$error.min ? 'Min: invalid, ' : 'Min:

Range

-
+
From 3810655d23309229b4ecb7ef5222d9bec635104c Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Wed, 4 Nov 2015 11:40:21 -0800 Subject: [PATCH 03/22] Updating demo --- app/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/index.html b/app/index.html index b69a0c8..471dda6 100644 --- a/app/index.html +++ b/app/index.html @@ -87,7 +87,7 @@
Min + max ({{demoForm.pickerBothDates.$error.min ? 'Min: invalid, ' : 'Min:

Range

-
+
From 805cf24c3cc65fd1c2c9d31ee3d2961dedd55d1e Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Thu, 5 Nov 2015 09:27:04 -0800 Subject: [PATCH 04/22] Release v2.0.1 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index d13ab83..8e3c1e9 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-datepicker", "license": "MIT", - "version": "2.0.0", + "version": "2.0.1", "main": [ "./dist/angular-datepicker.js", "./dist/angular-datepicker.css" diff --git a/package.json b/package.json index e469996..d13fb44 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-datepicker", - "version": "2.0.0", + "version": "2.0.1", "main": "dist/angular-datepicker.js", "repository": { "url": "https://github.com/g00fy-/angular-datepicker.git" From 5b82eecccf067fe2fa33d68617659c6adf7a623b Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:12:09 -0800 Subject: [PATCH 05/22] Fixing issue with months where the first day is a Sunday * Fixing logic flaw in getVisibleWeeks which incorrectly prepares weeks for months where the first day falls on a Sunday. --- app/scripts/datePickerUtils.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/scripts/datePickerUtils.js b/app/scripts/datePickerUtils.js index f18c536..fbdceb5 100644 --- a/app/scripts/datePickerUtils.js +++ b/app/scripts/datePickerUtils.js @@ -28,21 +28,18 @@ angular.module('datePicker').factory('datePickerUtils', function () { var startYear = m.year(), startMonth = m.month(); - // set date to start of the week + //Set date to the first day of the month m.date(1); + //Grab day of the week var day = m.day(); if (day === 0) { - // day is sunday, let's get back to the previous week - m.date(-5); - } else { - // day is not sunday, let's get back to the start of the week - m.date(m.date() - day); - } - if (m.date() === 1) { - // day is monday, let's get back to the previous week + //If the first day of the month is a sunday, go back one week. m.date(-6); + } else { + //Otherwise, go back the required number of days to arrive at the previous sunday + m.date(1 - day); } var weeks = []; From 26f681430ac7e8c34e8c75f1dd60d147e0cd36b6 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:16:55 -0800 Subject: [PATCH 06/22] Updating README to point to my demo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 050f72a..635b590 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ## Usage Example -[Live demo](https://rawgithub.com/g00fy-/angular-datepicker/master/app/index.html) +[Live demo](https://rawgithub.com/DanTalash/angular-datepicker/master/app/index.html) ## New features From 496b1aa7b47b7728012fcb9f6c3d808e4f1f6480 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:21:29 -0800 Subject: [PATCH 07/22] Update generated files --- dist/angular-datepicker.js | 15 ++++++--------- dist/angular-datepicker.min.js | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index e76405c..cfd5238 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -382,21 +382,18 @@ var tz; var startYear = m.year(), startMonth = m.month(); - // set date to start of the week + //Set date to the first day of the month m.date(1); + //Grab day of the week var day = m.day(); if (day === 0) { - // day is sunday, let's get back to the previous week - m.date(-5); - } else { - // day is not sunday, let's get back to the start of the week - m.date(m.date() - day); - } - if (m.date() === 1) { - // day is monday, let's get back to the previous week + //If the first day of the month is a sunday, go back one week. m.date(-6); + } else { + //Otherwise, go back the required number of days to arrive at the previous sunday + m.date(1 - day); } var weeks = []; diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 008535d..d88478f 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-5):a.date(a.date()-d),1===a.date()&&a.date(-6);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},findFunction:function(b,c){var d=b;do if(d=d.$parent,a.isFunction(d[c]))return d[c];while(d.$parent);return!1},findParam:function(a,b){var c=a;do if(c=c.$parent,c[b])return c[b];while(c.$parent);return!1},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file +"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},findFunction:function(b,c){var d=b;do if(d=d.$parent,a.isFunction(d[c]))return d[c];while(d.$parent);return!1},findParam:function(a,b){var c=a;do if(c=c.$parent,c[b])return c[b];while(c.$parent);return!1},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file From a83632331b680155c5dd3488d11bc94dc2d60de0 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:21:44 -0800 Subject: [PATCH 08/22] Release v2.0.2 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 8e3c1e9..9b6577e 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-datepicker", "license": "MIT", - "version": "2.0.1", + "version": "2.0.2", "main": [ "./dist/angular-datepicker.js", "./dist/angular-datepicker.css" diff --git a/package.json b/package.json index d13fb44..8c62340 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-datepicker", - "version": "2.0.1", + "version": "2.0.2", "main": "dist/angular-datepicker.js", "repository": { "url": "https://github.com/g00fy-/angular-datepicker.git" From 79896469f1f892aac453bfda391df71b07d050d2 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:36:24 -0800 Subject: [PATCH 09/22] Fixing test dates * Dates in tests were not correct (month used for visible weeks test was June 2014. * This month starts on Sunday the 1st. * The previous week starts on Sunday the 25th May 2014. This date was incorrect. * The following week ends on Sunday, the 5th July 2014. This date was also incorrect. --- test/spec/datePickerUtilsTest.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/spec/datePickerUtilsTest.js b/test/spec/datePickerUtilsTest.js index 6211ead..a7adda2 100644 --- a/test/spec/datePickerUtilsTest.js +++ b/test/spec/datePickerUtilsTest.js @@ -37,9 +37,9 @@ describe('Test date Picker Utils', function(){ }); it('get visible weeks provided date', function(){ - var start = dateBuilder('2014-05-26T00:00:00+00:00'); // monday - var end = dateBuilder('2014-07-06T00:00:00+00:00'); // sunday - var chosen = ('2014-06-29T19:00:00+00:00'); // sunday + var start = dateBuilder('2014-05-25T00:00:00+00:00'); // sunday + var end = dateBuilder('2014-07-05T00:00:00+00:00'); // sunday + var chosen = dateBuilder('2014-06-29T19:00:00+00:00'); // sunday var weeks = utils.getVisibleWeeks(chosen, constants.step); expect(weeks).toBeDefined(); From 60624f70325b0b6f5c56414fc9df40499f6ad878 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 10 Nov 2015 10:38:46 -0800 Subject: [PATCH 10/22] Incorrect day of the week in test data comment --- test/spec/datePickerUtilsTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/datePickerUtilsTest.js b/test/spec/datePickerUtilsTest.js index a7adda2..7c60214 100644 --- a/test/spec/datePickerUtilsTest.js +++ b/test/spec/datePickerUtilsTest.js @@ -38,7 +38,7 @@ describe('Test date Picker Utils', function(){ it('get visible weeks provided date', function(){ var start = dateBuilder('2014-05-25T00:00:00+00:00'); // sunday - var end = dateBuilder('2014-07-05T00:00:00+00:00'); // sunday + var end = dateBuilder('2014-07-05T00:00:00+00:00'); // saturday var chosen = dateBuilder('2014-06-29T19:00:00+00:00'); // sunday var weeks = utils.getVisibleWeeks(chosen, constants.step); From a6f87479c6116c2f68d02e32225eca0722cb26e4 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Fri, 13 Nov 2015 09:59:53 -0800 Subject: [PATCH 11/22] Fixing CSS issue * A previous change erroneously removed a CSS rule which was used to offset the popup div in order to get the date-range directive working. * Restored this CSS rule, and added a new rule for date-range directive to fix the previous problem. --- app/scripts/dateRange.js | 2 +- app/styles/style.less | 8 ++++++++ dist/angular-datepicker.css | 6 ++++++ dist/angular-datepicker.js | 2 +- dist/angular-datepicker.min.css | 2 +- dist/angular-datepicker.min.js | 2 +- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/scripts/dateRange.js b/app/scripts/dateRange.js index 6e58874..d2cf927 100644 --- a/app/scripts/dateRange.js +++ b/app/scripts/dateRange.js @@ -73,7 +73,7 @@ Module.directive('dateRange', ['$compile', 'datePickerUtils', 'dateTimeConfig', attrs.onSetDate = 'dateChange'; - var template = '
' + + var template = '
' + getTemplate(attrs, pickerIDs[0], 'start', false, scope.end) + '' + getTemplate(attrs, pickerIDs[1], 'end', scope.start, false) + diff --git a/app/styles/style.less b/app/styles/style.less index cde64da..0127b96 100644 --- a/app/styles/style.less +++ b/app/styles/style.less @@ -1,6 +1,14 @@ @import "variables.less"; @import "mixins.less"; +.date-picker-date-time { + position: absolute; +} + +.date-range .date-picker-date-time { + position: inherit; +} + [date-picker-wrapper] { position: absolute; min-width: 220px; diff --git a/dist/angular-datepicker.css b/dist/angular-datepicker.css index b31d905..02f2a52 100644 --- a/dist/angular-datepicker.css +++ b/dist/angular-datepicker.css @@ -25,6 +25,12 @@ -moz-box-sizing: border-box; box-sizing: border-box; } +.date-picker-date-time { + position: absolute; +} +.date-range .date-picker-date-time { + position: inherit; +} [date-picker-wrapper] { position: absolute; min-width: 220px; diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index cfd5238..879ca2e 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -645,7 +645,7 @@ Module.directive('dateRange', ['$compile', 'datePickerUtils', 'dateTimeConfig', attrs.onSetDate = 'dateChange'; - var template = '
' + + var template = '
' + getTemplate(attrs, pickerIDs[0], 'start', false, scope.end) + '' + getTemplate(attrs, pickerIDs[1], 'end', scope.start, false) + diff --git a/dist/angular-datepicker.min.css b/dist/angular-datepicker.min.css index b515d6b..3abd9bd 100644 --- a/dist/angular-datepicker.min.css +++ b/dist/angular-datepicker.min.css @@ -1 +1 @@ -.clearfix:after,.clearfix:before{display:table;content:"";line-height:0}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}[date-picker],[date-picker] td,[date-picker] th{-webkit-border-radius:4px;-moz-border-radius:4px}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}[date-picker-wrapper]{position:absolute;min-width:220px;z-index:10;display:block;font-size:14px}[date-time-append] [date-picker-wrapper] [date-picker]{margin-top:-30px}[date-time-append] [date-picker]{position:relative;margin-right:-1000px;margin-bottom:-1000px}[date-range] [date-picker] .after.before{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#499dcd;background-image:-moz-linear-gradient(top,#5bc0de,#2f6ab4);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f6ab4));background-image:-webkit-linear-gradient(top,#5bc0de,#2f6ab4);background-image:-o-linear-gradient(top,#5bc0de,#2f6ab4);background-image:linear-gradient(to bottom,#5bc0de,#2f6ab4);background-repeat:repeat-x;border-color:#2f6ab4 #2f6ab4 #1f4677;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}[date-range] [date-picker] .after.before.active,[date-range] [date-picker] .after.before.disabled,[date-range] [date-picker] .after.before:active,[date-range] [date-picker] .after.before:hover,[date-range] [date-picker] .after.before[disabled]{color:#fff;background-color:#2f6ab4}[date-range] [date-picker] .after.before.active,[date-range] [date-picker] .after.before:active{background-color:#24528c\9}[date-picker].hidden{display:none}[date-picker]{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;border-radius:4px;background-color:#fff;padding:4px}[date-picker] table{margin:0}[date-picker] td,[date-picker] th{padding:4px 5px;text-align:center;width:20px;height:20px;border-radius:4px;border:none}[date-picker] .switch{width:145px}[date-picker] span{display:block;width:23%;height:26px;line-height:25px;float:left;margin:1%;cursor:pointer;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}[date-picker] span:hover{background:#eee}[date-picker] span.disabled,[date-picker] span.disabled:hover{background:0 0;color:#999;cursor:default}[date-picker] .active,[date-picker] .now{text-shadow:0 -1px 0 rgba(0,0,0,.25);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);color:#fff}[date-picker] .active.active,[date-picker] .active.disabled,[date-picker] .active:active,[date-picker] .active:hover,[date-picker] .active[disabled],[date-picker] .now.active,[date-picker] .now.disabled,[date-picker] .now:active,[date-picker] .now:hover,[date-picker] .now[disabled]{color:#fff;background-color:#04c}[date-picker] .active.active,[date-picker] .active:active,[date-picker] .now.active,[date-picker] .now:active{background-color:#039\9}[date-picker] .now{color:#fff;background-color:#ee735b;background-image:-moz-linear-gradient(top,#ee5f5b,#ee905b);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#ee905b));background-image:-webkit-linear-gradient(top,#ee5f5b,#ee905b);background-image:-o-linear-gradient(top,#ee5f5b,#ee905b);background-image:linear-gradient(to bottom,#ee5f5b,#ee905b);border-color:#ee905b #ee905b #e56218;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25)}[date-picker] .now.active,[date-picker] .now.disabled,[date-picker] .now:active,[date-picker] .now:hover,[date-picker] .now[disabled]{color:#fff;background-color:#ee905b}[date-picker] .now.active,[date-picker] .now:active{background-color:#e9712d\9}[date-picker] .disabled{background:0 0;color:#999!important;cursor:default}[date-picker] [ng-switch-when=year] span,[date-picker] [ng-switch-when=month] span,[date-picker] [ng-switch-when=minutes] span{height:54px;line-height:54px}[date-picker] [ng-switch-when=date] td{padding:0}[date-picker] [ng-switch-when=date] span{width:100%;height:26px;line-height:26px}[date-picker] [ng-switch-when=date] td span:hover,[date-picker] th:hover{background:#eee;cursor:pointer} \ No newline at end of file +.clearfix:after,.clearfix:before{display:table;content:"";line-height:0}.clearfix:after{clear:both}.hide-text{font:0/0 a;color:transparent;text-shadow:none;background-color:transparent;border:0}[date-picker],[date-picker] td,[date-picker] th{-webkit-border-radius:4px;-moz-border-radius:4px}.input-block-level{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}.date-picker-date-time{position:absolute}.date-range .date-picker-date-time{position:inherit}[date-picker-wrapper]{position:absolute;min-width:220px;z-index:10;display:block;font-size:14px}[date-time-append] [date-picker-wrapper] [date-picker]{margin-top:-30px}[date-time-append] [date-picker]{position:relative;margin-right:-1000px;margin-bottom:-1000px}[date-range] [date-picker] .after.before{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.25);background-color:#499dcd;background-image:-moz-linear-gradient(top,#5bc0de,#2f6ab4);background-image:-webkit-gradient(linear,0 0,0 100%,from(#5bc0de),to(#2f6ab4));background-image:-webkit-linear-gradient(top,#5bc0de,#2f6ab4);background-image:-o-linear-gradient(top,#5bc0de,#2f6ab4);background-image:linear-gradient(to bottom,#5bc0de,#2f6ab4);background-repeat:repeat-x;border-color:#2f6ab4 #2f6ab4 #1f4677;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);filter:progid:DXImageTransform.Microsoft.gradient(enabled=false)}[date-range] [date-picker] .after.before.active,[date-range] [date-picker] .after.before.disabled,[date-range] [date-picker] .after.before:active,[date-range] [date-picker] .after.before:hover,[date-range] [date-picker] .after.before[disabled]{color:#fff;background-color:#2f6ab4}[date-range] [date-picker] .after.before.active,[date-range] [date-picker] .after.before:active{background-color:#24528c\9}[date-picker].hidden{display:none}[date-picker]{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;border-radius:4px;background-color:#fff;padding:4px}[date-picker] table{margin:0}[date-picker] td,[date-picker] th{padding:4px 5px;text-align:center;width:20px;height:20px;border-radius:4px;border:none}[date-picker] .switch{width:145px}[date-picker] span{display:block;width:23%;height:26px;line-height:25px;float:left;margin:1%;cursor:pointer;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}[date-picker] span:hover{background:#eee}[date-picker] span.disabled,[date-picker] span.disabled:hover{background:0 0;color:#999;cursor:default}[date-picker] .active,[date-picker] .now{text-shadow:0 -1px 0 rgba(0,0,0,.25);background-repeat:repeat-x;filter:progid:DXImageTransform.Microsoft.gradient(enabled=false);background-color:#006dcc;background-image:-moz-linear-gradient(top,#08c,#04c);background-image:-webkit-gradient(linear,0 0,0 100%,from(#08c),to(#04c));background-image:-webkit-linear-gradient(top,#08c,#04c);background-image:-o-linear-gradient(top,#08c,#04c);background-image:linear-gradient(to bottom,#08c,#04c);border-color:#04c #04c #002a80;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25);color:#fff}[date-picker] .active.active,[date-picker] .active.disabled,[date-picker] .active:active,[date-picker] .active:hover,[date-picker] .active[disabled],[date-picker] .now.active,[date-picker] .now.disabled,[date-picker] .now:active,[date-picker] .now:hover,[date-picker] .now[disabled]{color:#fff;background-color:#04c}[date-picker] .active.active,[date-picker] .active:active,[date-picker] .now.active,[date-picker] .now:active{background-color:#039\9}[date-picker] .now{color:#fff;background-color:#ee735b;background-image:-moz-linear-gradient(top,#ee5f5b,#ee905b);background-image:-webkit-gradient(linear,0 0,0 100%,from(#ee5f5b),to(#ee905b));background-image:-webkit-linear-gradient(top,#ee5f5b,#ee905b);background-image:-o-linear-gradient(top,#ee5f5b,#ee905b);background-image:linear-gradient(to bottom,#ee5f5b,#ee905b);border-color:#ee905b #ee905b #e56218;border-color:rgba(0,0,0,.1) rgba(0,0,0,.1) rgba(0,0,0,.25)}[date-picker] .now.active,[date-picker] .now.disabled,[date-picker] .now:active,[date-picker] .now:hover,[date-picker] .now[disabled]{color:#fff;background-color:#ee905b}[date-picker] .now.active,[date-picker] .now:active{background-color:#e9712d\9}[date-picker] .disabled{background:0 0;color:#999!important;cursor:default}[date-picker] [ng-switch-when=year] span,[date-picker] [ng-switch-when=month] span,[date-picker] [ng-switch-when=minutes] span{height:54px;line-height:54px}[date-picker] [ng-switch-when=date] td{padding:0}[date-picker] [ng-switch-when=date] span{width:100%;height:26px;line-height:26px}[date-picker] [ng-switch-when=date] td span:hover,[date-picker] th:hover{background:#eee;cursor:pointer} \ No newline at end of file diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index d88478f..bb7f43d 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},findFunction:function(b,c){var d=b;do if(d=d.$parent,a.isFunction(d[c]))return d[c];while(d.$parent);return!1},findParam:function(a,b){var c=a;do if(c=c.$parent,c[b])return c[b];while(c.$parent);return!1},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file +"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},findFunction:function(b,c){var d=b;do if(d=d.$parent,a.isFunction(d[c]))return d[c];while(d.$parent);return!1},findParam:function(a,b){var c=a;do if(c=c.$parent,c[b])return c[b];while(c.$parent);return!1},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file From 9ee450a871929c964306207ea8a43ccce0636a4a Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Fri, 13 Nov 2015 10:00:14 -0800 Subject: [PATCH 12/22] Release v2.0.3 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 9b6577e..24c5733 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-datepicker", "license": "MIT", - "version": "2.0.2", + "version": "2.0.3", "main": [ "./dist/angular-datepicker.js", "./dist/angular-datepicker.css" diff --git a/package.json b/package.json index 8c62340..7a9bb56 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-datepicker", - "version": "2.0.2", + "version": "2.0.3", "main": "dist/angular-datepicker.js", "repository": { "url": "https://github.com/g00fy-/angular-datepicker.git" From 8199ce2c3b3a61adfbd2bd1e48a92225ed493800 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Wed, 18 Nov 2015 10:09:01 -0800 Subject: [PATCH 13/22] Allowing lodash style selectors for findFunction and findParam * Can now specify a callback function or min/maxDate by passing a set of object keys into the picker. * Eg, 'objectA.objectB.functionName' to search scopes for an object called objectA, containing an object called objectB, containing a function called functionName --- app/scripts/datePickerUtils.js | 51 ++++++++++++++++++++++------------ dist/angular-datepicker.js | 51 ++++++++++++++++++++++------------ dist/angular-datepicker.min.js | 2 +- 3 files changed, 67 insertions(+), 37 deletions(-) diff --git a/app/scripts/datePickerUtils.js b/app/scripts/datePickerUtils.js index fbdceb5..84d75b8 100644 --- a/app/scripts/datePickerUtils.js +++ b/app/scripts/datePickerUtils.js @@ -159,32 +159,47 @@ angular.module('datePicker').factory('datePickerUtils', function () { setParams: function (zone) { tz = zone; }, - findFunction: function (scope, name) { - //Search scope ancestors for a matching function. - //Can probably combine this and the below function - //into a single search function and two comparison functions - //Need to add support for lodash style selectors (eg, 'objectA.objectB.function') - var parentScope = scope; + scopeSearch: function (scope, name, comparisonFn) { + var parentScope = scope, + nameArray = name.split('.'), + target, i, j = nameArray.length; + do { - parentScope = parentScope.$parent; - if (angular.isFunction(parentScope[name])) { - return parentScope[name]; + target = parentScope = parentScope.$parent; + + //Loop through provided names. + for (i = 0; i < j; i++) { + target = target[nameArray[i]]; + if (!target) { + continue; + } + } + + //If we reached the end of the list for this scope, + //and something was found, trigger the comparison + //function. If the comparison function is happy, return + //found result. Otherwise, continue to the next parent scope + if (target && comparisonFn(target)) { + return target; } + } while (parentScope.$parent); return false; }, + findFunction: function (scope, name) { + //Search scope ancestors for a matching function. + return this.scopeSearch(scope, name, function(target) { + //Property must also be a function + return angular.isFunction(target); + }); + }, findParam: function (scope, name) { //Search scope ancestors for a matching parameter. - var parentScope = scope; - do { - parentScope = parentScope.$parent; - if (parentScope[name]) { - return parentScope[name]; - } - } while (parentScope.$parent); - - return false; + return this.scopeSearch(scope, name, function() { + //As long as the property exists, we're good + return true; + }); }, createMoment: function (m) { if (tz) { diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index 879ca2e..f4cdef8 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -513,32 +513,47 @@ var tz; setParams: function (zone) { tz = zone; }, - findFunction: function (scope, name) { - //Search scope ancestors for a matching function. - //Can probably combine this and the below function - //into a single search function and two comparison functions - //Need to add support for lodash style selectors (eg, 'objectA.objectB.function') - var parentScope = scope; + scopeSearch: function (scope, name, comparisonFn) { + var parentScope = scope, + nameArray = name.split('.'), + target, i, j = nameArray.length; + do { - parentScope = parentScope.$parent; - if (angular.isFunction(parentScope[name])) { - return parentScope[name]; + target = parentScope = parentScope.$parent; + + //Loop through provided names. + for (i = 0; i < j; i++) { + target = target[nameArray[i]]; + if (!target) { + continue; + } } + + //If we reached the end of the list for this scope, + //and something was found, trigger the comparison + //function. If the comparison function is happy, return + //found result. Otherwise, continue to the next parent scope + if (target && comparisonFn(target)) { + return target; + } + } while (parentScope.$parent); return false; }, + findFunction: function (scope, name) { + //Search scope ancestors for a matching function. + return this.scopeSearch(scope, name, function(target) { + //Property must also be a function + return angular.isFunction(target); + }); + }, findParam: function (scope, name) { //Search scope ancestors for a matching parameter. - var parentScope = scope; - do { - parentScope = parentScope.$parent; - if (parentScope[name]) { - return parentScope[name]; - } - } while (parentScope.$parent); - - return false; + return this.scopeSearch(scope, name, function() { + //As long as the property exists, we're good + return true; + }); }, createMoment: function (m) { if (tz) { diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index bb7f43d..822980d 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},findFunction:function(b,c){var d=b;do if(d=d.$parent,a.isFunction(d[c]))return d[c];while(d.$parent);return!1},findParam:function(a,b){var c=a;do if(c=c.$parent,c[b])return c[b];while(c.$parent);return!1},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file +"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},scopeSearch:function(a,b,c){var d,e,f=a,g=b.split("."),h=g.length;do{for(d=f=f.$parent,e=0;h>e;e++){d=d[g[e]]}if(d&&c(d))return d}while(f.$parent);return!1},findFunction:function(b,c){return this.scopeSearch(b,c,function(b){return a.isFunction(b)})},findParam:function(a,b){return this.scopeSearch(a,b,function(){return!0})},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file From b47935037337b715f98fca11046cc6a05092fbd6 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Wed, 18 Nov 2015 10:09:12 -0800 Subject: [PATCH 14/22] Release v2.0.4 --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 24c5733..46c3614 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angular-datepicker", "license": "MIT", - "version": "2.0.3", + "version": "2.0.4", "main": [ "./dist/angular-datepicker.js", "./dist/angular-datepicker.css" diff --git a/package.json b/package.json index 7a9bb56..6a7dff0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-datepicker", - "version": "2.0.3", + "version": "2.0.4", "main": "dist/angular-datepicker.js", "repository": { "url": "https://github.com/g00fy-/angular-datepicker.git" From 7de5aee9477ba8ca91f4e0532783bbada893c446 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 24 Nov 2015 11:45:11 -0800 Subject: [PATCH 15/22] Adding option for first day of the week * A new option has been added which controls what day will be drawn as the first day of the week. * The possibilities are 0 (sunday) to 6 (saturday). * The default is 0 (sunday) * If the provided value is not within a valid range (0-6) then the default value is selected. --- app/scripts/datePicker.js | 14 ++++++++------ app/scripts/datePickerUtils.js | 16 ++++++---------- app/scripts/input.js | 1 + 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/scripts/datePicker.js b/app/scripts/datePicker.js index ea1394e..13e6c0c 100644 --- a/app/scripts/datePicker.js +++ b/app/scripts/datePicker.js @@ -20,7 +20,8 @@ Module.constant('datePickerConfig', { hours: ['hours', 'isSameHour'], minutes: ['minutes', 'isSameMinutes'], }, - step: 5 + step: 5, + firstDay: 0 //Sunday is the first day by default. }); //Moment format filter. @@ -64,8 +65,6 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function return datePickerUtils.getDate(scope, attrs, name); } - datePickerUtils.setParams(attrs.timezone); - var arrowClick = false, tz = scope.tz = attrs.timezone, createMoment = datePickerUtils.createMoment, @@ -77,7 +76,10 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function pickerID = element[0].id, now = scope.now = createMoment(), selected = scope.date = createMoment(scope.model || now), - autoclose = attrs.autoClose === 'true'; + autoclose = attrs.autoClose === 'true', + firstDay = attrs.firstDay && attrs.firstDay >= 0 && attrs.firstDay <= 6 ? parseInt(attrs.firstDay, 10) : datePickerConfig.firstDay; + + datePickerUtils.setParams(tz, firstDay); if (!scope.model) { selected.minute(Math.ceil(selected.minute() / step) * step).second(0); @@ -141,7 +143,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function function update() { var view = scope.view; - datePickerUtils.setParams(tz); + datePickerUtils.setParams(tz, firstDay); if (scope.model && !arrowClick) { scope.date = createMoment(scope.model); @@ -194,7 +196,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function classes = [], classList = '', i, j; - datePickerUtils.setParams(tz); + datePickerUtils.setParams(tz, firstDay); if (view === 'date') { var weeks = scope.weeks, week; diff --git a/app/scripts/datePickerUtils.js b/app/scripts/datePickerUtils.js index 84d75b8..a1119fe 100644 --- a/app/scripts/datePickerUtils.js +++ b/app/scripts/datePickerUtils.js @@ -2,7 +2,7 @@ angular.module('datePicker').factory('datePickerUtils', function () { 'use strict'; - var tz; + var tz, firstDay; var createNewDate = function (year, month, day, hour, minute) { var utc = Date.UTC(year | 0, month | 0, day | 0, hour | 0, minute | 0); return tz ? moment.tz(utc, tz) : moment(utc); @@ -34,13 +34,8 @@ angular.module('datePicker').factory('datePickerUtils', function () { //Grab day of the week var day = m.day(); - if (day === 0) { - //If the first day of the month is a sunday, go back one week. - m.date(-6); - } else { - //Otherwise, go back the required number of days to arrive at the previous sunday - m.date(1 - day); - } + //Go back the required number of days to arrive at the previous week start + m.date(firstDay - (day + (firstDay >= day ? 6 : -1))); var weeks = []; @@ -78,7 +73,7 @@ angular.module('datePicker').factory('datePickerUtils', function () { return years; }, getDaysOfWeek: function (m) { - m = m ? m : (tz ? moment.tz(tz).day(0) : moment().day(0)); + m = m ? m : (tz ? moment.tz(tz).day(firstDay) : moment().day(firstDay)); var year = m.year(), month = m.month(), @@ -156,8 +151,9 @@ angular.module('datePicker').factory('datePickerUtils', function () { isSameMinutes: function (model, date) { return this.isSameHour(model, date) && model.minutes() === date.minutes(); }, - setParams: function (zone) { + setParams: function (zone, fd) { tz = zone; + firstDay = fd; }, scopeSearch: function (scope, name, comparisonFn) { var parentScope = scope, diff --git a/app/scripts/input.js b/app/scripts/input.js index a66f6ba..24eb32e 100644 --- a/app/scripts/input.js +++ b/app/scripts/input.js @@ -23,6 +23,7 @@ Module.constant('dateTimeConfig', { (attrs.step ? 'step="' + attrs.step + '" ' : '') + (attrs.onSetDate ? 'date-change="' + attrs.onSetDate + '" ' : '') + (attrs.ngModel ? 'ng-model="' + attrs.ngModel + '" ' : '') + + (attrs.firstDay ? 'first-day="' + attrs.firstDay + '" ' : '') + (attrs.timezone ? 'timezone="' + attrs.timezone + '" ' : '') + 'class="date-picker-date-time">'; }, From bd6b3b5729a3bc3829bc0a2da7b8e000f48c4d7e Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 24 Nov 2015 11:46:47 -0800 Subject: [PATCH 16/22] Updating demo to show new functionality. --- app/index.html | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/index.html b/app/index.html index 471dda6..f4ea382 100644 --- a/app/index.html +++ b/app/index.html @@ -39,7 +39,13 @@

Custom formats

{{format}}
- +
+ +

First day

+
+
First Day: {{weekDay[0]}}
+
+

Minimum / Maximum dates

@@ -187,6 +193,16 @@

Select a date from either picker

"lll", ]; + $scope.weekDays = [ + ['Sunday', 0], + ['Monday', 1], + ['Tuesday', 2], + ['Wednesday', 3], + ['Thursday', 4], + ['Friday', 5], + ['Saturday', 6], + ]; + $scope.timezones = [ ['London, UK', 'Europe/London'], ['Hong Kong, China', 'Asia/Hong_Kong'], From 55ec7e64f8f4583cf83bc54da7af9e724ae9b795 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 24 Nov 2015 11:56:02 -0800 Subject: [PATCH 17/22] Updating combined and minified files --- dist/angular-datepicker.js | 31 +++++++++++++++---------------- dist/angular-datepicker.min.js | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index f4cdef8..d6cde62 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -20,7 +20,8 @@ Module.constant('datePickerConfig', { hours: ['hours', 'isSameHour'], minutes: ['minutes', 'isSameMinutes'], }, - step: 5 + step: 5, + firstDay: 0 //Sunday is the first day by default. }); //Moment format filter. @@ -64,8 +65,6 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function return datePickerUtils.getDate(scope, attrs, name); } - datePickerUtils.setParams(attrs.timezone); - var arrowClick = false, tz = scope.tz = attrs.timezone, createMoment = datePickerUtils.createMoment, @@ -77,7 +76,10 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function pickerID = element[0].id, now = scope.now = createMoment(), selected = scope.date = createMoment(scope.model || now), - autoclose = attrs.autoClose === 'true'; + autoclose = attrs.autoClose === 'true', + firstDay = attrs.firstDay && attrs.firstDay >= 0 && attrs.firstDay <= 6 ? parseInt(attrs.firstDay, 10) : datePickerConfig.firstDay; + + datePickerUtils.setParams(tz, firstDay); if (!scope.model) { selected.minute(Math.ceil(selected.minute() / step) * step).second(0); @@ -141,7 +143,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function function update() { var view = scope.view; - datePickerUtils.setParams(tz); + datePickerUtils.setParams(tz, firstDay); if (scope.model && !arrowClick) { scope.date = createMoment(scope.model); @@ -194,7 +196,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function classes = [], classList = '', i, j; - datePickerUtils.setParams(tz); + datePickerUtils.setParams(tz, firstDay); if (view === 'date') { var weeks = scope.weeks, week; @@ -356,7 +358,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function /* global moment */ angular.module('datePicker').factory('datePickerUtils', function () { -var tz; +var tz, firstDay; var createNewDate = function (year, month, day, hour, minute) { var utc = Date.UTC(year | 0, month | 0, day | 0, hour | 0, minute | 0); return tz ? moment.tz(utc, tz) : moment(utc); @@ -388,13 +390,8 @@ var tz; //Grab day of the week var day = m.day(); - if (day === 0) { - //If the first day of the month is a sunday, go back one week. - m.date(-6); - } else { - //Otherwise, go back the required number of days to arrive at the previous sunday - m.date(1 - day); - } + //Go back the required number of days to arrive at the previous week start + m.date(firstDay - (day + (firstDay >= day ? 6 : -1))); var weeks = []; @@ -432,7 +429,7 @@ var tz; return years; }, getDaysOfWeek: function (m) { - m = m ? m : (tz ? moment.tz(tz).day(0) : moment().day(0)); + m = m ? m : (tz ? moment.tz(tz).day(firstDay) : moment().day(firstDay)); var year = m.year(), month = m.month(), @@ -510,8 +507,9 @@ var tz; isSameMinutes: function (model, date) { return this.isSameHour(model, date) && model.minutes() === date.minutes(); }, - setParams: function (zone) { + setParams: function (zone, fd) { tz = zone; + firstDay = fd; }, scopeSearch: function (scope, name, comparisonFn) { var parentScope = scope, @@ -694,6 +692,7 @@ Module.constant('dateTimeConfig', { (attrs.step ? 'step="' + attrs.step + '" ' : '') + (attrs.onSetDate ? 'date-change="' + attrs.onSetDate + '" ' : '') + (attrs.ngModel ? 'ng-model="' + attrs.ngModel + '" ' : '') + + (attrs.firstDay ? 'first-day="' + attrs.firstDay + '" ' : '') + (attrs.timezone ? 'timezone="' + attrs.timezone + '" ' : '') + 'class="date-picker-date-time">
'; }, diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 822980d..5491594 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s),"date"===f){var j,k=d.weeks;for(a=0;ae;e+=b)d=c(f,g,h,i-j,e),k.push(d);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),c=a.month();a.date(1);var d=a.day();0===d?a.date(-6):a.date(1-d);for(var e=[];e.length<6&&!(a.year()===b&&a.month()>c);)e.push(this.getDaysOfWeek(a)),a.add(7,"d");return e},getVisibleYears:function(a){var b=moment(a),d=b.year();b.year(d-d%10),d=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=c(d,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=c(d,0,1,0-f),g=f),h.push(e),d++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(0):moment().day(0);for(var d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60,k=0;7>k;k++)d=c(f,g,h,0-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,0-e,0,!1)),i.push(d),h++;return i},getVisibleMonths:function(a){for(var b,d,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=c(e,h,1,0-f,0,!1),d=b.utcOffset()/60,d!==f&&(b=c(e,h,1,0-d,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,d,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)d=c(f,g,h,b-j,0,!1),e=d.utcOffset()/60,e!==j&&(d=c(f,g,h,b-e,0,!1)),i.push(d);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a){b=a},scopeSearch:function(a,b,c){var d,e,f=a,g=b.split("."),h=g.length;do{for(d=f=f.$parent,e=0;h>e;e++){d=d[g[e]]}if(d&&c(d))return d}while(f.$parent);return!1},findFunction:function(b,c){return this.scopeSearch(b,c,function(b){return a.isFunction(b)})},findParam:function(a,b){return this.scopeSearch(a,b,function(){return!0})},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file +"use strict";!function(a){var b=a.module("datePicker",[]);b.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5,firstDay:0}),b.filter("mFormat",function(){return function(a,b,c){return moment.isMoment(a)?c?moment.tz(a,c).format(b):a.format(b):moment(a).format(b)}}),b.directive("datePicker",["datePickerConfig","datePickerUtils",function(b,c){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(d,e,f,g){function h(){d.views=b.views.concat(),d.view=f.view||b.view,d.views=d.views.slice(d.views.indexOf(f.maxView||"year"),d.views.indexOf(f.minView||"minutes")+1),(1===d.views.length||-1===d.views.indexOf(d.view))&&(d.view=d.views[0])}function i(a){return c.getDate(d,f,a)}function j(a){a&&(d.model=a,g&&g.$setViewValue(a)),d.$emit("setDate",d.model,d.view),d.callbackOnSetDate&&d.callbackOnSetDate(f.datePicker,d.date)}function k(){var a=d.view;c.setParams(s,D),d.model&&!r&&(d.date=t(d.model),r=!1);var b=d.date;switch(a){case"year":d.years=c.getVisibleYears(b);break;case"month":d.months=c.getVisibleMonths(b);break;case"date":d.weekdays=d.weekdays||c.getDaysOfWeek(),d.weeks=c.getVisibleWeeks(b);break;case"hours":d.hours=c.getVisibleHours(b);break;case"minutes":d.minutes=c.getVisibleMinutes(b,v)}m()}function l(){return"date"!==d.view?d.view:d.date?d.date.month():null}function m(){var a,e,f=d.view,g=d.date,h=[],i="";if(c.setParams(s,D),"date"===f){var j,k=d.weeks;for(a=0;a=0&&f.firstDay<=6?parseInt(f.firstDay,10):b.firstDay;c.setParams(s,D),d.model||B.minute(Math.ceil(B.minute()/v)*v).second(0),d.template=f.template||b.template,d.watchDirectChanges=void 0!==f.watchDirectChanges,d.callbackOnSetDate=f.dateChange?c.findFunction(d,f.dateChange):void 0,h(),d.setView=function(a){-1!==d.views.indexOf(a)&&(d.view=a)},d.selectDate=function(a){if(f.disabled)return!1;if(o(d.date,a)&&(a=d.date),a=p(a),!a)return!1;d.date=a;var b=d.views[d.views.indexOf(d.view)+1];(!b||w||d.model)&&j(a),b?d.setView(b):C?(e.addClass("hidden"),d.$emit("hidePicker")):m()},d.$watch(l,k),d.watchDirectChanges&&d.$watch("model",function(){r=!1,k()}),d.next=function(a){var b=moment(d.date);switch(a=a||1,d.view){case"year":case"month":b.year(b.year()+a);break;case"date":b.month(b.month()+a);break;case"hours":case"minutes":b.hours(b.hours()+a)}b=p(b),b&&(d.date=b,j(b),r=!0,k())},d.prev=function(a){return d.next(-a||-1)},z&&d.$on("pickerUpdate",function(b,c,d){if(u(c,z)){var e=!1,g=!1;a.isDefined(d.minDate)&&(x=d.minDate?d.minDate:!1,g=!0),a.isDefined(d.maxDate)&&(y=d.maxDate?d.maxDate:!1,g=!0),a.isDefined(d.minView)&&(f.minView=d.minView,e=!0),a.isDefined(d.maxView)&&(f.maxView=d.maxView,e=!0),f.view=d.view||f.view,e&&h(),g&&k()}})}}}]),a.module("datePicker").factory("datePickerUtils",function(){var b,c,d=function(a,c,d,e,f){var g=Date.UTC(0|a,0|c,0|d,0|e,0|f);return b?moment.tz(g,b):moment(g)};return{getVisibleMinutes:function(a,b){var c,e,f=a.year(),g=a.month(),h=a.date(),i=a.hours(),j=a.utcOffset()/60,k=[];for(e=0;60>e;e+=b)c=d(f,g,h,i-j,e),k.push(c);return k},getVisibleWeeks:function(a){a=moment(a);var b=a.year(),d=a.month();a.date(1);var e=a.day();a.date(c-(e+(c>=e?6:-1)));for(var f=[];f.length<6&&!(a.year()===b&&a.month()>d);)f.push(this.getDaysOfWeek(a)),a.add(7,"d");return f},getVisibleYears:function(a){var b=moment(a),c=b.year();b.year(c-c%10),c=b.year();for(var e,f,g=b.utcOffset()/60,h=[],i=0;12>i;i++)e=d(c,0,1,0-g),f=e.utcOffset()/60,f!==g&&(e=d(c,0,1,0-f),g=f),h.push(e),c++;return h},getDaysOfWeek:function(a){a=a?a:b?moment.tz(b).day(c):moment().day(c);for(var e,f,g=a.year(),h=a.month(),i=a.date(),j=[],k=a.utcOffset()/60,l=0;7>l;l++)e=d(g,h,i,0-k,0,!1),f=e.utcOffset()/60,f!==k&&(e=d(g,h,i,0-f,0,!1)),j.push(e),i++;return j},getVisibleMonths:function(a){for(var b,c,e=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=d(e,h,1,0-f,0,!1),c=b.utcOffset()/60,c!==f&&(b=d(e,h,1,0-c,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,c,e,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)c=d(f,g,h,b-j,0,!1),e=c.utcOffset()/60,e!==j&&(c=d(f,g,h,b-e,0,!1)),i.push(c);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a,d){b=a,c=d},scopeSearch:function(a,b,c){var d,e,f=a,g=b.split("."),h=g.length;do{for(d=f=f.$parent,e=0;h>e;e++){d=d[g[e]]}if(d&&c(d))return d}while(f.$parent);return!1},findFunction:function(b,c){return this.scopeSearch(b,c,function(b){return a.isFunction(b)})},findParam:function(a,b){return this.scopeSearch(a,b,function(){return!0})},createMoment:function(a){return b?moment.tz(a,b):moment.isMoment(a)?moment.unix(a.unix()):moment(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var b=a.module("datePicker");b.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(b,c,d){function e(b,c,e,f,g){return d.template(a.extend(b,{ngModel:e,minDate:f&&moment.isMoment(f)?f.format():!1,maxDate:g&&moment.isMoment(g)?g.format():!1}),c)}function f(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(d,g,h){function i(a){d.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){d.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=g[0].id,m=[f(),f()],n=c.createMoment,o=c.eventIsForPicker;d.dateChange=function(a,b){k&&k(a,b)},l&&d.$on("pickerUpdate",function(a,b,c){o(b,l)&&d.$broadcast("pickerUpdate",m,c)}),c.setParams(h.timezone),d.start=n(d.start),d.end=n(d.end),d.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=c.findFunction(d,h.dateChange)),h.onSetDate="dateChange";var p='
'+e(h,m[0],"start",!1,d.end)+''+e(h,m[1],"end",d.start,!1)+"
",q=b(p)(d);g.append(q)}}}]);var c="ng-pristine",d="ng-dirty",b=a.module("datePicker");b.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),b.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),b.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(b,e,f,g,h,i){var j=e.find("body"),k=f("mFormat");return{require:"ngModel",scope:!0,link:function(e,f,l,m){function n(a){return k(a,w,K)}function o(a){return a.length===w.length?a:void 0}function p(a){G=a,l.minDate=a?a.format():a,H=moment.isMoment(a)}function q(a){I=a,l.maxDate=a?a.format():a,J=moment.isMoment(a)}function r(){v=g.template(l)}function s(a){a.stopPropagation(),m.$pristine&&(m.$dirty=!0,m.$pristine=!1,f.removeClass(c).addClass(d),x&&x.$setDirty(),m.$render())}function t(){C&&(C.remove(),C=null),F&&(F.remove(),F=null)}function u(){if(!C){if(C=b(v)(e),e.$digest(),N||(e.$on("setDate",function(a,b,c){s(a),M&&M(l.ngModel,b),B&&y[y.length-1]===c&&t()}),e.$on("hidePicker",function(){f.triggerHandler("blur")}),e.$on("$destroy",t),N=!0),"absolute"===E){var c=a.extend(f.offset(),{height:f[0].offsetHeight});C.css({top:c.top+c.height,left:c.left,display:"block",position:E}),j.append(C)}else F=a.element("
"),f[0].parentElement.insertBefore(F[0],f[0]),F.append(C),C.css({top:f[0].offsetHeight+"px",display:"block"});C.bind("mousedown",function(a){a.preventDefault()})}}var v,w=l.format||g.format,x=f.inheritedData("$formController"),y=h(l.views)(e)||g.views.concat(),z=l.view||y[0],A=y.indexOf(z),B=l.autoClose?h(l.autoClose)(e):g.autoClose,C=null,D=f[0].id,E=l.position||g.position,F=null,G=null,H=null,I=null,J=null,K=l.timezone||!1,L=i.eventIsForPicker,M=null,N=!1;-1===A&&y.splice(A,1),y.unshift(z),m.$formatters.push(n),m.$parsers.unshift(o),a.isDefined(l.minDate)&&(p(i.findParam(e,l.minDate)),m.$validators.min=function(a){return H?moment.isMoment(a)&&(G.isSame(a)||G.isBefore(a)):!0}),a.isDefined(l.maxDate)&&(q(i.findParam(e,l.maxDate)),m.$validators.max=function(a){return J?moment.isMoment(a)&&(I.isSame(a)||I.isAfter(a)):!0}),a.isDefined(l.dateChange)&&(M=i.findFunction(e,l.dateChange)),D&&e.$on("pickerUpdate",function(b,c,d){if(L(c,D))if(C);else{var e=!1;a.isDefined(d.minDate)&&(p(d.minDate),e=!0),a.isDefined(d.maxDate)&&(q(d.maxDate),e=!0),a.isDefined(d.minView)&&(l.minView=d.minView),a.isDefined(d.maxView)&&(l.maxView=d.maxView),l.view=d.view||l.view,e&&m.$validate(),a.isDefined(d.format)&&(w=l.format=d.format||g.format,m.$modelValue=-1),r()}}),f.bind("focus",u),f.bind("blur",t),r()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}(angular); \ No newline at end of file From 328958838f32f86b130f68ca00422f1089fafaf3 Mon Sep 17 00:00:00 2001 From: Daniel Talash Date: Tue, 24 Nov 2015 11:58:07 -0800 Subject: [PATCH 18/22] Updating tests --- test/spec/datePickerUtilsTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/spec/datePickerUtilsTest.js b/test/spec/datePickerUtilsTest.js index 7c60214..681be4a 100644 --- a/test/spec/datePickerUtilsTest.js +++ b/test/spec/datePickerUtilsTest.js @@ -1,5 +1,5 @@ describe('Test date Picker Utils', function(){ - var utils, constants, tz = 'UTC'; + var utils, constants, tz = 'UTC', firstDay = 0 //Sunday; /** * Creates a moment object from an iso8601 string, using a pre-set timezone. @@ -15,7 +15,7 @@ describe('Test date Picker Utils', function(){ beforeEach(angular.mock.inject(function($injector){ utils = $injector.get('datePickerUtils'); constants = $injector.get('datePickerConfig'); - utils.setParams(tz); + utils.setParams(tz, firstDay); })); /* From 442b845840347c344fdde933a6a287fa53230e1e Mon Sep 17 00:00:00 2001 From: Dan Talash Date: Thu, 23 Feb 2017 10:08:05 -0800 Subject: [PATCH 19/22] Fix scoping issue with callbacks --- app/scripts/datePickerUtils.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/app/scripts/datePickerUtils.js b/app/scripts/datePickerUtils.js index 9925cbd..8168d4b 100644 --- a/app/scripts/datePickerUtils.js +++ b/app/scripts/datePickerUtils.js @@ -156,13 +156,15 @@ angular.module('datePicker').factory('datePickerUtils', function () { scopeSearch: function (scope, name, comparisonFn) { var parentScope = scope, nameArray = name.split('.'), - target, i, j = nameArray.length; + target, i, j = nameArray.length, + lastTarget; do { - target = parentScope = parentScope.$parent; + lastTarget = target = parentScope = parentScope.$parent; //Loop through provided names. for (i = 0; i < j; i++) { + lastTarget = target; target = target[nameArray[i]]; if (!target) { continue; @@ -174,7 +176,7 @@ angular.module('datePicker').factory('datePickerUtils', function () { //function. If the comparison function is happy, return //found result. Otherwise, continue to the next parent scope if (target && comparisonFn(target)) { - return target; + return [target, lastTarget]; } } while (parentScope.$parent); @@ -183,17 +185,24 @@ angular.module('datePicker').factory('datePickerUtils', function () { }, findFunction: function (scope, name) { //Search scope ancestors for a matching function. - return this.scopeSearch(scope, name, function (target) { + var result = this.scopeSearch(scope, name, function (target) { //Property must also be a function return angular.isFunction(target); }); + + + return result ? function () { + result[0].apply(result[1], arguments); + } : false; }, findParam: function (scope, name) { //Search scope ancestors for a matching parameter. - return this.scopeSearch(scope, name, function () { + var result = this.scopeSearch(scope, name, function () { //As long as the property exists, we're good return true; }); + + return result ? result[0] : false; }, createMoment: function (m) { if (tz) { From 61406b7e5b72b84652df8f884c009c0a690287e6 Mon Sep 17 00:00:00 2001 From: Dan Talash Date: Thu, 23 Feb 2017 10:10:42 -0800 Subject: [PATCH 20/22] Updating combined and minified files. --- dist/angular-datepicker.js | 1663 ++++++++++++++++---------------- dist/angular-datepicker.min.js | 2 +- 2 files changed, 828 insertions(+), 837 deletions(-) diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index fb1dc57..1ef70f7 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -1,959 +1,950 @@ (function (global, factory) {'use strict';var fnc;fnc = (typeof exports === 'object' && typeof module !== 'undefined') ? module.exports = factory(require('angular'), require('moment')) :(typeof define === 'function' && define.amd) ? define(['angular', 'moment'], factory) :factory(global.angular, global.moment);}(this, function (angular, moment) { -//(function (global, factory) { -// 'use strict'; -// var fnc; -// fnc = (typeof exports === 'object' && typeof module !== 'undefined') ? module.exports = factory(require('angular'), require('moment')) : -// (typeof define === 'function' && define.amd) ? define(['angular', 'moment'], factory) : -// factory(global.angular, global.moment); -//}(this, function (angular, moment) { var Module = angular.module('datePicker', []); - Module.constant('datePickerConfig', { - template: 'templates/datepicker.html', - view: 'month', - views: ['year', 'month', 'date', 'hours', 'minutes'], - momentNames: { - year: 'year', - month: 'month', - date: 'day', - hours: 'hours', - minutes: 'minutes', - }, - viewConfig: { - year: ['years', 'isSameYear'], - month: ['months', 'isSameMonth'], - hours: ['hours', 'isSameHour'], - minutes: ['minutes', 'isSameMinutes'], - }, - step: 5 - }); +Module.constant('datePickerConfig', { + template: 'templates/datepicker.html', + view: 'month', + views: ['year', 'month', 'date', 'hours', 'minutes'], + momentNames: { + year: 'year', + month: 'month', + date: 'day', + hours: 'hours', + minutes: 'minutes', + }, + viewConfig: { + year: ['years', 'isSameYear'], + month: ['months', 'isSameMonth'], + hours: ['hours', 'isSameHour'], + minutes: ['minutes', 'isSameMinutes'], + }, + step: 5 +}); //Moment format filter. - Module.filter('mFormat', function () { - return function (m, format, tz) { - if (!(moment.isMoment(m))) { - return (m) ? moment(m).format(format) : ''; - } - return tz ? moment.tz(m, tz).format(format) : m.format(format); - }; - }); - - Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function datePickerDirective(datePickerConfig, datePickerUtils) { - - //noinspection JSUnusedLocalSymbols - return { - // this is a bug ? - require: '?ngModel', - template: '
', - scope: { - model: '=datePicker', - after: '=?', - before: '=?' - }, - link: function (scope, element, attrs, ngModel) { - function prepareViews() { - scope.views = datePickerConfig.views.concat(); - scope.view = attrs.view || datePickerConfig.view; - - scope.views = scope.views.slice( - scope.views.indexOf(attrs.maxView || 'year'), - scope.views.indexOf(attrs.minView || 'minutes') + 1 - ); - - if (scope.views.length === 1 || scope.views.indexOf(scope.view) === -1) { - scope.view = scope.views[0]; - } +Module.filter('mFormat', function () { + return function (m, format, tz) { + if (!(moment.isMoment(m))) { + return moment(m).format(format); + } + return tz ? moment.tz(m, tz).format(format) : m.format(format); + }; +}); + +Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function datePickerDirective(datePickerConfig, datePickerUtils) { + + //noinspection JSUnusedLocalSymbols + return { + // this is a bug ? + require: '?ngModel', + template: '
', + scope: { + model: '=datePicker', + after: '=?', + before: '=?' + }, + link: function (scope, element, attrs, ngModel) { + function prepareViews() { + scope.views = datePickerConfig.views.concat(); + scope.view = attrs.view || datePickerConfig.view; + + scope.views = scope.views.slice( + scope.views.indexOf(attrs.maxView || 'year'), + scope.views.indexOf(attrs.minView || 'minutes') + 1 + ); + + if (scope.views.length === 1 || scope.views.indexOf(scope.view) === -1) { + scope.view = scope.views[0]; } + } - function getDate(name) { - return datePickerUtils.getDate(scope, attrs, name); - } + function getDate(name) { + return datePickerUtils.getDate(scope, attrs, name); + } - var arrowClick = false, - tz = scope.tz = attrs.timezone, - createMoment = datePickerUtils.createMoment, - eventIsForPicker = datePickerUtils.eventIsForPicker, - step = parseInt(attrs.step || datePickerConfig.step, 10), - partial = !!attrs.partial, - minDate = getDate('minDate'), - maxDate = getDate('maxDate'), - pickerID = element[0].id, - now = scope.now = createMoment(), - selected = scope.date = createMoment(scope.model || now), - autoclose = attrs.autoClose === 'true', - // Either gets the 1st day from the attributes, or asks moment.js to give it to us as it is localized. - firstDay = attrs.firstDay && attrs.firstDay >= 0 && attrs.firstDay <= 6 ? parseInt(attrs.firstDay, 10) : moment().weekday(0).day(), - setDate, - prepareViewData, - isSame, - clipDate, - isNow, - inValidRange; + var arrowClick = false, + tz = scope.tz = attrs.timezone, + createMoment = datePickerUtils.createMoment, + eventIsForPicker = datePickerUtils.eventIsForPicker, + step = parseInt(attrs.step || datePickerConfig.step, 10), + partial = !!attrs.partial, + minDate = getDate('minDate'), + maxDate = getDate('maxDate'), + pickerID = element[0].id, + now = scope.now = createMoment(), + selected = scope.date = createMoment(scope.model || now), + autoclose = attrs.autoClose === 'true', + // Either gets the 1st day from the attributes, or asks moment.js to give it to us as it is localized. + firstDay = attrs.firstDay && attrs.firstDay >= 0 && attrs.firstDay <= 6 ? parseInt(attrs.firstDay, 10) : moment().weekday(0).day(), + setDate, + prepareViewData, + isSame, + clipDate, + isNow, + inValidRange; + + datePickerUtils.setParams(tz, firstDay); + + if (!scope.model) { + selected.minute(Math.ceil(selected.minute() / step) * step).second(0); + } - datePickerUtils.setParams(tz, firstDay); + scope.template = attrs.template || datePickerConfig.template; - if (!scope.model) { - selected.minute(Math.ceil(selected.minute() / step) * step).second(0); - } + scope.watchDirectChanges = attrs.watchDirectChanges !== undefined; + scope.callbackOnSetDate = attrs.dateChange ? datePickerUtils.findFunction(scope, attrs.dateChange) : undefined; - scope.template = attrs.template || datePickerConfig.template; + prepareViews(); - scope.watchDirectChanges = attrs.watchDirectChanges !== undefined; - scope.callbackOnSetDate = attrs.dateChange ? datePickerUtils.findFunction(scope, attrs.dateChange) : undefined; + scope.setView = function (nextView) { + if (scope.views.indexOf(nextView) !== -1) { + scope.view = nextView; + } + }; - prepareViews(); + scope.selectDate = function (date) { + if (attrs.disabled) { + return false; + } + if (isSame(scope.date, date)) { + date = scope.date; + } + date = clipDate(date); + if (!date) { + return false; + } + scope.date = date; - scope.setView = function (nextView) { - if (scope.views.indexOf(nextView) !== -1) { - scope.view = nextView; - } - }; + var nextView = scope.views[scope.views.indexOf(scope.view) + 1]; + if ((!nextView || partial) || scope.model) { + setDate(date); + } - scope.selectDate = function (date) { - if (attrs.disabled) { - return false; - } - if (isSame(scope.date, date)) { - date = scope.date; - } - date = clipDate(date); - if (!date) { - return false; - } - scope.date = date; + if (nextView) { + scope.setView(nextView); + } else if (autoclose) { + element.addClass('hidden'); + scope.$emit('hidePicker'); + } else { + prepareViewData(); + } + }; - var nextView = scope.views[scope.views.indexOf(scope.view) + 1]; - if ((!nextView || partial) || scope.model) { - setDate(date); + setDate = function (date) { + if (date) { + scope.model = date; + if (ngModel) { + ngModel.$setViewValue(date); } + } + scope.$emit('setDate', scope.model, scope.view); - if (nextView) { - scope.setView(nextView); - } else if (autoclose) { - element.addClass('hidden'); - scope.$emit('hidePicker'); - } else { - prepareViewData(); - } - }; + //This is duplicated in the new functionality. + if (scope.callbackOnSetDate) { + scope.callbackOnSetDate(attrs.datePicker, scope.date); + } + }; - setDate = function (date) { - if (date) { - scope.model = date; - if (ngModel) { - ngModel.$setViewValue(date); - } - } - scope.$emit('setDate', scope.model, scope.view); + function update() { + var view = scope.view; + datePickerUtils.setParams(tz, firstDay); - //This is duplicated in the new functionality. - if (scope.callbackOnSetDate) { - scope.callbackOnSetDate(attrs.datePicker, scope.date); - } - }; + if (scope.model && !arrowClick) { + scope.date = createMoment(scope.model); + arrowClick = false; + } - function update() { - var view = scope.view; - datePickerUtils.setParams(tz, firstDay); + var date = scope.date; - if (scope.model && !arrowClick) { - scope.date = createMoment(scope.model); - arrowClick = false; - } + switch (view) { + case 'year': + scope.years = datePickerUtils.getVisibleYears(date); + break; + case 'month': + scope.months = datePickerUtils.getVisibleMonths(date); + break; + case 'date': + scope.weekdays = scope.weekdays || datePickerUtils.getDaysOfWeek(); + scope.weeks = datePickerUtils.getVisibleWeeks(date); + break; + case 'hours': + scope.hours = datePickerUtils.getVisibleHours(date); + break; + case 'minutes': + scope.minutes = datePickerUtils.getVisibleMinutes(date, step); + break; + } - var date = scope.date; - - switch (view) { - case 'year': - scope.years = datePickerUtils.getVisibleYears(date); - break; - case 'month': - scope.months = datePickerUtils.getVisibleMonths(date); - break; - case 'date': - scope.weekdays = scope.weekdays || datePickerUtils.getDaysOfWeek(); - scope.weeks = datePickerUtils.getVisibleWeeks(date); - break; - case 'hours': - scope.hours = datePickerUtils.getVisibleHours(date); - break; - case 'minutes': - scope.minutes = datePickerUtils.getVisibleMinutes(date, step); - break; - } + prepareViewData(); + } - prepareViewData(); + function watch() { + if (scope.view !== 'date') { + return scope.view; } + return scope.date ? scope.date.month() : null; + } - function watch() { - if (scope.view !== 'date') { - return scope.view; - } - return scope.date ? scope.date.month() : null; - } + scope.$watch(watch, update); - scope.$watch(watch, update); + if (scope.watchDirectChanges) { + scope.$watch('model', function () { + arrowClick = false; + update(); + }); + } - if (scope.watchDirectChanges) { - scope.$watch('model', function () { - arrowClick = false; - update(); - }); - } + prepareViewData = function () { + var view = scope.view, + date = scope.date, + classes = [], classList = '', + i, j; - prepareViewData = function () { - var view = scope.view, - date = scope.date, - classes = [], classList = '', - i, j; - - datePickerUtils.setParams(tz, firstDay); - - if (view === 'date') { - var weeks = scope.weeks, week; - for (i = 0; i < weeks.length; i++) { - week = weeks[i]; - classes.push([]); - for (j = 0; j < week.length; j++) { - classList = ''; - if (datePickerUtils.isSameDay(date, week[j])) { - classList += 'active'; - } - if (isNow(week[j], view)) { - classList += ' now'; - } - //if (week[j].month() !== date.month()) classList += ' disabled'; - if (week[j].month() !== date.month() || !inValidRange(week[j])) { - classList += ' disabled'; - } - classes[i].push(classList); - } - } - } else { - var params = datePickerConfig.viewConfig[view], - dates = scope[params[0]], - compareFunc = params[1]; + datePickerUtils.setParams(tz, firstDay); - for (i = 0; i < dates.length; i++) { + if (view === 'date') { + var weeks = scope.weeks, week; + for (i = 0; i < weeks.length; i++) { + week = weeks[i]; + classes.push([]); + for (j = 0; j < week.length; j++) { classList = ''; - if (datePickerUtils[compareFunc](date, dates[i])) { + if (datePickerUtils.isSameDay(date, week[j])) { classList += 'active'; } - if (isNow(dates[i], view)) { + if (isNow(week[j], view)) { classList += ' now'; } - if (!inValidRange(dates[i])) { + //if (week[j].month() !== date.month()) classList += ' disabled'; + if (week[j].month() !== date.month() || !inValidRange(week[j])) { classList += ' disabled'; } - classes.push(classList); + classes[i].push(classList); } } - scope.classes = classes; - }; - - scope.next = function (delta) { - var date = moment(scope.date); - delta = delta || 1; - switch (scope.view) { - case 'year': - /*falls through*/ - case 'month': - date.year(date.year() + delta); - break; - case 'date': - date.month(date.month() + delta); - break; - case 'hours': - /*falls through*/ - case 'minutes': - date.hours(date.hours() + delta); - break; - } - date = clipDate(date); - if (date) { - scope.date = date; - arrowClick = true; - update(); - } - }; - - inValidRange = function (date) { - var valid = true; - if (minDate && minDate.isAfter(date)) { - valid = isSame(minDate, date); - } - if (maxDate && maxDate.isBefore(date)) { - valid &= isSame(maxDate, date); - } - return valid; - }; - - isSame = function (date1, date2) { - return date1.isSame(date2, datePickerConfig.momentNames[scope.view]) ? true : false; - }; - - clipDate = function (date) { - if (minDate && minDate.isAfter(date)) { - return minDate; - } else if (maxDate && maxDate.isBefore(date)) { - return maxDate; - } else { - return date; + } else { + var params = datePickerConfig.viewConfig[view], + dates = scope[params[0]], + compareFunc = params[1]; + + for (i = 0; i < dates.length; i++) { + classList = ''; + if (datePickerUtils[compareFunc](date, dates[i])) { + classList += 'active'; + } + if (isNow(dates[i], view)) { + classList += ' now'; + } + if (!inValidRange(dates[i])) { + classList += ' disabled'; + } + classes.push(classList); } - }; + } + scope.classes = classes; + }; + + scope.next = function (delta) { + var date = moment(scope.date); + delta = delta || 1; + switch (scope.view) { + case 'year': + /*falls through*/ + case 'month': + date.year(date.year() + delta); + break; + case 'date': + date.month(date.month() + delta); + break; + case 'hours': + /*falls through*/ + case 'minutes': + date.hours(date.hours() + delta); + break; + } + date = clipDate(date); + if (date) { + scope.date = date; + arrowClick = true; + update(); + } + }; - isNow = function (date, view) { - var is = true; - - switch (view) { - case 'minutes': - is &= ~~(now.minutes() / step) === ~~(date.minutes() / step); - /* falls through */ - case 'hours': - is &= now.hours() === date.hours(); - /* falls through */ - case 'date': - is &= now.date() === date.date(); - /* falls through */ - case 'month': - is &= now.month() === date.month(); - /* falls through */ - case 'year': - is &= now.year() === date.year(); - } - return is; - }; + inValidRange = function (date) { + var valid = true; + if (minDate && minDate.isAfter(date)) { + valid = isSame(minDate, date); + } + if (maxDate && maxDate.isBefore(date)) { + valid &= isSame(maxDate, date); + } + return valid; + }; + + isSame = function (date1, date2) { + return date1.isSame(date2, datePickerConfig.momentNames[scope.view]) ? true : false; + }; + + clipDate = function (date) { + if (minDate && minDate.isAfter(date)) { + return minDate; + } else if (maxDate && maxDate.isBefore(date)) { + return maxDate; + } else { + return date; + } + }; + + isNow = function (date, view) { + var is = true; + + switch (view) { + case 'minutes': + is &= ~~(now.minutes() / step) === ~~(date.minutes() / step); + /* falls through */ + case 'hours': + is &= now.hours() === date.hours(); + /* falls through */ + case 'date': + is &= now.date() === date.date(); + /* falls through */ + case 'month': + is &= now.month() === date.month(); + /* falls through */ + case 'year': + is &= now.year() === date.year(); + } + return is; + }; - scope.prev = function (delta) { - return scope.next(-delta || -1); - }; + scope.prev = function (delta) { + return scope.next(-delta || -1); + }; - if (pickerID) { - scope.$on('pickerUpdate', function (event, pickerIDs, data) { - if (eventIsForPicker(pickerIDs, pickerID)) { - var updateViews = false, updateViewData = false; + if (pickerID) { + scope.$on('pickerUpdate', function (event, pickerIDs, data) { + if (eventIsForPicker(pickerIDs, pickerID)) { + var updateViews = false, updateViewData = false; - if (angular.isDefined(data.minDate)) { - minDate = data.minDate ? data.minDate : false; - updateViewData = true; - } - if (angular.isDefined(data.maxDate)) { - maxDate = data.maxDate ? data.maxDate : false; - updateViewData = true; - } + if (angular.isDefined(data.minDate)) { + minDate = data.minDate ? data.minDate : false; + updateViewData = true; + } + if (angular.isDefined(data.maxDate)) { + maxDate = data.maxDate ? data.maxDate : false; + updateViewData = true; + } - if (angular.isDefined(data.minView)) { - attrs.minView = data.minView; - updateViews = true; - } - if (angular.isDefined(data.maxView)) { - attrs.maxView = data.maxView; - updateViews = true; - } - attrs.view = data.view || attrs.view; + if (angular.isDefined(data.minView)) { + attrs.minView = data.minView; + updateViews = true; + } + if (angular.isDefined(data.maxView)) { + attrs.maxView = data.maxView; + updateViews = true; + } + attrs.view = data.view || attrs.view; - if (updateViews) { - prepareViews(); - } + if (updateViews) { + prepareViews(); + } - if (updateViewData) { - update(); - } + if (updateViewData) { + update(); } - }); - } + } + }); } - }; - }]); -//})); - -//(function (global, factory) { -// 'use strict'; -// var fnc; -// fnc = (typeof exports === 'object' && typeof module !== 'undefined') ? module.exports = factory(require('angular'), require('moment')) : -// (typeof define === 'function' && define.amd) ? define(['angular', 'moment'], factory) : -// factory(global.angular, global.moment); -//}(this, function (angular, moment) { + } + }; +}]); + angular.module('datePicker').factory('datePickerUtils', function () { - var tz, firstDay; - var createNewDate = function (year, month, day, hour, minute) { - var utc = Date.UTC(year | 0, month | 0, day | 0, hour | 0, minute | 0); - return tz ? moment.tz(utc, tz) : moment(utc); - }; - - return { - getVisibleMinutes: function (m, step) { - var year = m.year(), - month = m.month(), - day = m.date(), - hour = m.hours(), pushedDate, - offset = m.utcOffset() / 60, - minutes = [], minute; - - for (minute = 0; minute < 60; minute += step) { - pushedDate = createNewDate(year, month, day, hour - offset, minute); - minutes.push(pushedDate); - } - return minutes; - }, - getVisibleWeeks: function (m) { - m = moment(m); - var startYear = m.year(), - startMonth = m.month(); + var tz, firstDay; + var createNewDate = function (year, month, day, hour, minute) { + var utc = Date.UTC(year | 0, month | 0, day | 0, hour | 0, minute | 0); + return tz ? moment.tz(utc, tz) : moment(utc); + }; + + return { + getVisibleMinutes: function (m, step) { + var year = m.year(), + month = m.month(), + day = m.date(), + hour = m.hours(), pushedDate, + offset = m.utcOffset() / 60, + minutes = [], minute; + + for (minute = 0; minute < 60; minute += step) { + pushedDate = createNewDate(year, month, day, hour - offset, minute); + minutes.push(pushedDate); + } + return minutes; + }, + getVisibleWeeks: function (m) { + m = moment(m); + var startYear = m.year(), + startMonth = m.month(); - //Set date to the first day of the month - m.date(1); + //Set date to the first day of the month + m.date(1); - //Grab day of the week - var day = m.day(); + //Grab day of the week + var day = m.day(); - //Go back the required number of days to arrive at the previous week start - m.date(firstDay - (day + (firstDay >= day ? 6 : -1))); + //Go back the required number of days to arrive at the previous week start + m.date(firstDay - (day + (firstDay >= day ? 6 : -1))); - var weeks = []; + var weeks = []; - while (weeks.length < 6) { - if (m.year() === startYear && m.month() > startMonth) { - break; - } - weeks.push(this.getDaysOfWeek(m)); - m.add(7, 'd'); + while (weeks.length < 6) { + if (m.year() === startYear && m.month() > startMonth) { + break; } - return weeks; - }, - getVisibleYears: function (d) { - var m = moment(d), - year = m.year(); - - m.year(year - (year % 10)); + weeks.push(this.getDaysOfWeek(m)); + m.add(7, 'd'); + } + return weeks; + }, + getVisibleYears: function (d) { + var m = moment(d), year = m.year(); - var offset = m.utcOffset() / 60, - years = [], - pushedDate, - actualOffset; - - for (var i = 0; i < 12; i++) { - pushedDate = createNewDate(year, 0, 1, 0 - offset); - actualOffset = pushedDate.utcOffset() / 60; - if (actualOffset !== offset) { - pushedDate = createNewDate(year, 0, 1, 0 - actualOffset); - offset = actualOffset; - } - years.push(pushedDate); - year++; + m.year(year - (year % 10)); + year = m.year(); + + var offset = m.utcOffset() / 60, + years = [], + pushedDate, + actualOffset; + + for (var i = 0; i < 12; i++) { + pushedDate = createNewDate(year, 0, 1, 0 - offset); + actualOffset = pushedDate.utcOffset() / 60; + if (actualOffset !== offset) { + pushedDate = createNewDate(year, 0, 1, 0 - actualOffset); + offset = actualOffset; } - return years; - }, - getDaysOfWeek: function (m) { - m = m ? m : (tz ? moment.tz(tz).day(firstDay) : moment().day(firstDay)); - - var year = m.year(), - month = m.month(), - day = m.date(), - days = [], - pushedDate, - offset = m.utcOffset() / 60, - actualOffset; - - for (var i = 0; i < 7; i++) { - pushedDate = createNewDate(year, month, day, 0 - offset, 0, false); - actualOffset = pushedDate.utcOffset() / 60; - if (actualOffset !== offset) { - pushedDate = createNewDate(year, month, day, 0 - actualOffset, 0, false); - } - days.push(pushedDate); - day++; + years.push(pushedDate); + year++; + } + return years; + }, + getDaysOfWeek: function (m) { + m = m ? m : (tz ? moment.tz(tz).day(firstDay) : moment().day(firstDay)); + + var year = m.year(), + month = m.month(), + day = m.date(), + days = [], + pushedDate, + offset = m.utcOffset() / 60, + actualOffset; + + for (var i = 0; i < 7; i++) { + pushedDate = createNewDate(year, month, day, 0 - offset, 0, false); + actualOffset = pushedDate.utcOffset() / 60; + if (actualOffset !== offset) { + pushedDate = createNewDate(year, month, day, 0 - actualOffset, 0, false); } - return days; - }, - getVisibleMonths: function (m) { - var year = m.year(), - offset = m.utcOffset() / 60, - months = [], - pushedDate, - actualOffset; - - for (var month = 0; month < 12; month++) { - pushedDate = createNewDate(year, month, 1, 0 - offset, 0, false); - actualOffset = pushedDate.utcOffset() / 60; - if (actualOffset !== offset) { - pushedDate = createNewDate(year, month, 1, 0 - actualOffset, 0, false); - } - months.push(pushedDate); + days.push(pushedDate); + day++; + } + return days; + }, + getVisibleMonths: function (m) { + var year = m.year(), + offset = m.utcOffset() / 60, + months = [], + pushedDate, + actualOffset; + + for (var month = 0; month < 12; month++) { + pushedDate = createNewDate(year, month, 1, 0 - offset, 0, false); + actualOffset = pushedDate.utcOffset() / 60; + if (actualOffset !== offset) { + pushedDate = createNewDate(year, month, 1, 0 - actualOffset, 0, false); } - return months; - }, - getVisibleHours: function (m) { - var year = m.year(), - month = m.month(), - day = m.date(), - hours = [], - hour, pushedDate, actualOffset, - offset = m.utcOffset() / 60; - - for (hour = 0; hour < 24; hour++) { - pushedDate = createNewDate(year, month, day, hour - offset, 0, false); - actualOffset = pushedDate.utcOffset() / 60; - if (actualOffset !== offset) { - pushedDate = createNewDate(year, month, day, hour - actualOffset, 0, false); - } - hours.push(pushedDate); + months.push(pushedDate); + } + return months; + }, + getVisibleHours: function (m) { + var year = m.year(), + month = m.month(), + day = m.date(), + hours = [], + hour, pushedDate, actualOffset, + offset = m.utcOffset() / 60; + + for (hour = 0; hour < 24; hour++) { + pushedDate = createNewDate(year, month, day, hour - offset, 0, false); + actualOffset = pushedDate.utcOffset() / 60; + if (actualOffset !== offset) { + pushedDate = createNewDate(year, month, day, hour - actualOffset, 0, false); } + hours.push(pushedDate); + } - return hours; - }, - isAfter: function (model, date) { - return model && model.unix() >= date.unix(); - }, - isBefore: function (model, date) { - return model.unix() <= date.unix(); - }, - isSameYear: function (model, date) { - return model && model.year() === date.year(); - }, - isSameMonth: function (model, date) { - return this.isSameYear(model, date) && model.month() === date.month(); - }, - isSameDay: function (model, date) { - return this.isSameMonth(model, date) && model.date() === date.date(); - }, - isSameHour: function (model, date) { - return this.isSameDay(model, date) && model.hours() === date.hours(); - }, - isSameMinutes: function (model, date) { - return this.isSameHour(model, date) && model.minutes() === date.minutes(); - }, - setParams: function (zone, fd) { - tz = zone; - firstDay = fd; - }, - scopeSearch: function (scope, name, comparisonFn) { - var parentScope = scope, - nameArray = name.split('.'), - target, i, j = nameArray.length; - - do { - target = parentScope = parentScope.$parent; - - //Loop through provided names. - for (i = 0; i < j; i++) { - target = target[nameArray[i]]; - if (!target) { - continue; - } - } - - //If we reached the end of the list for this scope, - //and something was found, trigger the comparison - //function. If the comparison function is happy, return - //found result. Otherwise, continue to the next parent scope - if (target && comparisonFn(target)) { - return target; + return hours; + }, + isAfter: function (model, date) { + return model && model.unix() >= date.unix(); + }, + isBefore: function (model, date) { + return model.unix() <= date.unix(); + }, + isSameYear: function (model, date) { + return model && model.year() === date.year(); + }, + isSameMonth: function (model, date) { + return this.isSameYear(model, date) && model.month() === date.month(); + }, + isSameDay: function (model, date) { + return this.isSameMonth(model, date) && model.date() === date.date(); + }, + isSameHour: function (model, date) { + return this.isSameDay(model, date) && model.hours() === date.hours(); + }, + isSameMinutes: function (model, date) { + return this.isSameHour(model, date) && model.minutes() === date.minutes(); + }, + setParams: function (zone, fd) { + tz = zone; + firstDay = fd; + }, + scopeSearch: function (scope, name, comparisonFn) { + var parentScope = scope, + nameArray = name.split('.'), + target, i, j = nameArray.length, + lastTarget; + + do { + lastTarget = target = parentScope = parentScope.$parent; + + //Loop through provided names. + for (i = 0; i < j; i++) { + lastTarget = target; + target = target[nameArray[i]]; + if (!target) { + continue; } - - } while (parentScope.$parent); - - return false; - }, - findFunction: function (scope, name) { - //Search scope ancestors for a matching function. - return this.scopeSearch(scope, name, function (target) { - //Property must also be a function - return angular.isFunction(target); - }); - }, - findParam: function (scope, name) { - //Search scope ancestors for a matching parameter. - return this.scopeSearch(scope, name, function () { - //As long as the property exists, we're good - return true; - }); - }, - createMoment: function (m) { - if (tz) { - return moment.tz(m, tz); - } else { - //If input is a moment, and we have no TZ info, we need to remove TZ - //info from the moment, otherwise the newly created moment will take - //the timezone of the input moment. The easiest way to do that is to - //take the unix timestamp, and use that to create a new moment. - //The new moment will use the local timezone of the user machine. - return moment.isMoment(m) ? moment.unix(m.unix()) : moment(m); } - }, - getDate: function (scope, attrs, name) { - var result = false; - if (attrs[name]) { - result = this.createMoment(attrs[name]); - if (!result.isValid()) { - result = this.findParam(scope, attrs[name]); - if (result) { - result = this.createMoment(result); - } - } + + //If we reached the end of the list for this scope, + //and something was found, trigger the comparison + //function. If the comparison function is happy, return + //found result. Otherwise, continue to the next parent scope + if (target && comparisonFn(target)) { + return [target, lastTarget]; } - return result; - }, - eventIsForPicker: function (targetIDs, pickerID) { - //Checks if an event targeted at a specific picker, via either a string name, or an array of strings. - return (angular.isArray(targetIDs) && targetIDs.indexOf(pickerID) > -1 || targetIDs === pickerID); - } - }; - }); -//})); - -//(function (global, factory) { -// 'use strict'; -// var fnc; -// fnc = (typeof exports === 'object' && typeof module !== 'undefined') ? module.exports = factory(require('angular'), require('moment')) : -// (typeof define === 'function' && define.amd) ? define(['angular', 'moment'], factory) : -// factory(global.angular, global.moment); -//}(this, function (angular, moment) { -var Module = angular.module('datePicker'); + } while (parentScope.$parent); - Module.directive('dateRange', ['$compile', 'datePickerUtils', 'dateTimeConfig', function ($compile, datePickerUtils, dateTimeConfig) { - function getTemplate(attrs, id, model, min, max) { - return dateTimeConfig.template(angular.extend(attrs, { - ngModel: model, - minDate: min && moment.isMoment(min) ? min.format() : false, - maxDate: max && moment.isMoment(max) ? max.format() : false - }), id); - } + return false; + }, + findFunction: function (scope, name) { + //Search scope ancestors for a matching function. + var result = this.scopeSearch(scope, name, function (target) { + //Property must also be a function + return angular.isFunction(target); + }); - function randomName() { - return 'picker' + Math.random().toString().substr(2); - } - return { - scope: { - start: '=', - end: '=' - }, - link: function (scope, element, attrs) { - var dateChange = null, - pickerRangeID = element[0].id, - pickerIDs = [randomName(), randomName()], - createMoment = datePickerUtils.createMoment, - eventIsForPicker = datePickerUtils.eventIsForPicker; - - scope.dateChange = function (modelName, newDate) { - //Notify user if callback exists. - if (dateChange) { - dateChange(modelName, newDate); + return result ? function () { + result[0].apply(result[1], arguments); + } : false; + }, + findParam: function (scope, name) { + //Search scope ancestors for a matching parameter. + var result = this.scopeSearch(scope, name, function () { + //As long as the property exists, we're good + return true; + }); + + return result ? result[0] : false; + }, + createMoment: function (m) { + if (tz) { + return moment.tz(m, tz); + } else { + //If input is a moment, and we have no TZ info, we need to remove TZ + //info from the moment, otherwise the newly created moment will take + //the timezone of the input moment. The easiest way to do that is to + //take the unix timestamp, and use that to create a new moment. + //The new moment will use the local timezone of the user machine. + return moment.isMoment(m) ? moment.unix(m.unix()) : moment(m); + } + }, + getDate: function (scope, attrs, name) { + var result = false; + if (attrs[name]) { + result = this.createMoment(attrs[name]); + if (!result.isValid()) { + result = this.findParam(scope, attrs[name]); + if (result) { + result = this.createMoment(result); } - }; - - function setMax(date) { - scope.$broadcast('pickerUpdate', pickerIDs[0], { - maxDate: date - }); } + } - function setMin(date) { - scope.$broadcast('pickerUpdate', pickerIDs[1], { - minDate: date - }); + return result; + }, + //Checks if an event targeted at a specific picker, via either a string name, or an array of strings. + eventIsForPicker: function (targetIDs, pickerID) { + function matches(id) { + if (id instanceof RegExp) { + return id.test(pickerID); } + return id === pickerID; + } - if (pickerRangeID) { - scope.$on('pickerUpdate', function (event, targetIDs, data) { - if (eventIsForPicker(targetIDs, pickerRangeID)) { - //If we received an update event, dispatch it to the inner pickers using their IDs. - scope.$broadcast('pickerUpdate', pickerIDs, data); - } - }); + if (angular.isArray(targetIDs)) { + return targetIDs.some(matches); + } + return matches(targetIDs); + } + }; +}); + +var Module = angular.module('datePicker'); + +Module.directive('dateRange', ['$compile', 'datePickerUtils', 'dateTimeConfig', function ($compile, datePickerUtils, dateTimeConfig) { + function getTemplate(attrs, id, model, min, max) { + return dateTimeConfig.template(angular.extend(attrs, { + ngModel: model, + minDate: min && moment.isMoment(min) ? min.format() : false, + maxDate: max && moment.isMoment(max) ? max.format() : false + }), id); + } + + function randomName() { + return 'picker' + Math.random().toString().substr(2); + } + + return { + scope: { + start: '=', + end: '=' + }, + link: function (scope, element, attrs) { + var dateChange = null, + pickerRangeID = element[0].id, + pickerIDs = [randomName(), randomName()], + createMoment = datePickerUtils.createMoment, + eventIsForPicker = datePickerUtils.eventIsForPicker; + + scope.dateChange = function (modelName, newDate) { + //Notify user if callback exists. + if (dateChange) { + dateChange(modelName, newDate); } + }; - datePickerUtils.setParams(attrs.timezone); + function setMax(date) { + scope.$broadcast('pickerUpdate', pickerIDs[0], { + maxDate: date + }); + } - scope.start = createMoment(scope.start); - scope.end = createMoment(scope.end); + function setMin(date) { + scope.$broadcast('pickerUpdate', pickerIDs[1], { + minDate: date + }); + } - scope.$watchGroup(['start', 'end'], function (dates) { - //Scope data changed, update picker min/max - setMin(dates[0]); - setMax(dates[1]); + if (pickerRangeID) { + scope.$on('pickerUpdate', function (event, targetIDs, data) { + if (eventIsForPicker(targetIDs, pickerRangeID)) { + //If we received an update event, dispatch it to the inner pickers using their IDs. + scope.$broadcast('pickerUpdate', pickerIDs, data); + } }); + } - if (angular.isDefined(attrs.dateChange)) { - dateChange = datePickerUtils.findFunction(scope, attrs.dateChange); - } + datePickerUtils.setParams(attrs.timezone); - attrs.onSetDate = 'dateChange'; + scope.start = createMoment(scope.start); + scope.end = createMoment(scope.end); - var template = '
' + - getTemplate(attrs, pickerIDs[0], 'start', false, scope.end) + - '' + - getTemplate(attrs, pickerIDs[1], 'end', scope.start, false) + - '
'; + scope.$watchGroup(['start', 'end'], function (dates) { + //Scope data changed, update picker min/max + setMin(dates[0]); + setMax(dates[1]); + }); - var picker = $compile(template)(scope); - element.append(picker); + if (angular.isDefined(attrs.dateChange)) { + dateChange = datePickerUtils.findFunction(scope, attrs.dateChange); } - }; - }]); -//})); - -//(function (global, factory) { -// 'use strict'; -// var fnc; -// fnc = (typeof exports === 'object' && typeof module !== 'undefined') ? module.exports = factory(require('angular'), require('moment')) : -// (typeof define === 'function' && define.amd) ? define(['angular', 'moment'], factory) : -// factory(global.angular, global.moment); -//}(this, function (angular, moment) { + + attrs.onSetDate = 'dateChange'; + + var template = '
' + + getTemplate(attrs, pickerIDs[0], 'start', false, scope.end) + + '' + + getTemplate(attrs, pickerIDs[1], 'end', scope.start, false) + + '
'; + + var picker = $compile(template)(scope); + element.append(picker); + } + }; +}]); + var PRISTINE_CLASS = 'ng-pristine', - DIRTY_CLASS = 'ng-dirty'; - - var Module = angular.module('datePicker'); - - Module.constant('dateTimeConfig', { - template: function (attrs, id) { - return '' + - '
'; - }, - format: 'YYYY-MM-DD HH:mm', - views: ['date', 'year', 'month', 'hours', 'minutes'], - autoClose: false, - position: 'relative' - }); - - Module.directive('dateTimeAppend', function () { - return { - link: function (scope, element) { - element.bind('click', function () { - element.find('input')[0].focus(); - }); + DIRTY_CLASS = 'ng-dirty'; + +var Module = angular.module('datePicker'); + +Module.constant('dateTimeConfig', { + template: function (attrs, id) { + return '' + + '
'; + }, + format: 'YYYY-MM-DD HH:mm', + views: ['date', 'year', 'month', 'hours', 'minutes'], + autoClose: false, + position: 'relative' +}); + +Module.directive('dateTimeAppend', function () { + return { + link: function (scope, element) { + element.bind('click', function () { + element.find('input')[0].focus(); + }); + } + }; +}); + +Module.directive('dateTime', ['$compile', '$document', '$filter', 'dateTimeConfig', '$parse', 'datePickerUtils', function ($compile, $document, $filter, dateTimeConfig, $parse, datePickerUtils) { + var body = $document.find('body'); + var dateFilter = $filter('mFormat'); + + return { + require: 'ngModel', + scope: true, + link: function (scope, element, attrs, ngModel) { + var format = attrs.format || dateTimeConfig.format, + parentForm = element.inheritedData('$formController'), + views = $parse(attrs.views)(scope) || dateTimeConfig.views.concat(), + view = attrs.view || views[0], + index = views.indexOf(view), + dismiss = attrs.autoClose ? $parse(attrs.autoClose)(scope) : dateTimeConfig.autoClose, + picker = null, + pickerID = element[0].id, + position = attrs.position || dateTimeConfig.position, + container = null, + minDate = null, + minValid = null, + maxDate = null, + maxValid = null, + timezone = attrs.timezone || false, + eventIsForPicker = datePickerUtils.eventIsForPicker, + dateChange = null, + shownOnce = false, + template; + + if (index === -1) { + views.splice(index, 1); } - }; - }); - - Module.directive('dateTime', ['$compile', '$document', '$filter', 'dateTimeConfig', '$parse', 'datePickerUtils', function ($compile, $document, $filter, dateTimeConfig, $parse, datePickerUtils) { - var body = $document.find('body'); - var dateFilter = $filter('mFormat'); - - return { - require: 'ngModel', - scope: true, - link: function (scope, element, attrs, ngModel) { - var format = attrs.format || dateTimeConfig.format, - parentForm = element.inheritedData('$formController'), - views = $parse(attrs.views)(scope) || dateTimeConfig.views.concat(), - view = attrs.view || views[0], - index = views.indexOf(view), - dismiss = attrs.autoClose ? $parse(attrs.autoClose)(scope) : dateTimeConfig.autoClose, - picker = null, - pickerID = element[0].id, - position = attrs.position || dateTimeConfig.position, - container = null, - minDate = null, - minValid = null, - maxDate = null, - maxValid = null, - timezone = attrs.timezone || false, - eventIsForPicker = datePickerUtils.eventIsForPicker, - dateChange = null, - shownOnce = false, - template; - - if (index === -1) { - views.splice(index, 1); - } - views.unshift(view); + views.unshift(view); - function formatter(value) { + function formatter(value) { + if (value) { return dateFilter(value, format, timezone); } + } - function parser(viewValue) { - if (viewValue.length === format.length) { - return viewValue; - } - return (viewValue.length === 0) ? viewValue : undefined; + function parser(viewValue) { + if (!viewValue) { + return ''; } - - function setMin(date) { - minDate = date; - attrs.minDate = date ? date.format() : date; - minValid = moment.isMoment(date); + var parsed = moment(viewValue, format); + if (parsed.isValid()) { + return parsed; } + } - function setMax(date) { - maxDate = date; - attrs.maxDate = date ? date.format() : date; - maxValid = moment.isMoment(date); - } + function setMin(date) { + minDate = date; + attrs.minDate = date ? date.format() : date; + minValid = moment.isMoment(date); + } - ngModel.$formatters.push(formatter); - ngModel.$parsers.unshift(parser); + function setMax(date) { + maxDate = date; + attrs.maxDate = date ? date.format() : date; + maxValid = moment.isMoment(date); + } - if (angular.isDefined(attrs.minDate)) { - setMin(datePickerUtils.findParam(scope, attrs.minDate)); + ngModel.$formatters.push(formatter); + ngModel.$parsers.unshift(parser); - ngModel.$validators.min = function (value) { - //If we don't have a min / max value, then any value is valid. - return minValid ? moment.isMoment(value) && (minDate.isSame(value) || minDate.isBefore(value)) : true; - }; - } + if (angular.isDefined(attrs.minDate)) { + setMin(datePickerUtils.findParam(scope, attrs.minDate)); + + ngModel.$validators.min = function (value) { + //If we don't have a min / max value, then any value is valid. + return minValid ? moment.isMoment(value) && (minDate.isSame(value) || minDate.isBefore(value)) : true; + }; + } - if (angular.isDefined(attrs.maxDate)) { - setMax(datePickerUtils.findParam(scope, attrs.maxDate)); + if (angular.isDefined(attrs.maxDate)) { + setMax(datePickerUtils.findParam(scope, attrs.maxDate)); - ngModel.$validators.max = function (value) { - return maxValid ? moment.isMoment(value) && (maxDate.isSame(value) || maxDate.isAfter(value)) : true; - }; - } + ngModel.$validators.max = function (value) { + return maxValid ? moment.isMoment(value) && (maxDate.isSame(value) || maxDate.isAfter(value)) : true; + }; + } - if (angular.isDefined(attrs.dateChange)) { - dateChange = datePickerUtils.findFunction(scope, attrs.dateChange); - } + if (angular.isDefined(attrs.dateChange)) { + dateChange = datePickerUtils.findFunction(scope, attrs.dateChange); + } - function getTemplate() { - template = dateTimeConfig.template(attrs); - } + function getTemplate() { + template = dateTimeConfig.template(attrs); + } - function updateInput(event) { - event.stopPropagation(); - if (ngModel.$pristine) { - ngModel.$dirty = true; - ngModel.$pristine = false; - element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS); - if (parentForm) { - parentForm.$setDirty(); - } - ngModel.$render(); + function updateInput(event) { + event.stopPropagation(); + if (ngModel.$pristine) { + ngModel.$dirty = true; + ngModel.$pristine = false; + element.removeClass(PRISTINE_CLASS).addClass(DIRTY_CLASS); + if (parentForm) { + parentForm.$setDirty(); } + ngModel.$render(); } + } - function clear() { - if (picker) { - picker.remove(); - picker = null; - } - if (container) { - container.remove(); - container = null; - } + function clear() { + if (picker) { + picker.remove(); + picker = null; } - - if (pickerID) { - scope.$on('pickerUpdate', function (event, pickerIDs, data) { - if (eventIsForPicker(pickerIDs, pickerID)) { - if (picker) { - //Need to handle situation where the data changed but the picker is currently open. - //To handle this, we can create the inner picker with a random ID, then forward - //any events received to it. - } else { - var validateRequired = false; - if (angular.isDefined(data.minDate)) { - setMin(data.minDate); - validateRequired = true; - } - if (angular.isDefined(data.maxDate)) { - setMax(data.maxDate); - validateRequired = true; - } - - if (angular.isDefined(data.minView)) { - attrs.minView = data.minView; - } - if (angular.isDefined(data.maxView)) { - attrs.maxView = data.maxView; - } - attrs.view = data.view || attrs.view; - - if (validateRequired) { - ngModel.$validate(); - } - if (angular.isDefined(data.format)) { - format = attrs.format = data.format || dateTimeConfig.format; - ngModel.$modelValue = -1; //Triggers formatters. This value will be discarded. - } - getTemplate(); - } - } - }); + if (container) { + container.remove(); + container = null; } + } - function showPicker() { - if (picker) { - return; - } - // create picker element - picker = $compile(template)(scope); - scope.$digest(); - - //If the picker has already been shown before then we shouldn't be binding to events, as these events are already bound to in this scope. - if (!shownOnce) { - scope.$on('setDate', function (event, date, view) { - updateInput(event); - if (dateChange) { - dateChange(attrs.ngModel, date); + if (pickerID) { + scope.$on('pickerUpdate', function (event, pickerIDs, data) { + if (eventIsForPicker(pickerIDs, pickerID)) { + if (picker) { + //Need to handle situation where the data changed but the picker is currently open. + //To handle this, we can create the inner picker with a random ID, then forward + //any events received to it. + } else { + var validateRequired = false; + if (angular.isDefined(data.minDate)) { + setMin(data.minDate); + validateRequired = true; } - if (dismiss && views[views.length - 1] === view) { - clear(); + if (angular.isDefined(data.maxDate)) { + setMax(data.maxDate); + validateRequired = true; } - }); - scope.$on('hidePicker', function () { - element[0].blur(); - }); - - scope.$on('$destroy', clear); + if (angular.isDefined(data.minView)) { + attrs.minView = data.minView; + } + if (angular.isDefined(data.maxView)) { + attrs.maxView = data.maxView; + } + attrs.view = data.view || attrs.view; - shownOnce = true; + if (validateRequired) { + ngModel.$validate(); + } + if (angular.isDefined(data.format)) { + format = attrs.format = data.format || dateTimeConfig.format; + ngModel.$modelValue = -1; //Triggers formatters. This value will be discarded. + } + getTemplate(); + } } + }); + } + function showPicker() { + if (picker) { + return; + } + // create picker element + picker = $compile(template)(scope); + scope.$digest(); + + //If the picker has already been shown before then we shouldn't be binding to events, as these events are already bound to in this scope. + if (!shownOnce) { + scope.$on('setDate', function (event, date, view) { + updateInput(event); + if (dateChange) { + dateChange(attrs.ngModel, date); + } + if (dismiss && views[views.length - 1] === view) { + clear(); + } + }); - // move picker below input element - - if (position === 'absolute') { - var pos = element[0].getBoundingClientRect(); - // Support IE8 - var height = pos.height || element[0].offsetHeight; - picker.css({top: (pos.top + height) + 'px', left: pos.left + 'px', display: 'block', position: position}); - body.append(picker); - } else { - // relative - container = angular.element('
'); - element[0].parentElement.insertBefore(container[0], element[0]); - container.append(picker); - // this approach doesn't work - // element.before(picker); - picker.css({top: element[0].offsetHeight + 'px', display: 'block'}); - } - picker.bind('mousedown', function (evt) { - evt.preventDefault(); + scope.$on('hidePicker', function () { + element[0].blur(); }); + + scope.$on('$destroy', clear); + + shownOnce = true; } - element.bind('focus', showPicker); - element.bind('click', showPicker); - element.bind('blur', clear); - getTemplate(); + + // move picker below input element + + if (position === 'absolute') { + var pos = element[0].getBoundingClientRect(); + // Support IE8 + var height = pos.height || element[0].offsetHeight; + picker.css({top: (pos.top + height) + 'px', left: pos.left + 'px', display: 'block', position: position}); + body.append(picker); + } else { + // relative + container = angular.element('
'); + element[0].parentElement.insertBefore(container[0], element[0]); + container.append(picker); + // this approach doesn't work + // element.before(picker); + picker.css({top: element[0].offsetHeight + 'px', display: 'block'}); + } + picker.bind('mousedown', function (evt) { + evt.preventDefault(); + }); } - }; - }]); -//})); + + element.bind('focus', showPicker); + element.bind('blur', clear); + getTemplate(); + } + }; +}]); angular.module('datePicker').run(['$templateCache', function($templateCache) { $templateCache.put('templates/datepicker.html', @@ -1173,4 +1164,4 @@ $templateCache.put('templates/datepicker.html', ); }]); -})); +})); \ No newline at end of file diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index d2754ce..11e5461 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -!function(a,b){"use strict";var c;c="object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("angular"),require("moment")):"function"==typeof define&&define.amd?define(["angular","moment"],b):b(a.angular,a.moment)}(this,function(a,b){var c=a.module("datePicker",[]);c.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),c.filter("mFormat",function(){return function(a,c,d){return b.isMoment(a)?d?b.tz(a,d).format(c):a.format(c):b(a).format(c)}}),c.directive("datePicker",["datePickerConfig","datePickerUtils",function(c,d){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(e,f,g,h){function i(){e.views=c.views.concat(),e.view=g.view||c.view,e.views=e.views.slice(e.views.indexOf(g.maxView||"year"),e.views.indexOf(g.minView||"minutes")+1),(1===e.views.length||-1===e.views.indexOf(e.view))&&(e.view=e.views[0])}function j(a){return d.getDate(e,g,a)}function k(){var a=e.view;d.setParams(t,E),e.model&&!s&&(e.date=u(e.model),s=!1);var b=e.date;switch(a){case"year":e.years=d.getVisibleYears(b);break;case"month":e.months=d.getVisibleMonths(b);break;case"date":e.weekdays=e.weekdays||d.getDaysOfWeek(),e.weeks=d.getVisibleWeeks(b);break;case"hours":e.hours=d.getVisibleHours(b);break;case"minutes":e.minutes=d.getVisibleMinutes(b,w)}n()}function l(){return"date"!==e.view?e.view:e.date?e.date.month():null}var m,n,o,p,q,r,s=!1,t=e.tz=g.timezone,u=d.createMoment,v=d.eventIsForPicker,w=parseInt(g.step||c.step,10),x=!!g.partial,y=j("minDate"),z=j("maxDate"),A=f[0].id,B=e.now=u(),C=e.date=u(e.model||B),D="true"===g.autoClose,E=g.firstDay&&g.firstDay>=0&&g.firstDay<=6?parseInt(g.firstDay,10):b().weekday(0).day();d.setParams(t,E),e.model||C.minute(Math.ceil(C.minute()/w)*w).second(0),e.template=g.template||c.template,e.watchDirectChanges=void 0!==g.watchDirectChanges,e.callbackOnSetDate=g.dateChange?d.findFunction(e,g.dateChange):void 0,i(),e.setView=function(a){-1!==e.views.indexOf(a)&&(e.view=a)},e.selectDate=function(a){if(g.disabled)return!1;if(o(e.date,a)&&(a=e.date),a=p(a),!a)return!1;e.date=a;var b=e.views[e.views.indexOf(e.view)+1];(!b||x||e.model)&&m(a),b?e.setView(b):D?(f.addClass("hidden"),e.$emit("hidePicker")):n()},m=function(a){a&&(e.model=a,h&&h.$setViewValue(a)),e.$emit("setDate",e.model,e.view),e.callbackOnSetDate&&e.callbackOnSetDate(g.datePicker,e.date)},e.$watch(l,k),e.watchDirectChanges&&e.$watch("model",function(){s=!1,k()}),n=function(){var a,b,f=e.view,g=e.date,h=[],i="";if(d.setParams(t,E),"date"===f){var j,k=e.weeks;for(a=0;ad;d+=b)c=e(f,g,h,i-j,d),k.push(c);return k},getVisibleWeeks:function(a){a=b(a);var c=a.year(),e=a.month();a.date(1);var f=a.day();a.date(d-(f+(d>=f?6:-1)));for(var g=[];g.length<6&&!(a.year()===c&&a.month()>e);)g.push(this.getDaysOfWeek(a)),a.add(7,"d");return g},getVisibleYears:function(a){var c=b(a),d=c.year();c.year(d-d%10),d=c.year();for(var f,g,h=c.utcOffset()/60,i=[],j=0;12>j;j++)f=e(d,0,1,0-h),g=f.utcOffset()/60,g!==h&&(f=e(d,0,1,0-g),h=g),i.push(f),d++;return i},getDaysOfWeek:function(a){a=a?a:c?b.tz(c).day(d):b().day(d);for(var f,g,h=a.year(),i=a.month(),j=a.date(),k=[],l=a.utcOffset()/60,m=0;7>m;m++)f=e(h,i,j,0-l,0,!1),g=f.utcOffset()/60,g!==l&&(f=e(h,i,j,0-g,0,!1)),k.push(f),j++;return k},getVisibleMonths:function(a){for(var b,c,d=a.year(),f=a.utcOffset()/60,g=[],h=0;12>h;h++)b=e(d,h,1,0-f,0,!1),c=b.utcOffset()/60,c!==f&&(b=e(d,h,1,0-c,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,c,d,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;24>b;b++)c=e(f,g,h,b-j,0,!1),d=c.utcOffset()/60,d!==j&&(c=e(f,g,h,b-d,0,!1)),i.push(c);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a,b){c=a,d=b},scopeSearch:function(a,b,c){var d,e,f=a,g=b.split("."),h=g.length;do{for(d=f=f.$parent,e=0;h>e;e++){d=d[g[e]]}if(d&&c(d))return d}while(f.$parent);return!1},findFunction:function(b,c){return this.scopeSearch(b,c,function(b){return a.isFunction(b)})},findParam:function(a,b){return this.scopeSearch(a,b,function(){return!0})},createMoment:function(a){return c?b.tz(a,c):b.isMoment(a)?b.unix(a.unix()):b(a)},getDate:function(a,b,c){var d=!1;return b[c]&&(d=this.createMoment(b[c]),d.isValid()||(d=this.findParam(a,b[c]),d&&(d=this.createMoment(d)))),d},eventIsForPicker:function(b,c){return a.isArray(b)&&b.indexOf(c)>-1||b===c}}});var c=a.module("datePicker");c.directive("dateRange",["$compile","datePickerUtils","dateTimeConfig",function(c,d,e){function f(c,d,f,g,h){return e.template(a.extend(c,{ngModel:f,minDate:g&&b.isMoment(g)?g.format():!1,maxDate:h&&b.isMoment(h)?h.format():!1}),d)}function g(){return"picker"+Math.random().toString().substr(2)}return{scope:{start:"=",end:"="},link:function(b,e,h){function i(a){b.$broadcast("pickerUpdate",m[0],{maxDate:a})}function j(a){b.$broadcast("pickerUpdate",m[1],{minDate:a})}var k=null,l=e[0].id,m=[g(),g()],n=d.createMoment,o=d.eventIsForPicker;b.dateChange=function(a,b){k&&k(a,b)},l&&b.$on("pickerUpdate",function(a,c,d){o(c,l)&&b.$broadcast("pickerUpdate",m,d)}),d.setParams(h.timezone),b.start=n(b.start),b.end=n(b.end),b.$watchGroup(["start","end"],function(a){j(a[0]),i(a[1])}),a.isDefined(h.dateChange)&&(k=d.findFunction(b,h.dateChange)),h.onSetDate="dateChange";var p='
'+f(h,m[0],"start",!1,b.end)+''+f(h,m[1],"end",b.start,!1)+"
",q=c(p)(b);e.append(q)}}}]);var d="ng-pristine",e="ng-dirty",c=a.module("datePicker");c.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),c.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),c.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(c,f,g,h,i,j){var k=f.find("body"),l=g("mFormat");return{require:"ngModel",scope:!0,link:function(f,g,m,n){function o(a){return l(a,x,L)}function p(a){return a.length===x.length?a:void 0}function q(a){H=a,m.minDate=a?a.format():a,I=b.isMoment(a)}function r(a){J=a,m.maxDate=a?a.format():a,K=b.isMoment(a)}function s(){w=h.template(m)}function t(a){a.stopPropagation(),n.$pristine&&(n.$dirty=!0,n.$pristine=!1,g.removeClass(d).addClass(e),y&&y.$setDirty(),n.$render())}function u(){D&&(D.remove(),D=null),G&&(G.remove(),G=null)}function v(){if(!D){if(D=c(w)(f),f.$digest(),O||(f.$on("setDate",function(a,b,c){t(a),N&&N(m.ngModel,b),C&&z[z.length-1]===c&&u()}),f.$on("hidePicker",function(){g.triggerHandler("blur")}),f.$on("$destroy",u),O=!0),"absolute"===F){var b=g[0].getBoundingClientRect(),d=b.height||g[0].offsetHeight;D.css({top:b.top+d+"px",left:b.left+"px",display:"block",position:F}),k.append(D)}else G=a.element("
"),g[0].parentElement.insertBefore(G[0],g[0]),G.append(D),D.css({top:g[0].offsetHeight+"px",display:"block"});D.bind("mousedown",function(a){a.preventDefault()})}}var w,x=m.format||h.format,y=g.inheritedData("$formController"),z=i(m.views)(f)||h.views.concat(),A=m.view||z[0],B=z.indexOf(A),C=m.autoClose?i(m.autoClose)(f):h.autoClose,D=null,E=g[0].id,F=m.position||h.position,G=null,H=null,I=null,J=null,K=null,L=m.timezone||!1,M=j.eventIsForPicker,N=null,O=!1;-1===B&&z.splice(B,1),z.unshift(A),n.$formatters.push(o),n.$parsers.unshift(p),a.isDefined(m.minDate)&&(q(j.findParam(f,m.minDate)),n.$validators.min=function(a){return I?b.isMoment(a)&&(H.isSame(a)||H.isBefore(a)):!0}),a.isDefined(m.maxDate)&&(r(j.findParam(f,m.maxDate)),n.$validators.max=function(a){return K?b.isMoment(a)&&(J.isSame(a)||J.isAfter(a)):!0}),a.isDefined(m.dateChange)&&(N=j.findFunction(f,m.dateChange)),E&&f.$on("pickerUpdate",function(b,c,d){if(M(c,E))if(D);else{var e=!1;a.isDefined(d.minDate)&&(q(d.minDate),e=!0),a.isDefined(d.maxDate)&&(r(d.maxDate),e=!0),a.isDefined(d.minView)&&(m.minView=d.minView),a.isDefined(d.maxView)&&(m.maxView=d.maxView),m.view=d.view||m.view,e&&n.$validate(),a.isDefined(d.format)&&(x=m.format=d.format||h.format,n.$modelValue=-1),s()}}),g.bind("focus",v),g.bind("blur",u),s()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}); \ No newline at end of file +!function(a,b){"use strict";var c;c="object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("angular"),require("moment")):"function"==typeof define&&define.amd?define(["angular","moment"],b):b(a.angular,a.moment)}(this,function(a,b){var c=a.module("datePicker",[]);c.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),c.filter("mFormat",function(){return function(a,c,d){return b.isMoment(a)?d?b.tz(a,d).format(c):a.format(c):b(a).format(c)}}),c.directive("datePicker",["datePickerConfig","datePickerUtils",function(c,d){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(e,f,g,h){function i(){e.views=c.views.concat(),e.view=g.view||c.view,e.views=e.views.slice(e.views.indexOf(g.maxView||"year"),e.views.indexOf(g.minView||"minutes")+1),1!==e.views.length&&e.views.indexOf(e.view)!==-1||(e.view=e.views[0])}function j(a){return d.getDate(e,g,a)}function k(){var a=e.view;d.setParams(t,E),e.model&&!s&&(e.date=u(e.model),s=!1);var b=e.date;switch(a){case"year":e.years=d.getVisibleYears(b);break;case"month":e.months=d.getVisibleMonths(b);break;case"date":e.weekdays=e.weekdays||d.getDaysOfWeek(),e.weeks=d.getVisibleWeeks(b);break;case"hours":e.hours=d.getVisibleHours(b);break;case"minutes":e.minutes=d.getVisibleMinutes(b,w)}n()}function l(){return"date"!==e.view?e.view:e.date?e.date.month():null}var m,n,o,p,q,r,s=!1,t=e.tz=g.timezone,u=d.createMoment,v=d.eventIsForPicker,w=parseInt(g.step||c.step,10),x=!!g.partial,y=j("minDate"),z=j("maxDate"),A=f[0].id,B=e.now=u(),C=e.date=u(e.model||B),D="true"===g.autoClose,E=g.firstDay&&g.firstDay>=0&&g.firstDay<=6?parseInt(g.firstDay,10):b().weekday(0).day();d.setParams(t,E),e.model||C.minute(Math.ceil(C.minute()/w)*w).second(0),e.template=g.template||c.template,e.watchDirectChanges=void 0!==g.watchDirectChanges,e.callbackOnSetDate=g.dateChange?d.findFunction(e,g.dateChange):void 0,i(),e.setView=function(a){e.views.indexOf(a)!==-1&&(e.view=a)},e.selectDate=function(a){if(g.disabled)return!1;if(o(e.date,a)&&(a=e.date),a=p(a),!a)return!1;e.date=a;var b=e.views[e.views.indexOf(e.view)+1];(!b||x||e.model)&&m(a),b?e.setView(b):D?(f.addClass("hidden"),e.$emit("hidePicker")):n()},m=function(a){a&&(e.model=a,h&&h.$setViewValue(a)),e.$emit("setDate",e.model,e.view),e.callbackOnSetDate&&e.callbackOnSetDate(g.datePicker,e.date)},e.$watch(l,k),e.watchDirectChanges&&e.$watch("model",function(){s=!1,k()}),n=function(){var a,b,f=e.view,g=e.date,h=[],i="";if(d.setParams(t,E),"date"===f){var j,k=e.weeks;for(a=0;a=f?6:-1)));for(var g=[];g.length<6&&!(a.year()===c&&a.month()>e);)g.push(this.getDaysOfWeek(a)),a.add(7,"d");return g},getVisibleYears:function(a){var c=b(a),d=c.year();c.year(d-d%10),d=c.year();for(var f,g,h=c.utcOffset()/60,i=[],j=0;j<12;j++)f=e(d,0,1,0-h),g=f.utcOffset()/60,g!==h&&(f=e(d,0,1,0-g),h=g),i.push(f),d++;return i},getDaysOfWeek:function(a){a=a?a:c?b.tz(c).day(d):b().day(d);for(var f,g,h=a.year(),i=a.month(),j=a.date(),k=[],l=a.utcOffset()/60,m=0;m<7;m++)f=e(h,i,j,0-l,0,!1),g=f.utcOffset()/60,g!==l&&(f=e(h,i,j,0-g,0,!1)),k.push(f),j++;return k},getVisibleMonths:function(a){for(var b,c,d=a.year(),f=a.utcOffset()/60,g=[],h=0;h<12;h++)b=e(d,h,1,0-f,0,!1),c=b.utcOffset()/60,c!==f&&(b=e(d,h,1,0-c,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,c,d,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;b<24;b++)c=e(f,g,h,b-j,0,!1),d=c.utcOffset()/60,d!==j&&(c=e(f,g,h,b-d,0,!1)),i.push(c);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a,b){c=a,d=b},scopeSearch:function(a,b,c){var d,e,f,g=a,h=b.split("."),i=h.length;do{for(f=d=g=g.$parent,e=0;e
'+f(h,m[1],"end",b.start,!1)+"
",q=c(p)(b);e.append(q)}}}]);var d="ng-pristine",e="ng-dirty",c=a.module("datePicker");c.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),c.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),c.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(c,f,g,h,i,j){var k=f.find("body"),l=g("mFormat");return{require:"ngModel",scope:!0,link:function(f,g,m,n){function o(a){if(a)return l(a,x,L)}function p(a){if(!a)return"";var c=b(a,x);return c.isValid()?c:void 0}function q(a){H=a,m.minDate=a?a.format():a,I=b.isMoment(a)}function r(a){J=a,m.maxDate=a?a.format():a,K=b.isMoment(a)}function s(){w=h.template(m)}function t(a){a.stopPropagation(),n.$pristine&&(n.$dirty=!0,n.$pristine=!1,g.removeClass(d).addClass(e),y&&y.$setDirty(),n.$render())}function u(){D&&(D.remove(),D=null),G&&(G.remove(),G=null)}function v(){if(!D){if(D=c(w)(f),f.$digest(),O||(f.$on("setDate",function(a,b,c){t(a),N&&N(m.ngModel,b),C&&z[z.length-1]===c&&u()}),f.$on("hidePicker",function(){g[0].blur()}),f.$on("$destroy",u),O=!0),"absolute"===F){var b=g[0].getBoundingClientRect(),d=b.height||g[0].offsetHeight;D.css({top:b.top+d+"px",left:b.left+"px",display:"block",position:F}),k.append(D)}else G=a.element("
"),g[0].parentElement.insertBefore(G[0],g[0]),G.append(D),D.css({top:g[0].offsetHeight+"px",display:"block"});D.bind("mousedown",function(a){a.preventDefault()})}}var w,x=m.format||h.format,y=g.inheritedData("$formController"),z=i(m.views)(f)||h.views.concat(),A=m.view||z[0],B=z.indexOf(A),C=m.autoClose?i(m.autoClose)(f):h.autoClose,D=null,E=g[0].id,F=m.position||h.position,G=null,H=null,I=null,J=null,K=null,L=m.timezone||!1,M=j.eventIsForPicker,N=null,O=!1;B===-1&&z.splice(B,1),z.unshift(A),n.$formatters.push(o),n.$parsers.unshift(p),a.isDefined(m.minDate)&&(q(j.findParam(f,m.minDate)),n.$validators.min=function(a){return!I||b.isMoment(a)&&(H.isSame(a)||H.isBefore(a))}),a.isDefined(m.maxDate)&&(r(j.findParam(f,m.maxDate)),n.$validators.max=function(a){return!K||b.isMoment(a)&&(J.isSame(a)||J.isAfter(a))}),a.isDefined(m.dateChange)&&(N=j.findFunction(f,m.dateChange)),E&&f.$on("pickerUpdate",function(b,c,d){if(M(c,E))if(D);else{var e=!1;a.isDefined(d.minDate)&&(q(d.minDate),e=!0),a.isDefined(d.maxDate)&&(r(d.maxDate),e=!0),a.isDefined(d.minView)&&(m.minView=d.minView),a.isDefined(d.maxView)&&(m.maxView=d.maxView),m.view=d.view||m.view,e&&n.$validate(),a.isDefined(d.format)&&(x=m.format=d.format||h.format,n.$modelValue=-1),s()}}),g.bind("focus",v),g.bind("blur",u),s()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}); \ No newline at end of file From 477fee660398c2983c7f7795faea32f48a217c61 Mon Sep 17 00:00:00 2001 From: Dan Talash Date: Thu, 23 Feb 2017 10:14:40 -0800 Subject: [PATCH 21/22] Update demo url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ba3f56..a142f90 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Add the following module to your page : `datePicker` ## Usage Example -[Live demo](https://rawgithub.com/DanTalash/angular-datepicker/master/app/index.html) +[Live demo](https://rawgithub.com/g00fy-/angular-datepicker/master/app/index.html) ## New features From 0aa2007c3613ed01cdb1b599ca34f855e75a0c26 Mon Sep 17 00:00:00 2001 From: Dan Talash Date: Sat, 25 Feb 2017 09:09:07 -0800 Subject: [PATCH 22/22] * Fixing issue with formatting non-moment dates when there is a non-local timezone set. * Update combined files. --- app/scripts/datePicker.js | 11 ++++++++--- dist/angular-datepicker.js | 11 ++++++++--- dist/angular-datepicker.min.js | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/scripts/datePicker.js b/app/scripts/datePicker.js index b73f80c..3f2f1b5 100644 --- a/app/scripts/datePicker.js +++ b/app/scripts/datePicker.js @@ -24,10 +24,15 @@ Module.constant('datePickerConfig', { //Moment format filter. Module.filter('mFormat', function () { return function (m, format, tz) { - if (!(moment.isMoment(m))) { - return moment(m).format(format); + if (!m) { + return ''; + } + + if (tz) { + return moment.tz(m, tz).format(format); + } else { + return moment.isMoment(m) ? m.format(format) : moment(m).format(format); } - return tz ? moment.tz(m, tz).format(format) : m.format(format); }; }); diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js index 1ef70f7..e2441da 100644 --- a/dist/angular-datepicker.js +++ b/dist/angular-datepicker.js @@ -24,10 +24,15 @@ Module.constant('datePickerConfig', { //Moment format filter. Module.filter('mFormat', function () { return function (m, format, tz) { - if (!(moment.isMoment(m))) { - return moment(m).format(format); + if (!m) { + return ''; + } + + if (tz) { + return moment.tz(m, tz).format(format); + } else { + return moment.isMoment(m) ? m.format(format) : moment(m).format(format); } - return tz ? moment.tz(m, tz).format(format) : m.format(format); }; }); diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js index 11e5461..86ca258 100644 --- a/dist/angular-datepicker.min.js +++ b/dist/angular-datepicker.min.js @@ -1 +1 @@ -!function(a,b){"use strict";var c;c="object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("angular"),require("moment")):"function"==typeof define&&define.amd?define(["angular","moment"],b):b(a.angular,a.moment)}(this,function(a,b){var c=a.module("datePicker",[]);c.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),c.filter("mFormat",function(){return function(a,c,d){return b.isMoment(a)?d?b.tz(a,d).format(c):a.format(c):b(a).format(c)}}),c.directive("datePicker",["datePickerConfig","datePickerUtils",function(c,d){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(e,f,g,h){function i(){e.views=c.views.concat(),e.view=g.view||c.view,e.views=e.views.slice(e.views.indexOf(g.maxView||"year"),e.views.indexOf(g.minView||"minutes")+1),1!==e.views.length&&e.views.indexOf(e.view)!==-1||(e.view=e.views[0])}function j(a){return d.getDate(e,g,a)}function k(){var a=e.view;d.setParams(t,E),e.model&&!s&&(e.date=u(e.model),s=!1);var b=e.date;switch(a){case"year":e.years=d.getVisibleYears(b);break;case"month":e.months=d.getVisibleMonths(b);break;case"date":e.weekdays=e.weekdays||d.getDaysOfWeek(),e.weeks=d.getVisibleWeeks(b);break;case"hours":e.hours=d.getVisibleHours(b);break;case"minutes":e.minutes=d.getVisibleMinutes(b,w)}n()}function l(){return"date"!==e.view?e.view:e.date?e.date.month():null}var m,n,o,p,q,r,s=!1,t=e.tz=g.timezone,u=d.createMoment,v=d.eventIsForPicker,w=parseInt(g.step||c.step,10),x=!!g.partial,y=j("minDate"),z=j("maxDate"),A=f[0].id,B=e.now=u(),C=e.date=u(e.model||B),D="true"===g.autoClose,E=g.firstDay&&g.firstDay>=0&&g.firstDay<=6?parseInt(g.firstDay,10):b().weekday(0).day();d.setParams(t,E),e.model||C.minute(Math.ceil(C.minute()/w)*w).second(0),e.template=g.template||c.template,e.watchDirectChanges=void 0!==g.watchDirectChanges,e.callbackOnSetDate=g.dateChange?d.findFunction(e,g.dateChange):void 0,i(),e.setView=function(a){e.views.indexOf(a)!==-1&&(e.view=a)},e.selectDate=function(a){if(g.disabled)return!1;if(o(e.date,a)&&(a=e.date),a=p(a),!a)return!1;e.date=a;var b=e.views[e.views.indexOf(e.view)+1];(!b||x||e.model)&&m(a),b?e.setView(b):D?(f.addClass("hidden"),e.$emit("hidePicker")):n()},m=function(a){a&&(e.model=a,h&&h.$setViewValue(a)),e.$emit("setDate",e.model,e.view),e.callbackOnSetDate&&e.callbackOnSetDate(g.datePicker,e.date)},e.$watch(l,k),e.watchDirectChanges&&e.$watch("model",function(){s=!1,k()}),n=function(){var a,b,f=e.view,g=e.date,h=[],i="";if(d.setParams(t,E),"date"===f){var j,k=e.weeks;for(a=0;a=f?6:-1)));for(var g=[];g.length<6&&!(a.year()===c&&a.month()>e);)g.push(this.getDaysOfWeek(a)),a.add(7,"d");return g},getVisibleYears:function(a){var c=b(a),d=c.year();c.year(d-d%10),d=c.year();for(var f,g,h=c.utcOffset()/60,i=[],j=0;j<12;j++)f=e(d,0,1,0-h),g=f.utcOffset()/60,g!==h&&(f=e(d,0,1,0-g),h=g),i.push(f),d++;return i},getDaysOfWeek:function(a){a=a?a:c?b.tz(c).day(d):b().day(d);for(var f,g,h=a.year(),i=a.month(),j=a.date(),k=[],l=a.utcOffset()/60,m=0;m<7;m++)f=e(h,i,j,0-l,0,!1),g=f.utcOffset()/60,g!==l&&(f=e(h,i,j,0-g,0,!1)),k.push(f),j++;return k},getVisibleMonths:function(a){for(var b,c,d=a.year(),f=a.utcOffset()/60,g=[],h=0;h<12;h++)b=e(d,h,1,0-f,0,!1),c=b.utcOffset()/60,c!==f&&(b=e(d,h,1,0-c,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,c,d,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;b<24;b++)c=e(f,g,h,b-j,0,!1),d=c.utcOffset()/60,d!==j&&(c=e(f,g,h,b-d,0,!1)),i.push(c);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a,b){c=a,d=b},scopeSearch:function(a,b,c){var d,e,f,g=a,h=b.split("."),i=h.length;do{for(f=d=g=g.$parent,e=0;e
'+f(h,m[1],"end",b.start,!1)+"
",q=c(p)(b);e.append(q)}}}]);var d="ng-pristine",e="ng-dirty",c=a.module("datePicker");c.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),c.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),c.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(c,f,g,h,i,j){var k=f.find("body"),l=g("mFormat");return{require:"ngModel",scope:!0,link:function(f,g,m,n){function o(a){if(a)return l(a,x,L)}function p(a){if(!a)return"";var c=b(a,x);return c.isValid()?c:void 0}function q(a){H=a,m.minDate=a?a.format():a,I=b.isMoment(a)}function r(a){J=a,m.maxDate=a?a.format():a,K=b.isMoment(a)}function s(){w=h.template(m)}function t(a){a.stopPropagation(),n.$pristine&&(n.$dirty=!0,n.$pristine=!1,g.removeClass(d).addClass(e),y&&y.$setDirty(),n.$render())}function u(){D&&(D.remove(),D=null),G&&(G.remove(),G=null)}function v(){if(!D){if(D=c(w)(f),f.$digest(),O||(f.$on("setDate",function(a,b,c){t(a),N&&N(m.ngModel,b),C&&z[z.length-1]===c&&u()}),f.$on("hidePicker",function(){g[0].blur()}),f.$on("$destroy",u),O=!0),"absolute"===F){var b=g[0].getBoundingClientRect(),d=b.height||g[0].offsetHeight;D.css({top:b.top+d+"px",left:b.left+"px",display:"block",position:F}),k.append(D)}else G=a.element("
"),g[0].parentElement.insertBefore(G[0],g[0]),G.append(D),D.css({top:g[0].offsetHeight+"px",display:"block"});D.bind("mousedown",function(a){a.preventDefault()})}}var w,x=m.format||h.format,y=g.inheritedData("$formController"),z=i(m.views)(f)||h.views.concat(),A=m.view||z[0],B=z.indexOf(A),C=m.autoClose?i(m.autoClose)(f):h.autoClose,D=null,E=g[0].id,F=m.position||h.position,G=null,H=null,I=null,J=null,K=null,L=m.timezone||!1,M=j.eventIsForPicker,N=null,O=!1;B===-1&&z.splice(B,1),z.unshift(A),n.$formatters.push(o),n.$parsers.unshift(p),a.isDefined(m.minDate)&&(q(j.findParam(f,m.minDate)),n.$validators.min=function(a){return!I||b.isMoment(a)&&(H.isSame(a)||H.isBefore(a))}),a.isDefined(m.maxDate)&&(r(j.findParam(f,m.maxDate)),n.$validators.max=function(a){return!K||b.isMoment(a)&&(J.isSame(a)||J.isAfter(a))}),a.isDefined(m.dateChange)&&(N=j.findFunction(f,m.dateChange)),E&&f.$on("pickerUpdate",function(b,c,d){if(M(c,E))if(D);else{var e=!1;a.isDefined(d.minDate)&&(q(d.minDate),e=!0),a.isDefined(d.maxDate)&&(r(d.maxDate),e=!0),a.isDefined(d.minView)&&(m.minView=d.minView),a.isDefined(d.maxView)&&(m.maxView=d.maxView),m.view=d.view||m.view,e&&n.$validate(),a.isDefined(d.format)&&(x=m.format=d.format||h.format,n.$modelValue=-1),s()}}),g.bind("focus",v),g.bind("blur",u),s()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}); \ No newline at end of file +!function(a,b){"use strict";var c;c="object"==typeof exports&&"undefined"!=typeof module?module.exports=b(require("angular"),require("moment")):"function"==typeof define&&define.amd?define(["angular","moment"],b):b(a.angular,a.moment)}(this,function(a,b){var c=a.module("datePicker",[]);c.constant("datePickerConfig",{template:"templates/datepicker.html",view:"month",views:["year","month","date","hours","minutes"],momentNames:{year:"year",month:"month",date:"day",hours:"hours",minutes:"minutes"},viewConfig:{year:["years","isSameYear"],month:["months","isSameMonth"],hours:["hours","isSameHour"],minutes:["minutes","isSameMinutes"]},step:5}),c.filter("mFormat",function(){return function(a,c,d){return a?d?b.tz(a,d).format(c):b.isMoment(a)?a.format(c):b(a).format(c):""}}),c.directive("datePicker",["datePickerConfig","datePickerUtils",function(c,d){return{require:"?ngModel",template:'
',scope:{model:"=datePicker",after:"=?",before:"=?"},link:function(e,f,g,h){function i(){e.views=c.views.concat(),e.view=g.view||c.view,e.views=e.views.slice(e.views.indexOf(g.maxView||"year"),e.views.indexOf(g.minView||"minutes")+1),1!==e.views.length&&e.views.indexOf(e.view)!==-1||(e.view=e.views[0])}function j(a){return d.getDate(e,g,a)}function k(){var a=e.view;d.setParams(t,E),e.model&&!s&&(e.date=u(e.model),s=!1);var b=e.date;switch(a){case"year":e.years=d.getVisibleYears(b);break;case"month":e.months=d.getVisibleMonths(b);break;case"date":e.weekdays=e.weekdays||d.getDaysOfWeek(),e.weeks=d.getVisibleWeeks(b);break;case"hours":e.hours=d.getVisibleHours(b);break;case"minutes":e.minutes=d.getVisibleMinutes(b,w)}n()}function l(){return"date"!==e.view?e.view:e.date?e.date.month():null}var m,n,o,p,q,r,s=!1,t=e.tz=g.timezone,u=d.createMoment,v=d.eventIsForPicker,w=parseInt(g.step||c.step,10),x=!!g.partial,y=j("minDate"),z=j("maxDate"),A=f[0].id,B=e.now=u(),C=e.date=u(e.model||B),D="true"===g.autoClose,E=g.firstDay&&g.firstDay>=0&&g.firstDay<=6?parseInt(g.firstDay,10):b().weekday(0).day();d.setParams(t,E),e.model||C.minute(Math.ceil(C.minute()/w)*w).second(0),e.template=g.template||c.template,e.watchDirectChanges=void 0!==g.watchDirectChanges,e.callbackOnSetDate=g.dateChange?d.findFunction(e,g.dateChange):void 0,i(),e.setView=function(a){e.views.indexOf(a)!==-1&&(e.view=a)},e.selectDate=function(a){if(g.disabled)return!1;if(o(e.date,a)&&(a=e.date),a=p(a),!a)return!1;e.date=a;var b=e.views[e.views.indexOf(e.view)+1];(!b||x||e.model)&&m(a),b?e.setView(b):D?(f.addClass("hidden"),e.$emit("hidePicker")):n()},m=function(a){a&&(e.model=a,h&&h.$setViewValue(a)),e.$emit("setDate",e.model,e.view),e.callbackOnSetDate&&e.callbackOnSetDate(g.datePicker,e.date)},e.$watch(l,k),e.watchDirectChanges&&e.$watch("model",function(){s=!1,k()}),n=function(){var a,b,f=e.view,g=e.date,h=[],i="";if(d.setParams(t,E),"date"===f){var j,k=e.weeks;for(a=0;a=f?6:-1)));for(var g=[];g.length<6&&!(a.year()===c&&a.month()>e);)g.push(this.getDaysOfWeek(a)),a.add(7,"d");return g},getVisibleYears:function(a){var c=b(a),d=c.year();c.year(d-d%10),d=c.year();for(var f,g,h=c.utcOffset()/60,i=[],j=0;j<12;j++)f=e(d,0,1,0-h),g=f.utcOffset()/60,g!==h&&(f=e(d,0,1,0-g),h=g),i.push(f),d++;return i},getDaysOfWeek:function(a){a=a?a:c?b.tz(c).day(d):b().day(d);for(var f,g,h=a.year(),i=a.month(),j=a.date(),k=[],l=a.utcOffset()/60,m=0;m<7;m++)f=e(h,i,j,0-l,0,!1),g=f.utcOffset()/60,g!==l&&(f=e(h,i,j,0-g,0,!1)),k.push(f),j++;return k},getVisibleMonths:function(a){for(var b,c,d=a.year(),f=a.utcOffset()/60,g=[],h=0;h<12;h++)b=e(d,h,1,0-f,0,!1),c=b.utcOffset()/60,c!==f&&(b=e(d,h,1,0-c,0,!1)),g.push(b);return g},getVisibleHours:function(a){var b,c,d,f=a.year(),g=a.month(),h=a.date(),i=[],j=a.utcOffset()/60;for(b=0;b<24;b++)c=e(f,g,h,b-j,0,!1),d=c.utcOffset()/60,d!==j&&(c=e(f,g,h,b-d,0,!1)),i.push(c);return i},isAfter:function(a,b){return a&&a.unix()>=b.unix()},isBefore:function(a,b){return a.unix()<=b.unix()},isSameYear:function(a,b){return a&&a.year()===b.year()},isSameMonth:function(a,b){return this.isSameYear(a,b)&&a.month()===b.month()},isSameDay:function(a,b){return this.isSameMonth(a,b)&&a.date()===b.date()},isSameHour:function(a,b){return this.isSameDay(a,b)&&a.hours()===b.hours()},isSameMinutes:function(a,b){return this.isSameHour(a,b)&&a.minutes()===b.minutes()},setParams:function(a,b){c=a,d=b},scopeSearch:function(a,b,c){var d,e,f,g=a,h=b.split("."),i=h.length;do{for(f=d=g=g.$parent,e=0;e
'+f(h,m[1],"end",b.start,!1)+"
",q=c(p)(b);e.append(q)}}}]);var d="ng-pristine",e="ng-dirty",c=a.module("datePicker");c.constant("dateTimeConfig",{template:function(a,b){return"
'},format:"YYYY-MM-DD HH:mm",views:["date","year","month","hours","minutes"],autoClose:!1,position:"relative"}),c.directive("dateTimeAppend",function(){return{link:function(a,b){b.bind("click",function(){b.find("input")[0].focus()})}}}),c.directive("dateTime",["$compile","$document","$filter","dateTimeConfig","$parse","datePickerUtils",function(c,f,g,h,i,j){var k=f.find("body"),l=g("mFormat");return{require:"ngModel",scope:!0,link:function(f,g,m,n){function o(a){if(a)return l(a,x,L)}function p(a){if(!a)return"";var c=b(a,x);return c.isValid()?c:void 0}function q(a){H=a,m.minDate=a?a.format():a,I=b.isMoment(a)}function r(a){J=a,m.maxDate=a?a.format():a,K=b.isMoment(a)}function s(){w=h.template(m)}function t(a){a.stopPropagation(),n.$pristine&&(n.$dirty=!0,n.$pristine=!1,g.removeClass(d).addClass(e),y&&y.$setDirty(),n.$render())}function u(){D&&(D.remove(),D=null),G&&(G.remove(),G=null)}function v(){if(!D){if(D=c(w)(f),f.$digest(),O||(f.$on("setDate",function(a,b,c){t(a),N&&N(m.ngModel,b),C&&z[z.length-1]===c&&u()}),f.$on("hidePicker",function(){g[0].blur()}),f.$on("$destroy",u),O=!0),"absolute"===F){var b=g[0].getBoundingClientRect(),d=b.height||g[0].offsetHeight;D.css({top:b.top+d+"px",left:b.left+"px",display:"block",position:F}),k.append(D)}else G=a.element("
"),g[0].parentElement.insertBefore(G[0],g[0]),G.append(D),D.css({top:g[0].offsetHeight+"px",display:"block"});D.bind("mousedown",function(a){a.preventDefault()})}}var w,x=m.format||h.format,y=g.inheritedData("$formController"),z=i(m.views)(f)||h.views.concat(),A=m.view||z[0],B=z.indexOf(A),C=m.autoClose?i(m.autoClose)(f):h.autoClose,D=null,E=g[0].id,F=m.position||h.position,G=null,H=null,I=null,J=null,K=null,L=m.timezone||!1,M=j.eventIsForPicker,N=null,O=!1;B===-1&&z.splice(B,1),z.unshift(A),n.$formatters.push(o),n.$parsers.unshift(p),a.isDefined(m.minDate)&&(q(j.findParam(f,m.minDate)),n.$validators.min=function(a){return!I||b.isMoment(a)&&(H.isSame(a)||H.isBefore(a))}),a.isDefined(m.maxDate)&&(r(j.findParam(f,m.maxDate)),n.$validators.max=function(a){return!K||b.isMoment(a)&&(J.isSame(a)||J.isAfter(a))}),a.isDefined(m.dateChange)&&(N=j.findFunction(f,m.dateChange)),E&&f.$on("pickerUpdate",function(b,c,d){if(M(c,E))if(D);else{var e=!1;a.isDefined(d.minDate)&&(q(d.minDate),e=!0),a.isDefined(d.maxDate)&&(r(d.maxDate),e=!0),a.isDefined(d.minView)&&(m.minView=d.minView),a.isDefined(d.maxView)&&(m.maxView=d.maxView),m.view=d.view||m.view,e&&n.$validate(),a.isDefined(d.format)&&(x=m.format=d.format||h.format,n.$modelValue=-1),s()}}),g.bind("focus",v),g.bind("blur",u),s()}}}]),a.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n \r\n
\r\n
\r\n
')}])}); \ No newline at end of file