-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcalendar.min.js
10 lines (10 loc) · 5.02 KB
/
calendar.min.js
1
2
3
4
5
6
7
8
9
10
(function(){function o(){var f=this,c,j,m,p,q,i,r,e,g,h,n,l,k,s,t=0,u=Modernizr.csstransforms3d?"webkit moz o ms khtml ".split(" ").join("AnimationEnd ")+"animationEnd":"noAnimationEnd",d=function(a,b){b&&b.clearTime&&b.clearTime();a=="startDate"?e=b:g=b;y();c.data(a.toLowerCase(),!b?"":b.toString());c.trigger(a+"Changed")},o=function(a){a.preventDefault();a=$(this);if(!(a.hasClass("inactive")||a.text().length==0)){var b=new Date(h.getFullYear(),h.getMonth(),parseInt(a.text()));s?d("startDate",!e||
b.getTime()!=e.getTime()?b:null):e?g?a.hasClass("startDate")?d("startDate",null):(a.hasClass("endDate")||d("startDate",null),d("endDate",null)):e<b?d("endDate",b):b<e?(d("endDate",e),d("startDate",b)):d("startDate",null):g?b<g?d("startDate",b):g<b?(d("startDate",g),d("endDate",b)):d("endDate",null):d("startDate",b)}},D=function(){Date.prototype.clone=function(){return new Date(this.getTime())};Date.prototype.isLeapYear=function(){var a=this.getFullYear();return a%4===0&&a%100!==0||a%400===0};Date.prototype.getDaysInMonth=
function(){return[31,this.isLeapYear(this.getFullYear())?29:28,31,30,31,30,31,31,30,31,30,31][this.getMonth()]};Date.prototype.moveToFirstDayOfMonth=function(){this.setDate(1);return this};Date.prototype.moveToLastDayOfMonth=function(){this.setDate(this.getDaysInMonth());return this};Date.prototype.addMilliseconds=function(a){this.setMilliseconds(this.getMilliseconds()+a);return this};Date.prototype.addDays=function(a){return this.addMilliseconds(a*864E5)};Date.prototype.addMonths=function(a){var b=
this.getDate();this.setDate(1);this.setMonth(this.getMonth()+a);this.setDate(Math.min(b,this.getDaysInMonth()));return this};Date.prototype.clearTime=function(){this.setHours(0);this.setMinutes(0);this.setSeconds(0);this.setMilliseconds(0);return this}},v=function(a){return(a+t)%7},y=function(){i.removeClass("startDate").removeClass("endDate").removeClass("betweenDates");var a=h.clone().moveToFirstDayOfMonth(),b=h.clone().moveToLastDayOfMonth(),c=v(a.getDay())-1;if(e&&g&&e<b&&g>a){var d=new Date(Math.max(a,
e.clone().addDays(1))),f=new Date(Math.min(b,g.clone().addDays(-1)));d<=f&&i.slice(c+d.getDate(),c+f.getDate()+1).addClass("betweenDates")}e&&a<=e&&e<=b&&i.eq(c+e.getDate()).addClass("startDate");g&&a<=g&&g<=b&&i.eq(c+g.getDate()).addClass("endDate")};f.ready=function(a){c=a;j=$('<a href="#"><</a>');m=$('<a href="#">></a>');p=$('<li class="calMonth"></li>');c.append($('<ul class="calButtonBar"></ul>').append($('<li class="calPrevious"></li>').append(j)).append(p).append($('<li class="calNext"></li>').append(m)));
for(var a=0,b="",z="";a<7;a++)b+="<th></th>",z+='<td><a href="#"></a></td>';for(var a=0,A="";a<6;a++)A+="<tr>"+z+"</tr>";c.append('<div class="calGrid"><table><tr>'+b+"</tr>"+A+"</table></div>");q=c.find("th");i=c.find("td a");r=c.find("tr");r.eq(1).addClass("first");s=c.hasClass("jsSingleDate");t=c.data("firstdayofweek")||t;c.get(0).calendar=f;if($.fn)$.fn.slice=$.fn.slice||function(a,b){return $([].slice.call(this,a,b))},$.fn.calendar=function(){return this.get(0).calendar};D();l=n=(new Date).clearTime();
e=(e=c.data("startdate"))?(new Date(e)).clearTime():null;g=(g=c.data("enddate"))?(new Date(g)).clearTime():null;h=(e||n).clone();k=c.data("localized_date");typeof k=="string"&&(k=JSON.parse(k));var w=c.find(".calGrid"),x=[],B=function(a){return w.children().length>1?(x.push(a),!0):!1},C=function(){x.length>0&&setTimeout(function(){x.shift().trigger("click")},0)};j.bind("click",function(a){a.preventDefault();if(!B(j)){h=h.addMonths(-1);var b=$("<table>"+c.find("table").html()+"</table>");w.append(b);
i.closest("table").addClass("turndown").bind(u,function(){$(this).removeClass("turndown").unbind(u);b.remove();C()}).trigger("noAnimationEnd");f.showMonth(h)}});m.bind("click",function(a){a.preventDefault();if(!B(m)){h=h.addMonths(1);var b=$('<table class="turnup">'+c.find("table").html()+"</table>");w.append(b);b.bind(u,function(){b.remove();C()}).trigger("noAnimationEnd");f.showMonth(h)}});c.bind("resetDates",function(){d("startDate",null);d("endDate",null)});i.bind("click",o);f.showMonth(h)};f.setDates=
function(a,b){d("startDate",a&&b?new Date(Math.min(a,b)):a);!s&&d("endDate",a&&b?a.getTime()!=b.getTime()?new Date(Math.max(a,b)):null:b)};f.showMonth=function(a){l=new Date(Math.max(l,n));if(k){p.text(k.months.names["long"][a.getMonth()]+" "+a.getFullYear());for(var b=0,c=q.length;b<c;b++)q.eq(v(b)).text(k.days.names.min[b])}var d=l>a.clone().moveToLastDayOfMonth(),e=!d&&l>=a.clone().moveToFirstDayOfMonth(),g=l.getDate();i.addClass("noTransition").removeClass("inactive");r.removeClass("last").removeClass("hidden");
for(var f=v(a.clone().moveToFirstDayOfMonth().getDay())-1,a=f+a.clone().moveToLastDayOfMonth().getDate(),b=0,c=i.length;b<c;b++){var h=b>f&&b<=a,j=i.eq(b).text(h?""+(b-f):"");h&&(d||e&&b-f<g)&&j.addClass("inactive");e&&n.getDate()==b-f&&j.addClass("today");b==a&&j.closest("tr").addClass("last").next().addClass("hidden").next().addClass("hidden")}setTimeout(function(){i.removeClass("noTransition")},0);y()}}$(document).ready(function(){for(var f=$(".jsCalendar"),c=0,j=f.length;c<j;c++)(new o).ready(f.eq(c))})})();