1 define("dojo/dnd/TimedMoveable", ["../main", "./Moveable"], function(dojo) {
3 // dojo/dnd/TimedMoveable
8 dojo.declare("dojo.dnd.__TimedMoveableArgs", [dojo.dnd.__MoveableArgs], {
10 // delay move by this number of ms,
11 // accumulating position changes during the timeout
16 // precalculate long expressions
17 var oldOnMove = dojo.dnd.Moveable.prototype.onMove;
19 dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, {
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.
26 // object attributes (for markup)
27 timeout: 40, // in ms, 40ms corresponds to 25 fps
29 constructor: function(node, params){
31 // an object that makes a node moveable with a timer
33 // a node (or node's id) to be moved
34 // params: dojo.dnd.__TimedMoveableArgs
35 // object with additional parameters.
37 // sanitize parameters
38 if(!params){ params = {}; }
39 if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){
40 this.timeout = params.timeout;
44 onMoveStop: function(/* dojo.dnd.Mover */ mover){
47 clearTimeout(mover._timer);
48 // reflect the last received position
49 oldOnMove.call(this, mover, mover._leftTop)
51 dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments);
53 onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
54 mover._leftTop = leftTop;
56 var _t = this; // to avoid using dojo.hitch()
57 mover._timer = setTimeout(function(){
58 // we don't have any pending requests
60 // reflect the last received position
61 oldOnMove.call(_t, mover, mover._leftTop);
67 return dojo.dnd.TimedMoveable;