]>
Commit | Line | Data |
---|---|---|
1354d172 AD |
1 | define("dojo/dnd/TimedMoveable", ["../main", "./Moveable"], function(dojo) { |
2 | // module: | |
3 | // dojo/dnd/TimedMoveable | |
4 | // summary: | |
5 | // TODOC | |
6 | ||
7 | /*===== | |
8 | dojo.declare("dojo.dnd.__TimedMoveableArgs", [dojo.dnd.__MoveableArgs], { | |
9 | // timeout: Number | |
10 | // delay move by this number of ms, | |
11 | // accumulating position changes during the timeout | |
12 | timeout: 0 | |
13 | }); | |
14 | =====*/ | |
15 | ||
16 | // precalculate long expressions | |
17 | var oldOnMove = dojo.dnd.Moveable.prototype.onMove; | |
18 | ||
19 | dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, { | |
20 | // summary: | |
21 | // A specialized version of Moveable to support an FPS throttling. | |
22 | // This class puts an upper restriction on FPS, which may reduce | |
23 | // the CPU load. The additional parameter "timeout" regulates | |
24 | // the delay before actually moving the moveable object. | |
25 | ||
26 | // object attributes (for markup) | |
27 | timeout: 40, // in ms, 40ms corresponds to 25 fps | |
28 | ||
29 | constructor: function(node, params){ | |
30 | // summary: | |
31 | // an object that makes a node moveable with a timer | |
32 | // node: Node||String | |
33 | // a node (or node's id) to be moved | |
34 | // params: dojo.dnd.__TimedMoveableArgs | |
35 | // object with additional parameters. | |
36 | ||
37 | // sanitize parameters | |
38 | if(!params){ params = {}; } | |
39 | if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){ | |
40 | this.timeout = params.timeout; | |
41 | } | |
42 | }, | |
43 | ||
44 | onMoveStop: function(/* dojo.dnd.Mover */ mover){ | |
45 | if(mover._timer){ | |
46 | // stop timer | |
47 | clearTimeout(mover._timer); | |
48 | // reflect the last received position | |
49 | oldOnMove.call(this, mover, mover._leftTop) | |
50 | } | |
51 | dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments); | |
52 | }, | |
53 | onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){ | |
54 | mover._leftTop = leftTop; | |
55 | if(!mover._timer){ | |
56 | var _t = this; // to avoid using dojo.hitch() | |
57 | mover._timer = setTimeout(function(){ | |
58 | // we don't have any pending requests | |
59 | mover._timer = null; | |
60 | // reflect the last received position | |
61 | oldOnMove.call(_t, mover, mover._leftTop); | |
62 | }, this.timeout); | |
63 | } | |
64 | } | |
65 | }); | |
66 | ||
67 | return dojo.dnd.TimedMoveable; | |
68 | ||
69 | }); |