From 313378ad2905fc07be00183b2acc61284c1c2c39 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 18 Jun 2006 05:02:24 +0000 Subject: Add TCallbackTimer --- framework/Web/Javascripts/js/ajax.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'framework/Web/Javascripts/js/ajax.js') diff --git a/framework/Web/Javascripts/js/ajax.js b/framework/Web/Javascripts/js/ajax.js index fea7e573..c2fb8f82 100644 --- a/framework/Web/Javascripts/js/ajax.js +++ b/framework/Web/Javascripts/js/ajax.js @@ -200,4 +200,18 @@ this.onInit(options);},doCallback:function(event,options) {var element=Event.findElement(event,'LI');this.index=element.autocompleteIndex;this.selectEntry();this.hide();Event.fireEvent(this.element,"change");},getUpdatedChoices:function() {options=new Array(this.getToken(),"__TAutComplete_onSuggest__");Prado.Callback(this.options.EventTarget,options,null,this.options);},onComplete:function(request,boundary) {result=Prado.Element.extractContent(request.responseText,boundary);if(typeof(result)=="string"&&result.length>0) -this.updateChoices(result);}}); \ No newline at end of file +this.updateChoices(result);}});Prado.WebUI.TCallbackTimer=Base.extend({count:0,timeout:0,constructor:function(options) +{this.options=Object.extend({Interval:1,DecayRate:0},options||{}) +this.onComplete=this.options.onComplete;Prado.WebUI.TCallbackTimer.register(this);},startTimer:function() +{this.options.onComplete=this.onRequestComplete.bind(this);setTimeout(this.onTimerEvent.bind(this),200);},stopTimer:function() +{(this.onComplete||Prototype.emptyFunction).apply(this,arguments);this.options.onComplete=undefined;clearTimeout(this.timer);this.timer=undefined;this.count=0;},onTimerEvent:function() +{this.options.params=this.timeout/1000;new Prado.CallbackRequest(this.options.ID,this.options);},onRequestComplete:function() +{(this.onComplete||Prototype.emptyFunction).apply(this,arguments);this.timer=setTimeout(this.onTimerEvent.bind(this),this.getNewTimeout())},getNewTimeout:function() +{switch(this.options.DecayType) +{case'Exponential':t=(Math.exp(this.options.DecayRate*this.count*this.options.Interval))-1;break;case'Linear':t=this.options.DecayRate*this.count*this.options.Interval;break;case'Quadratic':t=this.options.DecayRate*this.count*this.count*this.options.Interval;break;case'Cubic':t=this.options.DecayRate*this.count*this.count*this.count*this.options.Interval;break;default:t=0;} +this.timeout=(t+this.options.Interval)*1000;this.count++;return parseInt(this.timeout);}},{timers:{},register:function(timer) +{this.timers[timer.options.ID]=timer;},start:function(id) +{if(this.timers[id]) +this.timers[id].startTimer();},stop:function(id) +{if(this.timers[id]) +this.timers[id].stopTimer();}}); \ No newline at end of file -- cgit v1.2.3