~yoboy-leguesh/ubuntu-fr-doc/maj20150810a

« back to all changes in this revision

Viewing changes to lib/scripts/drag.js

  • Committer: YoBoY
  • Date: 2015-11-11 10:05:14 UTC
  • Revision ID: yoboy.leguesh@gmail.com-20151111100514-bw7p06lrhban4g2t
Mise à jour vers Dokuwiki 2015-08-10a avec nos patchs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Makes a DOM object draggable
3
 
 *
4
 
 * If you just want to move objects around, use drag.attach. For full
5
 
 * customization, drag can be used as a javascript prototype, it is
6
 
 * inheritance-aware.
7
 
 *
8
 
 * @deprecated
9
 
 * @link http://nofunc.org/Drag_Drop/
10
 
 */
11
 
var drag = {
12
 
    obj: null,
13
 
    handle: null,
14
 
    oX: 0,  // object X position
15
 
    oY: 0,  // object Y position
16
 
    eX: 0,  // event X delta
17
 
    eY: 0,  // event Y delta
18
 
 
19
 
    /**
20
 
     * Attaches the needed handlers to the given object
21
 
     *
22
 
     * This can be called for multiple objects, the right one is later
23
 
     * determined from the event itself. The handle is optional
24
 
     *
25
 
     * @param DOMObject obj    The object that should be draggable
26
 
     * @param DOMObject handle A handle on which the obj can be dragged
27
 
     */
28
 
    attach: function (obj,handle) {
29
 
        DEPRECATED('Use jQuery.draggable() instead.');
30
 
        if(handle){
31
 
            handle.dragobject = obj;
32
 
        }else{
33
 
            handle = obj;
34
 
        }
35
 
        var _this = this;
36
 
        addEvent($(handle),'mousedown',function (e) {return _this.start(e); });
37
 
    },
38
 
 
39
 
    /**
40
 
     * Starts the dragging operation
41
 
     */
42
 
    start: function (e){
43
 
        this.handle = e.target;
44
 
        if(this.handle.dragobject){
45
 
            this.obj = this.handle.dragobject;
46
 
        }else{
47
 
            this.obj = this.handle;
48
 
        }
49
 
 
50
 
        this.handle.className += ' ondrag';
51
 
        this.obj.className    += ' ondrag';
52
 
 
53
 
        this.oX = parseInt(this.obj.style.left);
54
 
        this.oY = parseInt(this.obj.style.top);
55
 
        this.eX = e.pageX;
56
 
        this.eY = e.pageY;
57
 
 
58
 
        var _this = this;
59
 
        this.mousehandlers = [function (e) {return _this.drag(e);}, function (e) {return _this.stop(e);}];
60
 
        addEvent(document,'mousemove', this.mousehandlers[0]);
61
 
        addEvent(document,'mouseup', this.mousehandlers[1]);
62
 
 
63
 
        return false;
64
 
    },
65
 
 
66
 
    /**
67
 
     * Ends the dragging operation
68
 
     */
69
 
    stop: function(){
70
 
        this.handle.className = this.handle.className.replace(/ ?ondrag/,'');
71
 
        this.obj.className    = this.obj.className.replace(/ ?ondrag/,'');
72
 
        removeEvent(document,'mousemove', this.mousehandlers[0]);
73
 
        removeEvent(document,'mouseup', this.mousehandlers[1]);
74
 
        this.obj = null;
75
 
        this.handle = null;
76
 
    },
77
 
 
78
 
    /**
79
 
     * Moves the object during the dragging operation
80
 
     */
81
 
    drag: function(e) {
82
 
        if(this.obj) {
83
 
            this.obj.style.top  = (e.pageY+this.oY-this.eY+'px');
84
 
            this.obj.style.left = (e.pageX+this.oX-this.eX+'px');
85
 
        }
86
 
    }
87
 
};