gm.datepicker-multi-select
Version:
AngularJS module to extend UI Bootstrap's Datepicker directive to allow for multiple date selections.
2 lines • 1.68 kB
JavaScript
/*! gm.datepickerMultiSelect 2015-11-04 */
!function(a){"use strict";a.module("gm.datepickerMultiSelect",["ui.bootstrap"]).config(["$provide","$injector",function(b,c){var d=function(b){var c=b[0],d=c.link;return c.compile=function(){return function(b,c,e,f){if(d.apply(this,arguments),a.isDefined(e.multiSelect)){b.selectedDates=[],b.selectRange,b.$parent.$watchCollection(e.multiSelect,function(a){b.selectedDates=a||[]}),e.$observe("selectRange",function(a){b.selectRange=!!a&&"false"!==a});var g=f[1];g.$viewChangeListeners.push(function(){var a=b.$parent.$eval(e.ngModel);if(a){var c=a.getTime(),d=b.selectedDates;if(b.selectRange){if(!d.length||d.length>1||d[0]==c)return d.splice(0,d.length,c);d.push(c);var f=Math.min.apply(null,d),g=Math.max.apply(null,d);for(f=new Date(f).setHours(24);g>f;)d.push(f),f=new Date(f).setHours(24)}else d.indexOf(c)<0?d.push(c):d.splice(d.indexOf(c),1)}})}}},b};c.has("datepickerDirective")&&b.decorator("datepickerDirective",["$delegate",d]),c.has("uibDatepickerDirective")&&b.decorator("uibDatepickerDirective",["$delegate",d]);var e=function(b){var c=b[0],d=c.link;return c.compile=function(){return function(b,c,e,f){function g(){a.forEach(b.rows,function(c){a.forEach(c,function(a){a.selected=b.selectedDates.indexOf(a.date.setHours(0,0,0,0))>-1})})}if(d.apply(this,arguments),a.isDefined(b.$parent.selectedDates)){b.$parent.$watchCollection("selectedDates",g);var h=a.isArray(f)?f[0]:f;b.$watch(function(){return h.activeDate.getTime()},g)}}},b};c.has("daypickerDirective")&&b.decorator("daypickerDirective",["$delegate",e]),c.has("uibDaypickerDirective")&&b.decorator("uibDaypickerDirective",["$delegate",e])}])}(window.angular);