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