16 lines
16 KiB
JavaScript
16 lines
16 KiB
JavaScript
/*
|
|
* FullCalendar v1.2
|
|
* http://arshaw.com/fullcalendar/
|
|
*
|
|
* use fullcalendar.css for basic styling
|
|
* requires jQuery UI core and draggables ONLY if you plan to do drag & drop
|
|
*
|
|
* Copyright (c) 2009 Adam Shaw
|
|
* Dual licensed under the MIT and GPL licenses:
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
* Date: 2009-05-31 15:56:02 -0500 (Sun, 31 May 2009)
|
|
* Revision: 23
|
|
*/
|
|
(function(c){c.fn.fullCalendar=function(w){if(typeof w=="string"){var s=Array.prototype.slice.call(arguments,1);var r;this.each(function(){var y=c.data(this,"fullCalendar")[w].apply(this,s);if(typeof r=="undefined"){r=y}});if(typeof r!="undefined"){return r}return this}w=w||{};var t=w.rightToLeft;var m,l;if(t){m=-1;l=6;this.addClass("r2l")}else{m=1;l=0}var x=typeof w.showTime=="undefined"?"guess":w.showTime;var k=typeof w.buttons=="undefined"?true:w.buttons;var v=(w.weekStart||0)%7;var n=w.timeFormat||"gx";var p=w.titleFormat||(t?"Y F":"F Y");var o,j,q,u=true;this.each(function(){var at=w.year?new Date(w.year,w.month||0,1):new Date();var U,M;var L;var aE;var I=false;var V=[];var X=w.eventSources||[];if(w.events){X.push(w.events)}function ax(){aB();af()}function ae(){d(at,-1);ax()}function an(){d(at,1);ax()}function E(){at=new Date();ax()}function az(aF,aG){at=new Date(aF,aG,1);ax()}function aq(){h(at,-1);ax()}function y(){h(at,1);ax()}c.data(this,"fullCalendar",{refresh:ax,prevMonth:ae,nextMonth:an,today:E,gotoMonth:az,prevYear:aq,nextYear:y,addEvent:function(aF){V.push(f(aF));aB();B()},updateEvent:function(aJ){aJ.start=c.fullCalendar.parseDate(aJ.start);aJ.end=c.fullCalendar.parseDate(aJ.end);var aI=aJ.start-aJ._start;var aG=aJ.end-aJ.start;aJ._start=a(aJ.start);for(var aH=0;aH<V.length;aH++){var aK=V[aH];if(aK.id===aJ.id&&aK!==aJ){aK.start=new Date(aK.start.getTime()+aI);aK._start=a(aK.start);aK.end=new Date(aK.start.getTime()+aG);for(var aF in aJ){if(aF&&aF!="start"&&aF!="end"&&aF.charAt(0)!="_"){aK[aF]=aJ[aF]}}}}aB();B()},removeEvent:function(aJ){if(typeof aJ=="object"){aJ=aJ.id}var aI=[];for(var aH=0;aH<V.length;aH++){if(V[aH].id!==aJ){aI.push(V[aH])}}V=aI;for(var aH=0;aH<X.length;aH++){var aK=X[aH];if(typeof aK!="string"&&!c.isFunction(aK)){var aG=[];for(var aF=0;aF<aK.length;aF++){if(aK[aF].id!==aJ){aG.push(aK[aF])}}X[aH]=aG}}aB();B()},getEventsById:function(aH){var aG=[];for(var aF=0;aF<V.length;aF++){if(V[aF].id===aH){aG.push(V[aF])}}return aG},addEventSource:function(aF){X.push(aF);if(w.loading){w.loading(true)}G(aF,function(){if(w.loading){w.loading(false)}aB();B()})},removeEventSource:function(aI){var aH=[];for(var aF=0;aF<X.length;aF++){if(aI!==X[aF]){aH.push(X[aF])}}X=aH;var aG=[];for(var aF=0;aF<V.length;aF++){if(V[aF].source!==aI){aG.push(V[aF])}}V=aG;aB();B()}});var ad,z,ao,ay;var A=c("<div class='full-calendar-header'/>").appendTo(this);if(k){var ac=c("<div class='full-calendar-buttons'/>").appendTo(A);if(k==true||k.today!==false){z=c("<button class='today' />").append(c("<span />").html(typeof k.today=="string"?k.today:"today")).click(E);ac.append(z)}if(k.prevYear){var aC=c("<button class='prev-year' />").append(c("<span />").html(typeof k.prevYear=="string"?k.prevYear:"«")).click(aq);if(t){ac.prepend(aC)}else{ac.append(aC)}}if(k==true||k.prevMonth!==false){var aC=c("<button class='prev-month' />").append(c("<span />").html(typeof k.prevMonth=="string"?k.prevMonth:(t?">":"<"))).click(ae);if(t){ac.prepend(aC)}else{ac.append(aC)}}if(k==true||k.nextMonth!==false){var aC=c("<button class='next-month' />").append(c("<span />").html(typeof k.nextMonth=="string"?k.nextMonth:(t?"<":">"))).click(an);if(t){ac.prepend(aC)}else{ac.append(aC)}}if(k.nextYear){var aC=c("<button class='next-year' />").append(c("<span />").html(typeof k.nextYear=="string"?k.nextYear:"»")).click(y);if(t){ac.prepend(aC)}else{ac.append(aC)}}}if(w.title!==false){ad=c("<h2 class='full-calendar-title'/>").appendTo(A)}ao=c("<div class='full-calendar-month' style='position:relative'/>").appendTo(c("<div class='full-calendar-month-wrap'/>").appendTo(this));var aa,al,D;function af(){I=true;at.setDate(1);g(at);var aR=at.getFullYear();var aO=at.getMonth();var aL=c.fullCalendar.formatDate(at,p);if(ad){ad.text(aL)}g(at);U=a(at);i(U,-((U.getDay()-v+7)%7));M=a(at);d(M,1);i(M,(7-M.getDay()+v)%7);aE=Math.round((M.getTime()-U.getTime())/604800000);if(w.fixedWeeks!=false){i(M,(6-aE)*7);aE=6}L=g(new Date());if(z){if(L.getFullYear()==aR&&L.getMonth()==aO){z.css("visibility","hidden")}else{z.css("visibility","visible")}}var aF=c.fullCalendar.dayNames;var aG=c.fullCalendar.dayAbbrevs;if(!al){var aU=c("<table style='width:100%'/>").appendTo(ao);aa="<thead><tr>";for(var aK=0;aK<7;aK++){var aI=(aK*m+l+v)%7;aa+="<th class='"+aG[aI].toLowerCase()+(aK==0?" first":"")+"'>"+(w.abbrevDayHeadings!=false?aG[aI]:aF[aI])+"</th>"}aa=c(aa+"</tr></thead>").appendTo(aU);al="<tbody>";var aP=a(U);for(var aK=0;aK<aE;aK++){al+="<tr class='week"+(aK+1)+"'>";var aJ="";for(var aI=0;aI<7;aI++){var aV="<td class='day "+aG[(aI+v)%7].toLowerCase()+(aI==l?" first":"")+(aP.getMonth()==aO?"":" other-month")+(aP.getTime()==L.getTime()?" today":"")+"'><div class='day-number'>"+aP.getDate()+"</div><div class='day-content'><div/></div></td>";if(t){aJ=aV+aJ}else{aJ+=aV}i(aP,1)}al+=aJ+"</tr>"}al=c(al+"</tbody>").appendTo(aU);D=c("<div style='position:absolute;top:0;left:0;z-index:1;width:100%' />").appendTo(ao).click(function(aW,aX){if(w.dayClick){H();var aY=K(aW.pageX,aW.pageY);if(aY){return w.dayClick.call(aY,aA(aY))}}})}else{var aS=aE-al.find("tr").length;if(aS<0){al.find("tr:gt("+(aE-1)+")").remove()}else{if(aS>0){var aM="";for(var aK=0;aK<aS;aK++){aM+="<tr class='week"+(aE+aK)+"'>";for(var aI=0;aI<7;aI++){aM+="<td class='day "+aG[(aI*m+l+v)%7].toLowerCase()+(aI==0?" first":"")+"'><div class='day-number'></div><div class='day-content'><div/></div></td>"}aM+="</tr>"}if(aM){al.append(aM)}}}var aP=a(U);al.find("tr").each(function(){for(var aW=0;aW<7;aW++){var aX=this.childNodes[aW*m+l];if(aP.getMonth()==aO){c(aX).removeClass("other-month")}else{c(aX).addClass("other-month")}if(aP.getTime()==L.getTime()){c(aX).addClass("today")}else{c(aX).removeClass("today")}c(aX.childNodes[0]).text(aP.getDate());i(aP,1)}})}ak();if(u){var aQ=al.find("tr");var aH=aQ.find("td");var aT=aQ.position().top;var aN=aH.position().top;o=aN<0;j=aT!=aN;q=al.position().top!=aT;u=false}aw(B);I=false;if(w.monthDisplay){w.monthDisplay(at.getFullYear(),at.getMonth(),aL)}}function ak(){var aG=al.width();var aH=Math.floor(aG/7);var aF=Math.round(aH*0.85);aa.find("th").filter(":lt(6)").width(aH).end().filter(":eq(6)").width(aG-aH*6);al.find("td").height(aF);D.height(ao.height());ay=ao.width()}var ag=[];function B(){ag=[];var aI=0;var aG=a(U);var aH=i(a(aG),7);while(aG.getTime()<M.getTime()){var aF=[];c.each(V,function(aL,aN){if(aN.end.getTime()>aG.getTime()&&aN.start.getTime()<aH.getTime()){var aM,aP,aK,aO;if(aN.start.getTime()<aG.getTime()){aM=a(aG);aK=false}else{aM=a(aN.start);aK=true}if(aN.end.getTime()>aH.getTime()){aP=a(aH);aO=false}else{aP=a(aN.end);aO=true}aM=g(aM);aP=g((aP.getHours()==0&&aP.getMinutes()==0)?aP:i(aP,1));aF.push({event:aN,start:aM,end:aP,isStart:aK,isEnd:aO,msLength:aP-aM})}});aF.sort(b);var aJ=[];c.each(aF,function(aN,aL){var aK=0;while(true){var aO=false;if(aJ[aK]){for(var aM=0;aM<aJ[aK].length;aM++){if(aL.end.getTime()>aJ[aK][aM].start.getTime()&&aL.start.getTime()<aJ[aK][aM].end.getTime()){aO=true;break}}}if(aO){aK++;continue}else{break}}if(aJ[aK]){aJ[aK].push(aL)}else{aJ[aK]=[aL]}});ag[aI]=aJ;i(aG,7);i(aH,7);aI++}am()}var P=[];function am(){for(var aU=0;aU<ag.length;aU++){var aH=ag[aU];var aF=al.find("tr:eq("+aU+")");var aJ=aF.find("td:first");var aX=aJ.find("div.day-content div").css("position","relative");var aO=aX.position().top;if(o){aO-=aJ.position().top}if(j){aO+=aF.position().top}if(q){aO+=al.position().top}var aP=0;for(var aS=0;aS<aH.length;aS++){var aQ=aH[aS];var aM=0;for(var aR=0;aR<aQ.length;aR++){var aW=aQ[aR];var aT=aW.event;var aN,aL,aY,aI;if(t){aL=aW.isStart?aF.find("td:eq("+((aW.start.getDay()-v+7)%7*m+l)+") div.day-content div"):al;aN=aW.isEnd?aF.find("td:eq("+((aW.end.getDay()+6-v)%7*m+l)+") div.day-content div").position().left:al.position().left;aY=aW.isEnd;aI=aW.isStart}else{aN=aW.isStart?aF.find("td:eq("+((aW.start.getDay()-v+7)%7)+") div.day-content div").position().left:al.position().left;aL=aW.isEnd?aF.find("td:eq("+((aW.end.getDay()+6-v)%7)+") div.day-content div"):al;aY=aW.isStart;aI=aW.isEnd}aL=aL.position().left+aL.width();var aK=aT.className;if(typeof aK=="string"){aK=" "+aK}else{if(typeof aK=="object"){aK=" "+aK.join(" ")}}var aG=c("<table class='event"+(aK||"")+"' />").append("<tr>"+(aY?"<td class='nw'/>":"")+"<td class='n'/>"+(aI?"<td class='ne'/>":"")+"</tr>").append("<tr>"+(aY?"<td class='w'/>":"")+"<td class='c'/>"+(aI?"<td class='e'/>":"")+"</tr>").append("<tr>"+(aY?"<td class='sw'/>":"")+"<td class='s'/>"+(aI?"<td class='se'/>":"")+"</tr>");J(aT,aG.find("td.c"));if(w.eventRender){var aZ=w.eventRender(aT,aG);if(typeof aZ!="undefined"){if(aZ===false){continue}if(aZ!==true){aG=c(aZ)}}}aG.css({position:"absolute",top:aO,left:aN,width:aL-aN,"z-index":3}).appendTo(ao);au(aT,aG);var aV=aG.outerHeight({margin:true});if(aV>aM){aM=aV}}aP+=aM;aO+=aM}aX.height(aP)}}function J(aH,aG){c("<span class='event-title' />").text(aH.title).appendTo(aG);var aF=typeof aH.showTime=="undefined"?x:aH.showTime;if(aF!=false){if(aF==true||aF=="guess"&&(aH.start.getHours()||aH.start.getMinutes()||aH.end.getHours()||aH.end.getMinutes())){var aJ=c.fullCalendar.formatDate(aH.start,n);var aI=c("<span class='event-time' />");if(t){aG.append(aI.text(" "+aJ))}else{aG.prepend(aI.text(aJ+" "))}}}}function au(aG,aF){aF.click(function(aI){if(!aF.hasClass("ui-draggable-dragging")){if(w.eventClick){var aH=w.eventClick.call(this,aG,aI);if(aH===false){return false}}if(aG.url){window.location.href=aG.url}}});if(w.eventMouseover){aF.mouseover(function(aH){w.eventMouseover.call(this,aG,aH)})}if(w.eventMouseout){aF.mouseout(function(aH){w.eventMouseout.call(this,aG,aH)})}if(typeof aG.draggable!="undefined"){if(aG.draggable){ai(aG,aF)}}else{if(w.draggable){ai(aG,aF)}}P.push([aG,aF])}function aB(){for(var aF=0;aF<P.length;aF++){P[aF][1].remove()}P=[]}var W,C;var O;function ai(aG,aF){aF.draggable({zIndex:4,delay:50,opacity:w.eventDragOpacity,revertDuration:w.eventRevertDuration,start:function(aJ,aK){for(var aI=0;aI<P.length;aI++){var aH=P[aI];var aL=aH[0];if(aH[1].get(0)!=this&&(aL==aG||typeof aL.id!="undefined"&&aL.id==aG.id)){aH[1].hide()}}if(!O){O=c("<div class='over-day' style='position:absolute;z-index:2' />").appendTo(ao)}H();C=W=null;Y(this,aJ,aK);if(w.eventDragStart){w.eventDragStart.call(this,aG,aJ,aK)}},drag:function(aH,aI){Y(this,aH,aI)},stop:function(aI,aJ){if(!C||C==W){for(var aH=0;aH<P.length;aH++){P[aH][1].show()}}else{var aK=aD(W,C);for(var aH=0;aH<V.length;aH++){if(aG==V[aH]||typeof aG.id!="undefined"&&aG.id==V[aH].id){i(V[aH].start,aK,true);i(V[aH].end,aK,true);V[aH]._start=a(V[aH].start)}}if(w.eventDrop){w.eventDrop.call(this,aG,aK,aI,aJ)}aB();B()}O.hide();if(w.eventDragStop){w.eventDragStop.call(this,aG,aI,aJ)}}})}function Y(aG,aF,aH){var aI=C;C=K(aF.pageX,aF.pageY);if(!W){W=C}if(C!=aI){if(C){c(aG).draggable("option","revert",C==W);O.css({top:N,left:Q,width:R,height:ab,display:"block"})}else{c(aG).draggable("option","revert",true);O.hide()}}}var T,S,F,ar;var Z,aj,ap;var Q,N,R,ab;function H(){var aF,aH,aG=ao.offset();F=aG.left;ar=aG.top;S=[];al.find("tr").each(function(){aF=c(this);S.push(aF.position().top+(j?al.position().top:0))});S.push(S[S.length-1]+aF.height());T=[];aF.find("td").each(function(){aH=c(this);T.push(aH.position().left)});T.push(T[T.length-1]+aH.width());Z=null}function K(aG,aK){var aH=-1,aJ=-1;var aI=S.length-1,aF=T.length-1;while(aH<aI&&aK>ar+S[aH+1]){aH++}while(aJ<aF&&aG>F+T[aJ+1]){aJ++}if(aH<0||aH>=aI||aJ<0||aJ>=aF){return Z=null}else{if(!Z||aH!=aj||aJ!=ap){aj=aH;ap=aJ;Z=al.find("tr:eq("+aH+") td:eq("+aJ+")").get(0);Q=T[aJ];N=S[aH];R=T[aJ+1]-Q;ab=S[aH+1]-N;return Z}}return Z}function aA(aK){var aH,aF=al.get(0).getElementsByTagName("tr");for(aH=0;aH<aF.length;aH++){var aI=aF[aH];for(var aG=0;aG<7;aG++){if(aI.childNodes[aG]==aK){var aJ=a(U);return i(aJ,aH*7+aG*m+l)}}}}function aD(aH,aF){var aJ,aI,aM=al.get(0).getElementsByTagName("tr");for(var aL=0;aL<aM.length;aL++){var aN=aM[aL];for(var aK=0;aK<7;aK++){var aG=aN.childNodes[aK];if(aG==aH){aJ=aL*7+aK*m+l}if(aG==aF){aI=aL*7+aK*m+l}}}return aI-aJ}function aw(aI){V=[];if(X.length>0){var aH=X.length;var aF=function(){if(--aH==0){if(w.loading){w.loading(false)}if(aI){aI(V)}}};if(w.loading){w.loading(true)}for(var aG=0;aG<X.length;aG++){G(X[aG],aF)}}}function G(aI,aK){var aJ=at.getFullYear();var aF=at.getMonth();var aH=function(aL){if(at.getFullYear()==aJ&&at.getMonth()==aF){for(var aM=0;aM<aL.length;aM++){f(aL[aM]);aL[aM].source=aI}V=V.concat(aL)}if(aK){aK(aL)}};if(typeof aI=="string"){var aG={};aG[w.startParam||"start"]=Math.round(U.getTime()/1000);aG[w.endParam||"end"]=Math.round(M.getTime()/1000);aG[w.cacheParam||"_"]=(new Date()).getTime();c.getJSON(aI,aG,aH)}else{if(c.isFunction(aI)){aI(U,M,aH)}else{aH(aI)}}}var av=this;var ah=0;c(window).resize(function(){if(!I){var aF=++ah;setTimeout(function(){if(aF==ah){if(ao.width()!=ay){aB();ak();am();if(w.resize){w.resize.call(av)}}}},200)}});af()});return this};function f(j){if(j.date){j.start=j.date;delete j.date}j.start=c.fullCalendar.parseDate(j.start);j._start=a(j.start);j.end=c.fullCalendar.parseDate(j.end);if(!j.end){j.end=i(a(j.start),1)}return j}function b(k,j){return(j.msLength-k.msLength)*100+(k.event.start-j.event.start)}function e(j){return(j<10?"0":"")+j}function d(k,l,j){k.setMonth(k.getMonth()+l);if(j){return k}return g(k)}function h(k,l,j){k.setFullYear(k.getFullYear()+l);if(j){return k}return g(k)}function i(k,l,j){k.setDate(k.getDate()+l);if(j){return k}return g(k)}function g(j){j.setHours(0);j.setMinutes(0);j.setSeconds(0);j.setMilliseconds(0);return j}function a(j){return new Date(+j)}c.fullCalendar={monthNames:["January","February","March","April","May","June","July","August","September","October","November","December"],monthAbbrevs:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],dayNames:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],dayAbbrevs:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],formatDate:function(n,m){var l=c.fullCalendar.dateFormatters;var k="";for(var j=0;j<m.length;j++){var o=m.charAt(j);if(l[o]){k+=l[o](n)}else{k+=o}}return k},dateFormatters:{a:function(j){return j.getHours()<12?"am":"pm"},A:function(j){return j.getHours()<12?"AM":"PM"},x:function(j){return j.getHours()<12?"a":"p"},X:function(j){return j.getHours()<12?"A":"P"},g:function(j){return j.getHours()%12||12},G:function(j){return j.getHours()},h:function(j){return e(j.getHours()%12||12)},H:function(j){return e(j.getHours())},i:function(j){return e(j.getMinutes())},F:function(j){return c.fullCalendar.monthNames[j.getMonth()]},m:function(j){return e(j.getMonth()+1)},M:function(j){return c.fullCalendar.monthAbbrevs[j.getMonth()]},n:function(j){return j.getMonth()+1},Y:function(j){return j.getFullYear()},y:function(j){return(j.getFullYear()+"").substring(2)},c:function(j){return j.getUTCFullYear()+"-"+e(j.getUTCMonth()+1)+"-"+e(j.getUTCDate())+"T"+e(j.getUTCHours())+":"+e(j.getUTCMinutes())+":"+e(j.getUTCSeconds())+"Z"}},parseDate:function(j){if(typeof j=="object"){return j}if(typeof j=="undefined"){return null}if(typeof j=="number"){return new Date(j*1000)}return c.fullCalendar.parseISO8601(j,true)||Date.parse(j)||new Date(parseInt(j)*1000)},parseISO8601:function(l,j){var m="([0-9]{4})(-([0-9]{2})(-([0-9]{2})(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";var o=l.match(new RegExp(m));if(!o){return null}var n=0;var k=new Date(o[1],0,1);if(o[3]){k.setMonth(o[3]-1)}if(o[5]){k.setDate(o[5])}if(o[7]){k.setHours(o[7])}if(o[8]){k.setMinutes(o[8])}if(o[10]){k.setSeconds(o[10])}if(o[12]){k.setMilliseconds(Number("0."+o[12])*1000)}if(!j){if(o[14]){n=(Number(o[16])*60)+Number(o[17]);n*=((o[15]=="-")?1:-1)}n-=k.getTimezoneOffset()}return new Date(Number(k)+(n*60*1000))}}})(jQuery); |