]> git.wh0rd.org Git - tt-rss.git/blob - lib/dojo/dnd/TimedMoveable.js
upgrade Dojo to 1.6.1
[tt-rss.git] / lib / dojo / dnd / TimedMoveable.js
1 /*
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
5 */
6
7
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");
12
13
14 /*=====
15 dojo.declare("dojo.dnd.__TimedMoveableArgs", [dojo.dnd.__MoveableArgs], {
16         // timeout: Number
17         //              delay move by this number of ms,
18         //              accumulating position changes during the timeout
19         timeout: 0
20 });
21 =====*/
22
23 (function(){
24         // precalculate long expressions
25         var oldOnMove = dojo.dnd.Moveable.prototype.onMove;
26                 
27         dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, {
28                 // summary:
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.
33                 
34                 // object attributes (for markup)
35                 timeout: 40,    // in ms, 40ms corresponds to 25 fps
36         
37                 constructor: function(node, params){
38                         // summary:
39                         //              an object that makes a node moveable with a timer
40                         // node: Node||String
41                         //              a node (or node's id) to be moved
42                         // params: dojo.dnd.__TimedMoveableArgs
43                         //              object with additional parameters.
44                         
45                         // sanitize parameters
46                         if(!params){ params = {}; }
47                         if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){
48                                 this.timeout = params.timeout;
49                         }
50                 },
51         
52                 // markup methods
53                 markupFactory: function(params, node){
54                         return new dojo.dnd.TimedMoveable(node, params);
55                 },
56         
57                 onMoveStop: function(/* dojo.dnd.Mover */ mover){
58                         if(mover._timer){
59                                 // stop timer
60                                 clearTimeout(mover._timer)
61                                 // reflect the last received position
62                                 oldOnMove.call(this, mover, mover._leftTop)
63                         }
64                         dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments);
65                 },
66                 onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
67                         mover._leftTop = leftTop;
68                         if(!mover._timer){
69                                 var _t = this;  // to avoid using dojo.hitch()
70                                 mover._timer = setTimeout(function(){
71                                         // we don't have any pending requests
72                                         mover._timer = null;
73                                         // reflect the last received position
74                                         oldOnMove.call(_t, mover, mover._leftTop);
75                                 }, this.timeout);
76                         }
77                 }
78         });
79 })();
80
81 }