-
Notifications
You must be signed in to change notification settings - Fork 86
/
angular-material-calendar.min.js
1 lines (1 loc) · 10.7 KB
/
angular-material-calendar.min.js
1
angular.module("materialCalendar",["ngMaterial","ngSanitize"]),angular.module("materialCalendar").constant("materialCalendar.config",{version:"0.2.13",debug:document.domain.indexOf("localhost")>-1}),angular.module("materialCalendar").config(["materialCalendar.config","$logProvider","$compileProvider",function(t,a,e){t.debug&&(a.debugEnabled(!1),e.debugInfoEnabled(!1))}]),angular.module("materialCalendar").directive("compile",["$compile",function(t){return function(a,e,n){a.$watch(function(t){return t.$eval(n.compile)},function(n){e.html(n),t(e.contents())(a)})}}]),angular.module("materialCalendar").service("materialCalendar.Calendar",[function(){function t(t,a,e){var n=new Date;this.setWeekStartsOn=function(t){var a=parseInt(t||0,10);return this.weekStartsOn=!isNaN(a)&&a>=0&&6>=a?a:0,this.weekStartsOn},this.setStartDateOfMonth=function(t){var a=parseInt(t||1,10);return this.startDateOfMonth=!isNaN(a)&&a>=1&&31>=a?a:1,this.startDateOfMonth},this.setNoOfDays=function(t){var a=parseInt(t||0,10);return this.noOfDays=!isNaN(a)&&a>0?a:0,this.noOfDays},this.options=angular.isObject(e)?e:{},this.year=n.getFullYear(),this.month=n.getMonth(),this.weeks=[],this.weekStartsOn=this.setWeekStartsOn(this.options.weekStartsOn),this.startDateOfMonth=this.setStartDateOfMonth(this.options.startDateOfMonth),this.noOfDays=this.setNoOfDays(this.options.noOfDays),this.next=function(){return this.start.getMonth()<11?void this.init(this.start.getFullYear(),this.start.getMonth()+1):void this.init(this.start.getFullYear()+1,0)},this.prev=function(){return this.month?void this.init(this.start.getFullYear(),this.start.getMonth()-1):void this.init(this.start.getFullYear()-1,11)},this.init=function(t,a){var e=new Date;this.year=angular.isDefined(t)?t:e.getFullYear(),this.month=angular.isDefined(a)?a:e.getMonth();var n=[31,28,31,30,31,30,31,31,30,31,30,31],o=n[this.month];1===this.month&&(this.year%4===0&&this.year%100!==0||this.year%400===0)&&(o=29),this.start=angular.isDefined(this.options.startDateOfMonth)?new Date(this.year,this.month,this.startDateOfMonth):new Date(this.year,this.month,1);var i=angular.copy(this.start);if(1===i.getDate())for(;i.getDay()!==this.weekStartsOn;)i.setDate(i.getDate()-1),o++;if(0!==this.noOfDays){for(;this.noOfDays%7!==0;)this.noOfDays++;o=this.noOfDays}else for(;o%7!==0;)o++;for(;o%7!==0;)o++;this.weeks=[];for(var r=0;o>r;++r)r%7===0&&this.weeks.push([]),this.weeks[this.weeks.length-1].push(angular.copy(i)),i.setDate(i.getDate()+1)},this.init(t,a)}return t}]),angular.module("materialCalendar").service("MaterialCalendarData",[function(){function t(){this.data={},this.getDayKey=function(t){return[t.getFullYear(),t.getMonth()+1,t.getDate()].join("-")},this.setDayContent=function(t,a){this.data[this.getDayKey(t)]=a||this.data[this.getDayKey(t)]||""}}return new t}]),angular.module("materialCalendar").directive("calendarMd",["$compile","$parse","$templateRequest","$q","materialCalendar.Calendar","MaterialCalendarData",function(t,a,e,n,o,i){var r="<md-content layout='column' layout-fill md-swipe-left='next()' md-swipe-right='prev()'><md-toolbar><div class='md-toolbar-tools' layout='row'><md-button class='md-icon-button' ng-click='prev()' aria-label='Previous month'><md-tooltip ng-if='::tooltips()'>Previous month</md-tooltip><md-icon md-svg-icon='md-tabs-arrow'></md-icon></md-button><div flex></div><h2 class='calendar-md-title'><span>{{ calendar.start | date:titleFormat:timezone }}</span></h2><div flex></div><md-button class='md-icon-button' ng-click='next()' aria-label='Next month'><md-tooltip ng-if='::tooltips()'>Next month</md-tooltip><md-icon md-svg-icon='md-tabs-arrow' class='moveNext'></md-icon></md-button></div></md-toolbar><!-- agenda view --><md-content ng-if='weekLayout === columnWeekLayout' class='agenda'><div ng-repeat='week in calendar.weeks track by $index'><div ng-if='sameMonth(day)' ng-class='{"disabled" : isDisabled(day), active: active === day }' ng-click='handleDayClick(day)' ng-repeat='day in week' layout><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat:timezone }}</md-tooltip><div>{{ day | date:dayFormat:timezone }}</div><div flex compile='dataService.data[dayKey(day)]'></div></div></div></md-content><!-- calendar view --><md-content ng-if='weekLayout !== columnWeekLayout' flex layout='column' class='calendar'><div layout='row' class='subheader'><div layout-padding class='subheader-day' flex ng-repeat='day in calendar.weeks[0]'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayLabelTooltipFormat }}</md-tooltip>{{ day | date:dayLabelFormat }}</div></div><div ng-if='week.length' ng-repeat='week in calendar.weeks track by $index' flex layout='row'><div tabindex='{{ sameMonth(day) ? (day | date:dayFormat:timezone) : 0 }}' ng-repeat='day in week track by $index' ng-click='handleDayClick(day)' flex layout layout-padding ng-class='{"disabled" : isDisabled(day), "active": isActive(day), "md-whiteframe-12dp": hover || focus }' ng-focus='focus = true;' ng-blur='focus = false;' ng-mouseleave='hover = false' ng-mouseenter='hover = true'><md-tooltip ng-if='::tooltips()'>{{ day | date:dayTooltipFormat }}</md-tooltip><div>{{ day | date:dayFormat }}</div><div flex compile='dataService.data[dayKey(day)]' id='{{ day | date:dayIdFormat }}'></div></div></div></md-content></md-content>",d=function(){var t="calendarMdCss";if(!document.getElementById(t)){var a=document.getElementsByTagName("head")[0],e=document.createElement("style");e.type="text/css",e.id=t,e.innerHTML="calendar-md md-content>md-content.agenda>*>* :not(:first-child),calendar-md md-content>md-content.calendar>:not(:first-child)>* :last-child{overflow:hidden;text-overflow:ellipsis}calendar-md{display:block;max-height:100%}calendar-md .md-toolbar-tools h2{overflow-x:hidden;text-overflow:ellipsis;white-space:nowrap}calendar-md .md-toolbar-tools .moveNext{transform:translate3d(0,0,0) rotate(180deg)}calendar-md md-content>md-content{border:1px solid rgba(0,0,0,.12)}calendar-md md-content>md-content.agenda>*>*{border-bottom:1px solid rgba(0,0,0,.12)}calendar-md md-content>md-content.agenda>*>.disabled{color:rgba(0,0,0,.3);pointer-events:none;cursor:auto}calendar-md md-content>md-content.agenda>*>* :first-child{padding:12px;width:200px;text-align:right;color:rgba(0,0,0,.75);font-weight:100;overflow-x:hidden;text-overflow:ellipsis;white-space:nowrap}calendar-md md-content>md-content>*>*{min-width:48px}calendar-md md-content>md-content.calendar>:first-child{background:rgba(0,0,0,.02);border-bottom:1px solid rgba(0,0,0,.12);margin-right:0;min-height:36px}calendar-md md-content>md-content.calendar>:not(:first-child)>*{border-bottom:1px solid rgba(0,0,0,.12);border-right:1px solid rgba(0,0,0,.12);cursor:pointer}calendar-md md-content>md-content.calendar>:not(:first-child)>:hover{background:rgba(0,0,0,.04)}calendar-md md-content>md-content.calendar>:not(:first-child)>.disabled{color:rgba(0,0,0,.3);pointer-events:none;cursor:auto}calendar-md md-content>md-content.calendar>:not(:first-child)>.active{box-shadow:0 1px 3px 0 rgba(0,0,0,.2),0 1px 1px 0 rgba(0,0,0,.14),0 2px 1px -1px rgba(0,0,0,.12);background:rgba(0,0,0,.02)}calendar-md md-content>md-content.calendar>:not(:first-child)>* :first-child{padding:0}",a.insertBefore(e,a.firstChild)}};return{restrict:"E",scope:{ngModel:"=?",template:"&",templateUrl:"=?",onDayClick:"=?",onPrevMonth:"=?",onNextMonth:"=?",calendarDirection:"=?",dayContent:"&?",timezone:"=?",titleFormat:"=?",dayFormat:"=?",dayLabelFormat:"=?",dayLabelTooltipFormat:"=?",dayTooltipFormat:"=?",weekStartsOn:"=?",tooltips:"&?",startDateOfMonth:"=?",noOfDays:"=?",clearDataCacheOnLoad:"=?",disableFutureSelection:"=?",disableSelection:"=?"},link:function(l,s,c){d();var u=new Date,m=parseInt(c.startMonth||u.getMonth()),h=parseInt(c.startYear||u.getFullYear());l.columnWeekLayout="column",l.weekLayout="row",l.timezone=l.timezone||null,l.noCache=c.clearDataCacheOnLoad||!1,c.ngModel?(l.active=l.$parent.$eval(c.ngModel),c.ngModel&&l.$watch("$parent."+c.ngModel,function(t){l.active=t})):l.active=null,l.titleFormat=l.titleFormat||"LLLL yyyy",l.dayLabelFormat=l.dayLabelFormat||"EEE",l.dayLabelTooltipFormat=l.dayLabelTooltipFormat||"EEEE",l.dayFormat=l.dayFormat||"d",l.dayTooltipFormat=l.dayTooltipFormat||"fullDate",l.dayIdFormat="dd-MM-yy",l.disableFutureSelection=l.disableFutureSelection||!1,l.disableSelection=l.disableSelection||!1,l.sameMonth=function(t){var a=angular.copy(t);return a.getFullYear()===l.calendar.year&&a.getMonth()===l.calendar.month},l.isDisabled=function(t,a,e){if(0!=e&&angular.isDefined(e)){var n=new Date(l.calendar.year,l.calendar.month,a),o=angular.copy(n);if(o.setDate(n.getDate()+parseInt(e)),t.getDate()<=n&&t.getDate()>=o)return!0}return l.disableSelection?!0:l.disableFutureSelection&&t>new Date?!0:!l.sameMonth(t)},l.calendarDirection=l.calendarDirection||"horizontal",l.$watch("calendarDirection",function(t){l.weekLayout="horizontal"===t?"row":"column"}),l.$watch("weekLayout",function(){h=l.calendar.year,m=l.calendar.month,w()});var g=function(t,a){(t||angular.noop)(a)},f=function(t,a){var e=-1;return angular.forEach(t,function(t,n){0>e&&angular.equals(a,t)&&(e=n)}),e};l.isActive=function(t){var a,e=angular.copy(l.active);return angular.isArray(e)?a=f(e,t)>-1:e&&angular.equals(e.getYear(),t.getYear())&&angular.equals(e.getMonth(),t.getMonth())&&angular.equals(e.getDate(),t.getDate())&&(a=!0),a},l.prev=function(){l.calendar.prev();var t={year:l.calendar.year,month:l.calendar.month+1};D(),g(l.onPrevMonth,t)},l.next=function(){l.calendar.next();var t={year:l.calendar.year,month:l.calendar.month+1};D(),g(l.onNextMonth,t)},l.handleDayClick=function(t){if(!(l.disableFutureSelection&&t>new Date||l.disableSelection)){var e=angular.copy(l.active);if(angular.isArray(e)){var n=f(e,t);n>-1?e.splice(n,1):e.push(t)}else e=angular.equals(e,t)?null:t;l.active=e,c.ngModel&&a(c.ngModel).assign(l.$parent,angular.copy(l.active)),g(l.onDayClick,angular.copy(t))}};var y=function(a){s.html(a),t(s.contents())(l)},p=function(){return l.calendar=new o(h,m,{weekStartsOn:l.weekStartsOn||0,startDateOfMonth:l.startDateOfMonth||1,noOfDays:l.noOfDays||0}),l.templateUrl?e(l.templateUrl):n.resolve(l.template()||r)};l.dataService=i;var v=function(t){return l.dataService.getDayKey(t)};l.dayKey=v;var b=function(t){l.noCache?l.dataService.setDayContent(t,""):l.dataService.setDayContent(t,l.dataService.data[v(t)]||"");var a=(l.dayContent||angular.noop)(),e=(a||angular.noop)(t);angular.isObject(e)&&"function"==typeof e.success?e.success(function(a){l.dataService.setDayContent(t,a)}):angular.isObject(e)&&"function"==typeof e.then?e.then(function(a){l.dataService.setDayContent(t,a)}):l.dataService.setDayContent(t,e)},D=function(){angular.forEach(l.calendar.weeks,function(t){angular.forEach(t,b)})};window.data=l.data;var w=function(){p().then(function(t){y(t),D()})};l.$watchGroup(["weekStartsOn","startDateOfMonth","noOfDays"],p),w(),l._$$init=p,l._$$setTemplate=y,l._$$bootstrap=w}}}]);