From 940fd56850d931517a70ddcaa4b8d5582652252d Mon Sep 17 00:00:00 2001 From: Julien Deniau Date: Tue, 3 Nov 2015 11:52:43 +0100 Subject: [PATCH] add past and future classes --- dist/multipleDatePicker.min.js | 2 +- multipleDatePicker.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/dist/multipleDatePicker.min.js b/dist/multipleDatePicker.min.js index b38ad02..1b4e730 100644 --- a/dist/multipleDatePicker.min.js +++ b/dist/multipleDatePicker.min.js @@ -1 +1 @@ -angular.module("multipleDatePicker",[]).directive("multipleDatePicker",["$log",function(a){"use strict";return{restrict:"AE",scope:{callback:"&",dayClick:"=?",dayHover:"=?",monthChanged:"=?",daysSelected:"=?",weekDaysOff:"=?",daysOff:"=?",highlightDays:"=?",allDaysOff:"=?",sundayFirstDay:"=?",disallowBackPastMonths:"=",disallowGoFuturMonths:"="},template:'
<
{{month.format(\'MMMM YYYY\')}}
>
{{day}}
 
{{day ? day.format(\'D\') : \'\'}}
 
',link:function(b){var c=function(){var a=moment(),c=moment(b.month).subtract(1,"month"),d=moment(b.month).add(1,"month");b.disableBackButton=b.disallowBackPastMonths&&a.isAfter(c,"month"),b.disableNextButton=b.disallowGoFuturMonths&&a.isBefore(d,"month")},d=function(){for(var a=moment().localeData()._weekdaysMin,c=[],d=1;7>d;d++)c.push(a[d]);return b.sundayFirstDay?c.splice(0,0,a[0]):c.push(a[0]),c};b.$watch("daysSelected",function(a){if(a){var c=[];a.map(function(a){c.push(moment(a))}),b.convertedDaysSelected=c,b.generate()}},!0),b.$watch("weekDaysOff",function(){b.generate()},!0),b.$watch("daysOff",function(c){void 0!==c&&a.warn("daysOff option deprecated since version 1.1.6, please use highlightDays"),b.generate()},!0),b.$watch("highlightDays",function(){b.generate()},!0),b.$watch("allDaysOff",function(){b.generate()},!0),b.month=b.month||moment().startOf("day"),b.days=[],b.convertedDaysSelected=b.convertedDaysSelected||[],b.weekDaysOff=b.weekDaysOff||[],b.daysOff=b.daysOff||[],b.disableBackButton=!1,b.disableNextButton=!1,b.daysOfWeek=d(),b.toggleDay=function(c,d){c.preventDefault();var e=!1;c.preventDefault=function(){e=!0},"function"==typeof b.dayClick&&b.dayClick(c,d),d.selectable&&!e&&(d.selected=!d.selected,d.selected?b.convertedDaysSelected.push(d):b.convertedDaysSelected=b.convertedDaysSelected.filter(function(a){return a.valueOf()!==d.valueOf()}),"function"==typeof b.callback&&(a.warn("callback option deprecated, please use dayClick"),b.callback({timestamp:d.valueOf(),selected:d.selected})))},b.hoverDay=function(a,c){a.preventDefault();var d=!1;a.preventDefault=function(){d=!0},"function"==typeof b.dayHover&&b.dayHover(a,c),d||(c.hover="mouseover"===a.type?!0:!1)},b.previousMonth=function(){if(!b.disableBackButton){var a=moment(b.month);b.month=b.month.subtract(1,"month"),"function"==typeof b.monthChanged&&b.monthChanged(b.month,a),b.generate()}},b.nextMonth=function(){if(!b.disableNextButton){var a=moment(b.month);b.month=b.month.add(1,"month"),"function"==typeof b.monthChanged&&b.monthChanged(b.month,a),b.generate()}},b.isDayOff=function(a,b){return a.allDaysOff||angular.isArray(a.weekDaysOff)&&a.weekDaysOff.some(function(a){return b.day()===a})||angular.isArray(a.daysOff)&&a.daysOff.some(function(a){return b.isSame(a,"day")})||angular.isArray(a.highlightDays)&&a.highlightDays.some(function(a){return b.isSame(a.date,"day")&&!a.selectable})},b.isSelected=function(a,b){return a.convertedDaysSelected.some(function(a){return b.isSame(a,"day")})},b.generate=function(){var a=moment(b.month).date(0),d=moment(b.month).date(1),e=[],f=moment(),g=moment(d).endOf("month"),h=g.date(),i=function(){var c=moment(a.add(1,"days"));if(angular.isArray(b.highlightDays)){var d=b.highlightDays.filter(function(a){return c.isSame(a.date,"day")});c.css=d.length>0?d[0].css:"",c.title=d.length>0?d[0].title:""}return c.selectable=!b.isDayOff(b,c),c.selected=b.isSelected(b,c),c.today=c.isSame(f,"day"),c};b.emptyFirstDays=[];var j;j=0===d.day()?b.sundayFirstDay?0:6:d.day()-(b.sundayFirstDay?0:1);for(var k=j;k>0;k--)b.emptyFirstDays.push({});for(var l=0;h>l;l++)e.push(i());b.emptyLastDays=[];var m=b.sundayFirstDay?6:7;0!==g.day()||b.sundayFirstDay?m-=g.day():m=0;for(var n=m;n>0;n--)b.emptyLastDays.push({});b.days=e,c()},b.generate()}}}]); \ No newline at end of file +angular.module("multipleDatePicker",[]).directive("multipleDatePicker",["$log",function(a){"use strict";return{restrict:"AE",scope:{callback:"&",dayClick:"=?",dayHover:"=?",monthChanged:"=?",daysSelected:"=?",weekDaysOff:"=?",daysOff:"=?",highlightDays:"=?",allDaysOff:"=?",sundayFirstDay:"=?",disallowBackPastMonths:"=",disallowGoFuturMonths:"="},template:'
<
{{month.format(\'MMMM YYYY\')}}
>
{{day}}
 
{{day ? day.format(\'D\') : \'\'}}
 
',link:function(b){var c=function(){var a=moment(),c=moment(b.month).subtract(1,"month"),d=moment(b.month).add(1,"month");b.disableBackButton=b.disallowBackPastMonths&&a.isAfter(c,"month"),b.disableNextButton=b.disallowGoFuturMonths&&a.isBefore(d,"month")},d=function(){for(var a=moment().localeData()._weekdaysMin,c=[],d=1;7>d;d++)c.push(a[d]);return b.sundayFirstDay?c.splice(0,0,a[0]):c.push(a[0]),c};b.$watch("daysSelected",function(a){if(a){var c=[];a.map(function(a){c.push(moment(a))}),b.convertedDaysSelected=c,b.generate()}},!0),b.$watch("weekDaysOff",function(){b.generate()},!0),b.$watch("daysOff",function(c){void 0!==c&&a.warn("daysOff option deprecated since version 1.1.6, please use highlightDays"),b.generate()},!0),b.$watch("highlightDays",function(){b.generate()},!0),b.$watch("allDaysOff",function(){b.generate()},!0),b.month=b.month||moment().startOf("day"),b.days=[],b.convertedDaysSelected=b.convertedDaysSelected||[],b.weekDaysOff=b.weekDaysOff||[],b.daysOff=b.daysOff||[],b.disableBackButton=!1,b.disableNextButton=!1,b.daysOfWeek=d(),b.toggleDay=function(c,d){c.preventDefault();var e=!1;c.preventDefault=function(){e=!0},"function"==typeof b.dayClick&&b.dayClick(c,d),d.selectable&&!e&&(d.selected=!d.selected,d.selected?b.convertedDaysSelected.push(d):b.convertedDaysSelected=b.convertedDaysSelected.filter(function(a){return a.valueOf()!==d.valueOf()}),"function"==typeof b.callback&&(a.warn("callback option deprecated, please use dayClick"),b.callback({timestamp:d.valueOf(),selected:d.selected})))},b.hoverDay=function(a,c){a.preventDefault();var d=!1;a.preventDefault=function(){d=!0},"function"==typeof b.dayHover&&b.dayHover(a,c),d||(c.hover="mouseover"===a.type?!0:!1)},b.previousMonth=function(){if(!b.disableBackButton){var a=moment(b.month);b.month=b.month.subtract(1,"month"),"function"==typeof b.monthChanged&&b.monthChanged(b.month,a),b.generate()}},b.nextMonth=function(){if(!b.disableNextButton){var a=moment(b.month);b.month=b.month.add(1,"month"),"function"==typeof b.monthChanged&&b.monthChanged(b.month,a),b.generate()}},b.isDayOff=function(a,b){return a.allDaysOff||angular.isArray(a.weekDaysOff)&&a.weekDaysOff.some(function(a){return b.day()===a})||angular.isArray(a.daysOff)&&a.daysOff.some(function(a){return b.isSame(a,"day")})||angular.isArray(a.highlightDays)&&a.highlightDays.some(function(a){return b.isSame(a.date,"day")&&!a.selectable})},b.isSelected=function(a,b){return a.convertedDaysSelected.some(function(a){return b.isSame(a,"day")})},b.generate=function(){var a=moment(b.month).date(0),d=moment(b.month).date(1),e=[],f=moment(),g=moment(d).endOf("month"),h=g.date(),i=function(){var c=moment(a.add(1,"days"));if(angular.isArray(b.highlightDays)){var d=b.highlightDays.filter(function(a){return c.isSame(a.date,"day")});c.css=d.length>0?d[0].css:"",c.title=d.length>0?d[0].title:""}return c.selectable=!b.isDayOff(b,c),c.selected=b.isSelected(b,c),c.today=c.isSame(f,"day"),c.past=c.isBefore(f,"day"),c.future=c.isAfter(f,"day"),c};b.emptyFirstDays=[];var j;j=0===d.day()?b.sundayFirstDay?0:6:d.day()-(b.sundayFirstDay?0:1);for(var k=j;k>0;k--)b.emptyFirstDays.push({});for(var l=0;h>l;l++)e.push(i());b.emptyLastDays=[];var m=b.sundayFirstDay?6:7;0!==g.day()||b.sundayFirstDay?m-=g.day():m=0;for(var n=m;n>0;n--)b.emptyLastDays.push({});b.days=e,c()},b.generate()}}}]); \ No newline at end of file diff --git a/multipleDatePicker.js b/multipleDatePicker.js index e229a3b..9697c50 100644 --- a/multipleDatePicker.js +++ b/multipleDatePicker.js @@ -83,7 +83,7 @@ angular.module('multipleDatePicker', []) '' + '
' + '
 
' + - '
{{day ? day.format(\'D\') : \'\'}}
' + + '
{{day ? day.format(\'D\') : \'\'}}
' + '
 
' + '
' + '', @@ -283,6 +283,8 @@ angular.module('multipleDatePicker', []) date.selectable = !scope.isDayOff(scope, date); date.selected = scope.isSelected(scope, date); date.today = date.isSame(now, 'day'); + date.past = date.isBefore(now, 'day'); + date.future = date.isAfter(now, 'day'); return date; };