From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- includes/js/dojox/timing/Sequence.js | 145 +++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 includes/js/dojox/timing/Sequence.js (limited to 'includes/js/dojox/timing/Sequence.js') diff --git a/includes/js/dojox/timing/Sequence.js b/includes/js/dojox/timing/Sequence.js new file mode 100644 index 0000000..4dc4bdb --- /dev/null +++ b/includes/js/dojox/timing/Sequence.js @@ -0,0 +1,145 @@ +if(!dojo._hasResource["dojox.timing.Sequence"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.timing.Sequence"] = true; +dojo.provide("dojox.timing.Sequence"); +dojo.experimental("dojox.timing.Sequence"); // in case it gets moved/renamed somewhere soon + +dojo.declare("dojox.timing.Sequence",null,{ + // summary: + // This class provides functionality to really sequentialize + // function calls. You need to provide a list of functions and + // some parameters for each (like: pauseBefore) and they will + // be run one after another. This can be very useful for slideshows + // or alike things. + // + // description: + // This array will contain the sequence defines resolved, so that + // ie. repeat:10 will result in 10 elements in the sequence, so + // the repeat handling is easier and we don't need to handle that + // many extra cases. Also the doneFunction, if given is added at the + // end of the resolved-sequences. + + // _defsResolved: Array + // The resolved sequence, for easier handling. + _defsResolved: [], + + // This is the time to wait before goOn() calls _go(), which + // mostly results from a pauseAfter for a function that returned + // false and is later continued by the external goOn() call. + // The time to wait needs to be waited in goOn() where the + // sequence is continued. + + // _goOnPause: Integer + // The pause to wait before really going on. + _goOnPause: 0, + + _running: false, + + go: function(/* Array */defs, /* function|Array? */doneFunction){ + // summary: + // + // defs: Array + // the sequence of actions + // doneFunction: Function|Array? + // The function to call when done + this._running = true; + var self = this; + dojo.forEach(defs, function(cur){ + if(cur.repeat > 1){ + var repeat = cur.repeat; + for(var j=0; j2){ + ret = func[0].apply(func[1], func.slice(2)); + }else{ + ret = func[0].apply(func[1]); + } + }else{ + ret = func(); + } + return ret; + } + + if(this._curId >= this._defsResolved.length){ + resolveAndCallFunc(cur.func); // call the last function, since it is the doneFunction we dont need to handle pause stuff + // don't go on and call this._go() again, we are done + return; + } + var self = this; + if(cur.pauseAfter){ + if(resolveAndCallFunc(cur.func)!==false){ + window.setTimeout(function() {self._go()}, cur.pauseAfter); + }else{ + this._goOnPause = cur.pauseAfter; + } + }else if(cur.pauseBefore){ + var x = function(){ + if(resolveAndCallFunc(cur.func)!==false){ + self._go() + } + }; + window.setTimeout(x, cur.pauseBefore); + }else{ + if(resolveAndCallFunc(cur.func)!==false){ + this._go(); + } + } + }, + + goOn: function(){ + // summary: This method just provides a hook from the outside, so that + // an interrupted sequence can be continued. + if(this._goOnPause){ + var self = this; + setTimeout(function(){ self._go() }, this._goOnPause); + this._goOnPause = 0; // reset it, so if the next one doesnt set it we dont use the old pause + }else{ this._go(); } + }, + + stop: function(){ + // summary: Stop the currently running sequence. + // description: + // This can only interrupt the sequence not the last function that + // had been started. If the last function was i.e. a slideshow + // that is handled inside a function that you have given as + // one sequence item it cant be stopped, since it is not controlled + // by this object here. In this case it would be smarter to + // run the slideshow using a sequence object so you can also stop + // it using this method. + this._running = false; + } +}); + +} -- cgit v1.2.3