/** * The calendar widget implemented with RightJS * * Home page: http://rightjs.org/ui/calendar * * @copyright (C) 2009-2010 Nikolay Nemshilov */ var Calendar=RightJS.Calendar=function(u,p,f){function x(a,b,c,e){if(f.Fx)if(c===undefined){c=this.options.fxName;if(e===undefined){e={duration:this.options.fxDuration,onFinish:f(this.fire).bind(this,b)};if(b==="hide")e.duration=(f.Fx.Durations[e.duration]||e.duration)/2}}f.Element.prototype[b].call(a,c,e);if(!f.Fx||!c)this.fire(b);return this}function s(a){return(a<10?"0":"")+a}var o=f,y=f.$,D=f.$$,q=f.$w,E=f.$ext,F=f.isString,z=f.isArray,G=f.isFunction,t=f.Wrapper,l=f.Element,A=f.Input,B=f.RegExp, C=f.Browser,r=new f.Wrapper(f.Element,{initialize:function(a,b){this.$super("div",b);this._.innerHTML=a;this.addClass("rui-button")},disable:function(){return this.addClass("rui-button-disabled")},enable:function(){return this.removeClass("rui-button-disabled")},disabled:function(){return this.hasClass("rui-button-disabled")},enabled:function(){return!this.disabled()},fire:function(){this.enabled()&&this.$super.apply(this,arguments);return this}}),n=new (function(a,b){if(!b){b=a;a="DIV"}var c=new f.Wrapper(f.Element.Wrappers[a]|| f.Element,{initialize:function(e,d){this.key=e;var g=[{"class":"rui-"+e}];this instanceof f.Input||this instanceof f.Form||g.unshift(a);this.$super.apply(this,g);if(f.isString(d))d=f.$(d);if(d instanceof f.Element){this._=d._;if("$listeners"in d)d.$listeners=d.$listeners;d={}}this.setOptions(d,this);return this},setOptions:function(e,d){d=d||this;f.Options.setOptions.call(this,f.Object.merge(e,eval("("+(d.get("data-"+this.key)||"{}")+")")));return this}});c=new f.Wrapper(c,b);f.Observer.createShortcuts(c.prototype, c.EVENTS||[]);return c})({include:[{show:function(a,b){this.constructor.current=this;return x.call(this,this,"show",a,b)},hide:function(a,b){this.constructor.current=null;return x.call(this,this,"hide",a,b)},showAt:function(a,b,c){var e=this.hide(null).shownAt=a=f.$(a),d=(this.reAnchor||(this.reAnchor=new f.Element("div",{"class":"rui-re-anchor"})).insert(this)).insertTo(e,"after").position();a=e.dimensions();var g=p(e.getStyle("borderTopWidth")),h=p(e.getStyle("borderLeftWidth")),j=p(e.getStyle("borderRightWidth")), i=p(e.getStyle("borderBottomWidth"));e=a.top-d.y+g;d=a.left-d.x+h;h=a.width-h-j;a=a.height-g-i;this.setStyle("visibility:hidden").show(null);if(b==="right")d+=h-this.size().x;else e+=a;this.moveTo(d,e);if(c)["left","right"].include(b)?this.setHeight(a):this.setWidth(h);this.setStyle("visibility:visible").hide(null);return this.show()},toggleAt:function(a,b,c){return this.hidden()?this.showAt(a,b,c):this.hide()}},{assignTo:function(a,b){a=f.$(a);if(b=f.$(b)){b[this.key]=this;b.assignedInput=a}else a[this.key]= this;var c=f(function(){if(this.visible()&&(!this.showAt||this.shownAt===a))this.setValue(a.value())}).bind(this);a.on({keyup:c,change:c});this.onChange(function(){if(!this.showAt||this.shownAt===a)a.setValue(this.getValue())});return this}}],extend:{version:"2.0.0",EVENTS:q("show hide change done"),Options:{format:"ISO",showTime:null,showButtons:false,minDate:false,maxDate:false,fxName:"fade",fxDuration:"short",firstDay:1,numberOfMonths:1,timePeriod:1,twentyFourHour:null,listYears:false,hideOnPick:false, update:null,trigger:null,cssRule:"*[data-calendar]"},Formats:{ISO:"%Y-%m-%d",POSIX:"%Y/%m/%d",EUR:"%d-%m-%Y",US:"%m/%d/%Y"},i18n:{Done:"Done",Now:"Now",NextMonth:"Next Month",PrevMonth:"Previous Month",NextYear:"Next Year",PrevYear:"Previous Year",dayNames:q("Sunday Monday Tuesday Wednesday Thursday Friday Saturday"),dayNamesShort:q("Sun Mon Tue Wed Thu Fri Sat"),dayNamesMin:q("Su Mo Tu We Th Fr Sa"),monthNames:q("January February March April May June July August September October November December"), monthNamesShort:q("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec")},current:null,hideAll:function(a){D("div.rui-calendar").each(function(b){b instanceof n&&b!==a&&b.visible()&&!b.inlined()&&b.hide()})}},initialize:function(a){this.$super("calendar",a);this.addClass("rui-panel");a=this.options;this.insert([this.swaps=new H(a),this.greed=new I(a)]);if(a.showTime)this.insert(this.timepicker=new J(a));if(a.showButtons)this.insert(this.buttons=new K(a));this.setDate(new Date).initEvents()},setDate:function(a, b){if(a=this.parse(a)){var c=this.options;if(c.minDate&&c.minDate>a)a=new Date(c.minDate);if(c.maxDate&&c.maxDate-1;if(c.twentyFourHour===null)c.twentyFourHour=c.format.search(/%[Il]/)<0;if(c.timePeriod>60&&12%Math.ceil(c.timePeriod/60))c.twentyFourHour=true;c.update&&this.assignTo(c.update,c.trigger);return this}, hideOthers:function(){n.hideAll(this);return this}}),H=new t(l,{initialize:function(a){this.$super("div",{"class":"swaps"});this.options=a;var b=a.i18n;this.insert([this.prevMonth=new r("‹",{title:b.PrevMonth,"class":"prev-month"}),this.nextMonth=new r("›",{title:b.NextMonth,"class":"next-month"})]);if(a.listYears)this.insert([this.prevYear=new r("«",{title:b.PrevYear,"class":"prev-year"}),this.nextYear=new r("»",{title:b.NextYear,"class":"next-year"})]);this.buttons=o([this.prevMonth, this.nextMonth,this.prevYear,this.nextYear]).compact();this.onClick(this.clicked)},setDate:function(a){var b=this.options,c=b.numberOfMonths[0]*b.numberOfMonths[1],e=true,d=true,g=true,h=true;if(b.minDate){g=new Date(a.getFullYear(),0,1,0,0,0);var j=new Date(b.minDate.getFullYear(),0,1,0,0,0);e=g>j;g.setMonth(a.getMonth()-Math.ceil(c-c/2));j.setMonth(b.minDate.getMonth());g=g>=j}if(b.maxDate){a=new Date(a);b=new Date(b.maxDate);c=o([a,b]);c.each(function(i){i.setDate(32);i.setMonth(i.getMonth()-1); i.setDate(32-i.getDate());i.setHours(0);i.setMinutes(0);i.setSeconds(0);i.setMilliseconds(0)});h=a"+a.dayNames.map(function(d){return""+d+""}).join("")+"");this.days=[];a=(new l("tbody")).insertTo(this);var b,c,e;for(c=0;c<6;c++){e=(new l("tr")).insertTo(a);for(b=0;b<7;b++)this.days.push((new l("td")).insertTo(e))}this.onClick(this.clicked)},setDate:function(a,b){a.setDate(32);var c=32-a.getDate();a.setMonth(a.getMonth()-1);for(var e=Math.ceil(b.getTime()/864E5),d=this.options,g=d.i18n,h=this.days,j=0,i= h.length-1,k,m,v;j<7;j++){k=h[j]._;m=h[i-j]._;v=h[i-j-7]._;k.innerHTML=m.innerHTML=v.innerHTML="";k.className=m.className=v.className="blank"}j=1;i=0;for(var w;j<=c;j++){a.setDate(j);m=a.getDay();if(d.firstDay===1)m=m>0?m-1:6;if(j===1||m===0){w=h.slice(i*7,i*7+7);i++}k=w[m]._;if(C.OLD){k.innerHTML="";k.appendChild(u.createTextNode(j))}else k.innerHTML=""+j;k.className=e===Math.ceil(a.getTime()/864E5)?"selected":"";if(d.minDate&&d.minDate>a||d.maxDate&&d.maxDate12?c-12:c}this.hours.setValue(c);this.minutes.setValue(a)},timeChanged:function(a){a.stopPropagation(); a=p(this.hours.value());var b=p(this.minutes.value());if(this.meridian){if(a==12)a=0;if(this.meridian.value()=="pm")a+=12}this.fire("time-set",{hours:a,minutes:b})}}),K=new t(l,{initialize:function(a){this.$super("div",{"class":"buttons"});this.insert([(new r(a.i18n.Now,{"class":"now"})).onClick("fire","now-clicked"),(new r(a.i18n.Done,{"class":"done"})).onClick("fire","done-clicked")])}});n.include({parse:function(a){var b;if(F(a)&&a){var c=B.escape(this.options.format),e=o(c.match(/%[a-z]/ig)).map("match", /[a-z]$/i).map("first").without("%");c=new B("^"+c.replace(/%p/i,"(pm|PM|am|AM)").replace(/(%[a-z])/ig,"(.+?)")+"$");if(a=o(a).trim().match(c)){a.shift();for(var d=c=null,g=null,h=null,j=null,i;a.length;){var k=a.shift(),m=e.shift();if(m.toLowerCase()=="b")d=this.options.i18n[m=="b"?"monthNamesShort":"monthNames"].indexOf(k);else if(m.toLowerCase()=="p")i=k.toLowerCase();else{k=p(k,10);switch(m){case "d":case "e":b=k;break;case "m":d=k-1;break;case "y":case "Y":c=k;break;case "H":case "k":case "I":case "l":g= k;break;case "M":h=k;break;case "S":j=k;break}}}if(i){g=g==12?0:g;g=i=="pm"?g+12:g}b=new Date(c,d,b,g,h,j)}}else if(a instanceof Date||Date.parse(a))b=new Date(a);return!b||isNaN(b.getTime())?null:b},format:function(a){var b=this.options.i18n,c=this.date.getDay(),e=this.date.getMonth(),d=this.date.getDate(),g=this.date.getFullYear(),h=this.date.getHours(),j=this.date.getMinutes(),i=this.date.getSeconds(),k=h==0?12:h<13?h:h-12;b={a:b.dayNamesShort[c],A:b.dayNames[c],b:b.monthNamesShort[e],B:b.monthNames[e], d:s(d),e:""+d,m:(e<9?"0":"")+(e+1),y:(""+g).substring(2,4),Y:""+g,H:s(h),k:""+h,I:(h>0&&(h<10||h>12&&h<22)?"0":"")+k,l:""+k,p:h<12?"AM":"PM",P:h<12?"am":"pm",M:s(j),S:s(i),"%":"%"};a=a||this.options.format;for(var m in b)a=a.replace("%"+m,b[m]);return a}});n.include({initEvents:function(){var a=this._terminate;this.on({"prev-day":["_shiftDate",{Date:-1}],"next-day":["_shiftDate",{Date:1}],"prev-week":["_shiftDate",{Date:-7}],"next-week":["_shiftDate",{Date:7}],"prev-month":["_shiftDate",{Month:-1}], "next-month":["_shiftDate",{Month:1}],"prev-year":["_shiftDate",{FullYear:-1}],"next-year":["_shiftDate",{FullYear:1}],"date-set":this._changeDate,"time-set":this._changeTime,"now-clicked":this._setNow,"done-clicked":this.done,click:a,mousedown:a,focus:a,blur:a})},_shiftDate:function(a){var b=new Date(this.date);for(var c in a)b["set"+c](b["get"+c]()+a[c]);this.setDate(b)},_changeDate:function(a){var b=new Date(this.date);b.setDate(a.date);b.setMonth(a.month);b.setFullYear(a.year);this.setDate(b, true);this.options.hideOnPick&&this.done()},_changeTime:function(a){var b=new Date(this.date);b.setHours(a.hours);b.setMinutes(a.minutes);this.setDate(b)},_setNow:function(){this.setDate(new Date)},_terminate:function(a){a.stopPropagation();if(this._hide_delay){this._hide_delay.cancel();this._hide_delay=null}}});y(u).on({focus:function(a){a=a.target instanceof A&&a.target.get("type")=="text"?a.target:null;n.hideAll();if(a&&(a.calendar||a.match(n.Options.cssRule)))(a.calendar||new n({update:a})).setValue(a.value()).showAt(a)}, blur:function(a){var b=a.target.calendar;if(b)b._hide_delay=o(function(){b.hide()}).delay(200)},click:function(a){var b=a.target instanceof l?a.target:null;if(b&&(b.calendar||b.match(n.Options.cssRule))){if(!(b instanceof A)||b.get("type")!="text"){a.stop();(b.calendar||new n({trigger:b})).hide(null).toggleAt(b.assignedInput)}}else a.find("div.rui-calendar")||n.hideAll()},keydown:function(a){var b=n.current,c={27:"hide",37:"prev-day",39:"next-day",38:"prev-week",40:"next-week",33:"prev-month",34:"next-month", 13:"done"}[a.keyCode];if(c&&b&&b.visible()){a.stop();G(b[c])?b[c]():b.fire(c)}}});u.write(''); return n}(document,parseInt,RightJS);