source: Dev/branches/rest-dojo-ui/client/dojox/timing/_base.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 1.7 KB
Line 
1define(["dojo/_base/kernel", "dojo/_base/lang"], function(dojo){
2        dojo.experimental("dojox.timing");
3        dojo.getObject("timing", true, dojox);
4
5        dojox.timing.Timer = function(/*int*/ interval){
6                // summary: Timer object executes an "onTick()" method repeatedly at a specified interval.
7                //                      repeatedly at a given interval.
8                // interval: Interval between function calls, in milliseconds.
9                this.timer = null;
10                this.isRunning = false;
11                this.interval = interval;
12
13                this.onStart = null;
14                this.onStop = null;
15        };
16
17        dojo.extend(dojox.timing.Timer, {
18                onTick: function(){
19                        // summary: Method called every time the interval passes.  Override to do something useful.
20                },
21                       
22                setInterval: function(interval){
23                        // summary: Reset the interval of a timer, whether running or not.
24                        // interval: New interval, in milliseconds.
25                        if (this.isRunning){
26                                window.clearInterval(this.timer);
27                        }
28                        this.interval = interval;
29                        if (this.isRunning){
30                                this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
31                        }
32                },
33               
34                start: function(){
35                        // summary: Start the timer ticking.
36                        // description: Calls the "onStart()" handler, if defined.
37                        //                              Note that the onTick() function is not called right away,
38                        //                              only after first interval passes.
39                        if (typeof this.onStart == "function"){
40                                this.onStart();
41                        }
42                        this.isRunning = true;
43                        this.timer = window.setInterval(dojo.hitch(this, "onTick"), this.interval);
44                },
45               
46                stop: function(){
47                        // summary: Stop the timer.
48                        // description: Calls the "onStop()" handler, if defined.
49                        if (typeof this.onStop == "function"){
50                                this.onStop();
51                        }
52                        this.isRunning = false;
53                        window.clearInterval(this.timer);
54                }
55        });
56        return dojox.timing;
57});
Note: See TracBrowser for help on using the repository browser.