2009-01-16 11:55:29 +01:00
|
|
|
(function($){function Countdown(){this.regional=[];this.regional['']={labels:['Years','Months','Weeks','Days','Hours','Minutes','Seconds'],labels1:['Year','Month','Week','Day','Hour','Minute','Second'],compactLabels:['y','m','w','d'],timeSeparator:':',isRTL:false};this._defaults={format:'dHMS',layout:'',compact:false,description:'',expiryUrl:null,alwaysExpire:false,onExpiry:null,onTick:null,serverTime:null};$.extend(this._defaults,this.regional[''])}var q='countdown';var Y=0;var O=1;var W=2;var D=3;var H=4;var M=5;var S=6;$.extend(Countdown.prototype,{markerClassName:'hasCountdown',setDefaults:function(a){this._resetExtraLabels(this._defaults,a);extendRemove(this._defaults,a||{})},_attachCountdown:function(a,b){a=$(a);if(a.is('.'+this.markerClassName)){return}a.addClass(this.markerClassName);if(!a[0].id){a[0].id='cdn'+new Date().getTime()}var c={};c.options=$.extend({},b);c._periods=[0,0,0,0,0,0,0];this._adjustSettings(c);$.data(a[0],q,c);this._updateCountdown(a,c)},_updateCountdown:function(a,b){var c=$(a);b=b||$.data(c[0],q);if(!b){return}c.html(this._generateHTML(b));c[(this._get(b,'isRTL')?'add':'remove')+'Class']('countdown_rtl');var d=this._get(b,'onTick');if(d){d.apply(c[0],[b._hold!='lap'?b._periods:this._calculatePeriods(b,b._show,new Date())])}var e=b._hold!='pause'&&(b._since?b._now.getTime()<=b._since.getTime():b._now.getTime()>=b._until.getTime());if(e){if(b._timer||this._get(b,'alwaysExpire')){var f=this._get(b,'onExpiry');if(f){f.apply(c[0],[])}var g=this._get(b,'expiryUrl');if(g){window.location=g}}b._timer=null}else if(b._hold=='pause'){b._time=null}else{var h=this._get(b,'format');b._timer=setTimeout('$.countdown._updateCountdown("#'+c[0].id+'")',(h.match('s|S')?1:(h.match('m|M')?30:600))*980)}$.data(c[0],q,b)},_changeCountdown:function(a,b){var c=$.data(a,q);if(c){this._resetExtraLabels(c.options,b);extendRemove(c.options,b||{});this._adjustSettings(c);$.data(a,q,c);this._updateCountdown(a,c)}},_resetExtraLabels:function(a,b){var c=false;for(var n in b){if(n.match(/[Ll]abels/)){c=true;break}}if(c){for(var n in a){if(n.match(/[Ll]abels[0-9]/)){a[n]=null}}}},_destroyCountdown:function(a){a=$(a);if(!a.is('.'+this.markerClassName)){return}a.removeClass(this.markerClassName).empty();var b=$.data(a[0],q);if(b._timer){clearTimeout(b._timer)}$.removeData(a[0],q)},_pauseCountdown:function(a){this._hold(a,'pause')},_lapCountdown:function(a){this._hold(a,'lap')},_resumeCountdown:function(a){this._hold(a,null)},_hold:function(a,b){var c=$.data(a,q);if(c){if(c._hold=='pause'&&!b){c._periods=c._savePeriods;var d=(c._since?'-':'+');c[c._since?'_since':'_until']=this._determineTime(d+c._periods[0]+'Y'+d+c._periods[1]+'O'+d+c._periods[2]+'W'+d+c._periods[3]+'D'+d+c._periods[4]+'H'+d+c._periods[5]+'M'+d+c._periods[6]+'S')}c._hold=b;c._savePeriods=(b=='pause'?c._periods:null);$.data(a,q,c);this._updateCountdown(a,c)}},_getTimesCountdown:function(a){var b=$.data(a,q);return(!b?null:(!b._hold?b._periods:this._calculatePeriods(b,b._show,new Date())))},_get:function(a,b){return(a.options[b]!=null?a.options[b]:$.countdown._defaults[b])},_adjustSettings:function(a){var b=new Date();var c=this._get(a,'serverTime');a._offset=(c?c.getTime()-b.getTime():0);a._since=this._get(a,'since');if(a._since){a._since=this._determineTime(a._since,null)}a._until=this._determineTime(this._get(a,'until'),b);a._show=this._determineShow(a)},_determineTime:function(k,l){var m=function(a){var b=new Date();b.setTime(b.getTime()+a*1000);return b};var n=function(a,b){return 32-new Date(a,b,32).getDate()};var o=function(a){var b=new Date();var c=b.getFullYear();var d=b.getMonth();var e=b.getDate();var f=b.getHours();var g=b.getMinutes();var h=b.getSeconds();var i=/([+-]?[0-9]+)\s*(s|S|m|M|h|H|d|D|w|W|o|O|y|Y)?/g;var j=i.exec(a);while(j){switch(j[2]||'s'){case's':case'S':h+=parseInt(j[1]);break;case'm':case'M':g+=parseInt(j[1]);break;case'h':case'H':f+=parseInt(j[1]);break;case'd':case'D':e+=parseInt(j[1]);break;case'w':case'W':e+=parseInt(j[1])*7;break;case'o':case'O':d+=parseInt(j[1]);e=Math.min(e,n(c,d));break;case'y':case'Y':c+=parseInt(j[1]);e=Mat
|