source: Dev/trunk/src/client/dojox/gfx/Mover.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.1 KB
Line 
1define(["dojo/_base/lang","dojo/_base/array", "dojo/_base/declare", "dojo/on", "dojo/touch", "dojo/_base/event"],
2  function(lang, arr, declare, on, touch, event){
3        return declare("dojox.gfx.Mover", null, {
4                constructor: function(shape, e, host){
5                        // summary:
6                        //              an object, which makes a shape follow the mouse,
7                        //              used as a default mover, and as a base class for custom movers
8                        // shape: dojox/gfx.Shape
9                        //              a shape object to be moved
10                        // e: Event
11                        //              a mouse event, which started the move;
12                        //              only clientX and clientY properties are used
13                        // host: Object?
14                        //              object which implements the functionality of the move,
15                        //               and defines proper events (onMoveStart and onMoveStop)
16                        this.shape = shape;
17                        this.lastX = e.clientX;
18                        this.lastY = e.clientY;
19                        var h = this.host = host, d = document,
20                                firstEvent = on(d, touch.move, lang.hitch(this, "onFirstMove"));
21                        this.events = [
22                                on(d, touch.move, lang.hitch(this, "onMouseMove")),
23                                on(d, touch.release, lang.hitch(this, "destroy")),
24                                // cancel text selection and text dragging
25                                on(d, "dragstart",   lang.hitch(event, "stop")),
26                                on(d, "selectstart", lang.hitch(event, "stop")),
27                                firstEvent
28                        ];
29                        // notify that the move has started
30                        if(h && h.onMoveStart){
31                                h.onMoveStart(this);
32                        }
33                },
34                // mouse event processors
35                onMouseMove: function(e){
36                        // summary:
37                        //              event processor for onmousemove
38                        // e: Event
39                        //              mouse event
40                        var x = e.clientX;
41                        var y = e.clientY;
42                        this.host.onMove(this, {dx: x - this.lastX, dy: y - this.lastY});
43                        this.lastX = x;
44                        this.lastY = y;
45                        event.stop(e);
46                },
47                // utilities
48                onFirstMove: function(){
49                        // summary:
50                        //              it is meant to be called only once
51                        this.host.onFirstMove(this);
52                        this.events.pop().remove();
53                },
54                destroy: function(){
55                        // summary:
56                        //              stops the move, deletes all references, so the object can be garbage-collected
57                        arr.forEach(this.events, function(handle){
58                                handle.remove();
59                        });
60                        // undo global settings
61                        var h = this.host;
62                        if(h && h.onMoveStop){
63                                h.onMoveStop(this);
64                        }
65                        // destroy objects
66                        this.events = this.shape = null;
67                }
68        });
69});
Note: See TracBrowser for help on using the repository browser.