Files
angular-datepicker/dist/index.min.js
2013-10-03 15:15:51 +02:00

1 line
12 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!function(a){"use strict";var b=a.module("datePicker",[]);b.directive("datePicker",function(){function a(a){return a instanceof Date&&!isNaN(a.getTime())}function b(a){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate(),a.getHours());for(var b=[],c=5,d=a.getTime()+36e5;a.getTime()<d;)b.push(a),a=new Date(a.getTime()+1e3*60*c);return b}function c(a){a=new Date(a||new Date),a.setDate(1),a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setMilliseconds(0),0===a.getDay()?a.setDate(-5):a.setDate(a.getDate()-(a.getDay()-1)),1===a.getDate()&&a.setDate(-6);for(var b=[];b.length<6;){for(var c=[],d=0;7>d;d++)c.push(new Date(a)),a.setDate(a.getDate()+1);b.push(c)}return b}function d(a){var b=[];a=new Date(a||new Date),a.setFullYear(a.getFullYear()-a.getFullYear()%10);for(var c=0;12>c;c++)b.push(new Date(a.getFullYear()+(c-1),0,1));return b}function e(a){a=new Date(a||new Date),a=new Date(a.getFullYear(),a.getMonth(),a.getDate()),a.setDate(a.getDate()-(a.getDay()-1));for(var b=[],c=0;7>c;c++)b.push(new Date(a)),a.setDate(a.getDate()+1);return b}function f(a){a=new Date(a||new Date);for(var b=a.getFullYear(),c=[],d=0;12>d;d++)c.push(new Date(b,d,1));return c}function g(a){a=new Date(a||new Date),a.setHours(0),a.setMinutes(0),a.setSeconds(0),a.setMilliseconds(0);for(var b=[],c=0;24>c;c++)b.push(a),a=new Date(a.getTime()+36e5);return b}var h=["month","date","year","month","hours","minutes"];return{scope:{date:"=datePicker",after:"=?",before:"=?"},link:function(i,j,k){function l(a){return-1!==i.views.indexOf(a)}function m(){a(i.date)||(i.date=new Date(2e3,1,1)),i.date=new Date(i.date)}function n(a){m(),i.date.setFullYear(a.getFullYear())}function o(a){n(a),i.date.setMonth(a.getMonth())}function p(a){o(a),i.date.setDate(a.getDate())}function q(a){p(a),i.date.setHours(a.getHours())}function r(a){q(a),i.date.setMinutes(a.getMinutes())}function s(){return i.date instanceof Date}i.views=[];for(var t in k)-1!==h.indexOf(t)&&i.views.push(t);i.views.length||(i.views=["date","month","year","hours","minutes"]),i.view=i.views[0],i.setYear=function(a){n(a),i.$emit("setYear",a)},i.setMonth=function(a){o(a),i.$emit("setMonth",a)},i.setDate=function(a){p(a),i.$emit("setDate",a)},i.setHours=function(a){q(a),i.$emit("setHours",a)},i.setMinutes=function(a){r(a),i.$emit("setMinutes",a)},i.setView=function(a){if(l(a))switch(i.view=a,a){case"minutes":i.minutes=b(i.visibleDate);break;case"hours":i.hours=g(i.visibleDate);break;case"date":i.weeks=c(i.visibleDate);break;case"month":i.months=f(i.visibleDate);break;case"year":i.years=d(i.visibleDate)}},i.nextMonth=function(a){i.visibleDate.setMonth(i.visibleDate.getMonth()+(a||1))},i.prevMonth=function(a){i.nextMonth(-a||-1)},i.nextDay=function(a){i.visibleDate.setDate(i.visibleDate.getDate()+(a||1))},i.prevDay=function(a){i.nextDay(-a||-1)},i.nextHour=function(a){i.visibleDate.setHours(i.visibleDate.getHours()+(a||1))},i.prevHour=function(a){i.nextHour(-a||-1)},i.nextYear=function(a){i.visibleDate.setFullYear(i.visibleDate.getFullYear()+(a||1))},i.prevYear=function(a){i.nextYear(-a||-1)},i.visibleDate=new Date,i.$watch("date",function(a){a&&(i.visibleDate=new Date(a))}),i.isAfter=function(a){return a>=i.after},i.isBefore=function(a){return a<=i.before},i.isSameMinutes=function(a){if(!s())return!1;var b=i.date;return a.getTime()-1e3*a.getSeconds()-a.getMilliseconds()===b.getTime()-1e3*b.getSeconds()-b.getMilliseconds()},i.isSameMonth=function(a){return s()?a.getFullYear()===i.date.getFullYear()&&a.getMonth()===i.date.getMonth():!1},i.isSameYear=function(a){return s()?a.getFullYear()===i.date.getFullYear():!1},i.isSameDate=function(a){return s()?i.date.getDate()===a.getDate()&&i.isSameMonth(a):!1},i.isSameHour=function(a){return s()?i.date.getHours()===a.getHours()&&i.isSameDate(a):!1},i.isOldMonth=function(a){return a.getTime()<i.visibleDate.getTime()&&a.getMonth()!==i.visibleDate.getMonth()},i.isNewHour=function(a){return a.getTime()>i.visibleDate.getTime()&&a.getHours()!==i.visibleDate.getHours()},i.isOldHour=function(a){return a.getTime()<i.visibleDate.getTime()&&a.getHours()!==i.visibleDate.getHours()},i.isNewMonth=function(a){return a.getTime()>i.visibleDate.getTime()&&a.getMonth()!==i.visibleDate.getMonth()},i.$on("setDate",i.setView.bind(null,"hours")),i.$on("setMonth",i.setView.bind(null,"date")),i.$on("setHours",i.setView.bind(null,"minutes")),i.$on("setYear",i.setView.bind(null,"month")),i.$watch(function(){return a(i.visibleDate)},function(a){a||(i.visibleDate=new Date)}),i.$watch("[visibleDate.getDate(),visibleDate.getHours()].join()",function(){"hours"===i.view&&(i.hours=g(i.visibleDate))}),i.$watch("[visibleDate.getFullYear(),visibleDate.getMonth(),visibleDate.getDate()].join()",function(){"date"===i.view&&(i.weeks=c(i.visibleDate),i.weekdays=e(i.visibleDate))}),i.$watch("[visibleDate.getFullYear(),visibleDate.getMonth()].join()",function(){"month"===i.view&&(i.months=f(i.visibleDate))}),i.$watch("visibleDate.getYear()",function(){"year"===i.view&&(i.years=d(i.visibleDate))}),i.$watch("visibleDate.getTime()",function(){"minutes"===i.view&&(i.minutes=b(i.visibleDate))})},replace:!0,templateUrl:"templates/datepicker.html"}}),b.directive("dateTime",["$compile","$document","$filter",function(b,c,d){var e=c.find("body"),f=d("date");return{require:"ngModel",link:function(c,d,g,h){function i(a){return f(a,j)}var j=g.format||"yyyy-MM-dd HH:mm",k=["date","year","month","hours","minutes","month"],l=[];for(var m in g)-1!==k.indexOf(m)&&l.push(m);c.$watch(""+g.ngModel+".getTime()",function(a,b){a!==b&&h.$setViewValue(a)}),h.$formatters.push(i);var n=null,o=a.noop;d.bind("focus",function(){if(!n){n=b('<div date-picker="'+g.ngModel+'" class="datetimepicker datetimepicker-dropdown-bottom-left dropdown-menu" format="'+j+'" '+l.join(" ")+"></div>")(c),e.append(n),c.$digest();var f=a.extend(d.offset(),{height:d[0].offsetHeight});n.css({top:f.top+f.height,left:f.left,display:"block",position:"absolute"}),n.bind("mousedown",function(){return!1})}return!1}),d.bind("blur",function(){o(),o=a.noop,n&&n.remove(),n=null})}}}]),b.directive("dateRange",function(){return{templateUrl:"templates/daterange.html",scope:{start:"=",end:"="},link:function(a){a.$watch("start.getTime()",function(b){b&&a.end&&b>a.end.getTime()&&(a.end=new Date(b))}),a.$watch("end.getTime()",function(b){b&&a.start&&b<a.start.getTime()&&(a.start=new Date(b))})}}})}(angular),angular.module("datePicker").run(["$templateCache",function(a){a.put("templates/datepicker.html",'<div>\n <div ng-switch="view">\n <div class="datetimepicker-days" ng-switch-when="date">\n <table class=" table-condensed">\n <thead>\n <tr>\n <th class="prev" style="visibility: visible;" ng-click="prevMonth()"></th>\n <th colspan="5" class="switch" ng-click="setView(\'month\')">{{visibleDate|date:"yyyy MMMM"}}</th>\n <th class="next" style="visibility: visible;" ng-click="nextMonth()"></i></th>\n </tr>\n <tr>\n <th class="dow" ng-repeat="day in weekdays">{{ day|date:"EEE"}}</th>\n </tr>\n </thead>\n <tbody>\n <tr ng-repeat="week in weeks">\n <td class="day" ng-repeat="day in week"\n ng-class="{\'active\':isSameDate(day),\'old\':isOldMonth(day),\'new\':isNewMonth(day),\'after\':isAfter(day),\'before\':isBefore(day)}"\n ng-click="setDate(day)">{{ day.getDate() }}\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <th colspan="7" class="today" style="display: none;">Today</th>\n </tr>\n </tfoot>\n </table>\n </div>\n <div class="datetimepicker-years" ng-switch-when="year">\n <table class="table-condensed">\n <thead>\n <tr>\n <th class="prev" style="visibility: visible;" ng-click="prevYear(10)"></th>\n <th colspan="5" class="switch">{{years[0].getFullYear()}}-{{years[years.length-1].getFullYear()}}</th>\n <th class="next" style="visibility: visible;" ng-click="nextYear(10)"></i></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td colspan="7">\n <span class="year" ng-repeat="year in years" ng-class="{\'active\':isSameYear(year)}"\n ng-click="setYear(year)">{{year.getFullYear()}}</span>\n </td>\n </tr>\n </tbody>\n </table>\n </div>\n\n <div class="datetimepicker-months" ng-switch-when="month">\n <table class="table-condensed">\n <thead>\n <tr>\n <th class="prev" style="visibility: visible;" ng-click="prevYear()"></th>\n <th colspan="5" class="switch" ng-click="setView(\'year\')">{{ visibleDate|date:"yyyy" }}</th>\n <th class="next" style="visibility: visible;" ng-click="nextYear()"></i></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td colspan="7">\n <span class="month" ng-repeat="month in months"\n ng-class="{\'active\':isSameMonth(month),\'after\':isAfter(month),\'before\':isBefore(month)}"\n ng-click="setMonth(month)">{{month|date:\'MMM\'}}</span>\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <th colspan="7" class="today" style="display: none;">Today</th>\n </tr>\n </tfoot>\n </table>\n </div>\n\n <div class="datetimepicker-hours" ng-switch-when="hours">\n <table class=" table-condensed">\n <thead>\n <tr>\n <th class="prev" style="visibility: visible;" ng-click="prevDay()"></th>\n <th colspan="5" class="switch" ng-click="setView(\'date\')">{{ visibleDate|date:"dd MMMM yyyy" }}</th>\n <th class="next" style="visibility: visible;" ng-click="nextDay()"></i></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td colspan="7">\n <span class="hour" ng-repeat="hour in hours"\n ng-class="{\'old\':isOldHour(hour),\'new\':isNewHour(hour),\'active\':isSameHour(hour)}"\n ng-click="setHours(hour)">{{hour|date:"HH:mm"}}</span>\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <th colspan="7" class="today" style="display: none;">Today</th>\n </tr>\n </tfoot>\n </table>\n </div>\n <div class="datetimepicker-minutes" ng-switch-when="minutes">\n <table class=" table-condensed">\n <thead>\n <tr>\n <th class="prev" style="visibility: visible;" ng-click="prevHour()"></th>\n <th colspan="5" class="switch" ng-click="setView(\'hours\')">{{ visibleDate|date:"dd MMMM yyyy HH:mm" }}\n </th>\n <th class="next" style="visibility: visible;" ng-click="nextHour()"></i></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td colspan="7">\n <span class="minute" ng-repeat="minute in minutes" ng-class="{active:isSameMinutes(minute)}"\n ng-click="setMinutes(minute)">{{minute|date:"HH:mm"}}</span>\n </td>\n </tr>\n </tbody>\n <tfoot>\n <tr>\n <th colspan="7" class="today" style="display: none;">Today</th>\n </tr>\n </tfoot>\n </table>\n </div>\n </div>\n</div>\n'),a.put("templates/daterange.html",'<div>\n <table>\n <tr>\n <td valign="top">\n <div date-picker="start" class="date-picker" date after="start" before="end"></div>\n </td>\n <td valign="top">\n <div date-picker="end" class="date-picker" date after="start" before="end"></div>\n </td>\n </tr>\n </table>\n</div>')}]);