2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo._hasResource["dojo.dnd.TimedMoveable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo._hasResource["dojo.dnd.TimedMoveable"] = true;
10 dojo.provide("dojo.dnd.TimedMoveable");
11 dojo.require("dojo.dnd.Moveable");
15 dojo.declare("dojo.dnd.__TimedMoveableArgs", [dojo.dnd.__MoveableArgs], {
17 // delay move by this number of ms,
18 // accumulating position changes during the timeout
24 // precalculate long expressions
25 var oldOnMove = dojo.dnd.Moveable.prototype.onMove;
27 dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, {
29 // A specialized version of Moveable to support an FPS throttling.
30 // This class puts an upper restriction on FPS, which may reduce
31 // the CPU load. The additional parameter "timeout" regulates
32 // the delay before actually moving the moveable object.
34 // object attributes (for markup)
35 timeout: 40, // in ms, 40ms corresponds to 25 fps
37 constructor: function(node, params){
39 // an object that makes a node moveable with a timer
41 // a node (or node's id) to be moved
42 // params: dojo.dnd.__TimedMoveableArgs
43 // object with additional parameters.
45 // sanitize parameters
46 if(!params){ params = {}; }
47 if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){
48 this.timeout = params.timeout;
53 markupFactory: function(params, node){
54 return new dojo.dnd.TimedMoveable(node, params);
57 onMoveStop: function(/* dojo.dnd.Mover */ mover){
60 clearTimeout(mover._timer)
61 // reflect the last received position
62 oldOnMove.call(this, mover, mover._leftTop)
64 dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments);
66 onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
67 mover._leftTop = leftTop;
69 var _t = this; // to avoid using dojo.hitch()
70 mover._timer = setTimeout(function(){
71 // we don't have any pending requests
73 // reflect the last received position
74 oldOnMove.call(_t, mover, mover._leftTop);