]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/dnd/TimedMoveable.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / dnd / TimedMoveable.js
1 if(!dojo._hasResource["dojo.dnd.TimedMoveable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.dnd.TimedMoveable"] = true;
3 dojo.provide("dojo.dnd.TimedMoveable");
4
5 dojo.require("dojo.dnd.Moveable");
6
7 (function(){
8         // precalculate long expressions
9         var oldOnMove = dojo.dnd.Moveable.prototype.onMove;
10                 
11         dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, {
12                 // summary:
13                 //      A specialized version of Moveable to support an FPS throttling.
14                 //      This class puts an upper restriction on FPS, which may reduce 
15                 //      the CPU load. The additional parameter "timeout" regulates
16                 //      the delay before actually moving the moveable object.
17                 
18                 // object attributes (for markup)
19                 timeout: 40,    // in ms, 40ms corresponds to 25 fps
20         
21                 constructor: function(node, params){
22                         // summary: an object, which makes a node moveable with a timer
23                         // node: Node: a node (or node's id) to be moved
24                         // params: Object: an optional object with additional parameters.
25                         //      See dojo.dnd.Moveable for details on general parameters.
26                         //      Following parameters are specific for this class:
27                         //              timeout: Number: delay move by this number of ms
28                         //                      accumulating position changes during the timeout
29                         
30                         // sanitize parameters
31                         if(!params){ params = {}; }
32                         if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){
33                                 this.timeout = params.timeout;
34                         }
35                 },
36         
37                 // markup methods
38                 markupFactory: function(params, node){
39                         return new dojo.dnd.TimedMoveable(node, params);
40                 },
41         
42                 onMoveStop: function(/* dojo.dnd.Mover */ mover){
43                         if(mover._timer){
44                                 // stop timer
45                                 clearTimeout(mover._timer)
46                                 // reflect the last received position
47                                 oldOnMove.call(this, mover, mover._leftTop)
48                         }
49                         dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments);
50                 },
51                 onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
52                         mover._leftTop = leftTop;
53                         if(!mover._timer){
54                                 var _t = this;  // to avoid using dojo.hitch()
55                                 mover._timer = setTimeout(function(){
56                                         // we don't have any pending requests
57                                         mover._timer = null;
58                                         // reflect the last received position
59                                         oldOnMove.call(_t, mover, mover._leftTop);
60                                 }, this.timeout);
61                         }
62                 }
63         });
64 })();
65
66 }