Projet

Général

Profil

Paste
Télécharger (4,45 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / jquery_update / replace / ui / ui / jquery.ui.mouse.js @ 503b3f7b

1
/*!
2
 * jQuery UI Mouse 1.10.2
3
 * http://jqueryui.com
4
 *
5
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
7
 * http://jquery.org/license
8
 *
9
 * http://api.jqueryui.com/mouse/
10
 *
11
 * Depends:
12
 *        jquery.ui.widget.js
13
 */
14
(function( $, undefined ) {
15

    
16
var mouseHandled = false;
17
$( document ).mouseup( function() {
18
        mouseHandled = false;
19
});
20

    
21
$.widget("ui.mouse", {
22
        version: "1.10.2",
23
        options: {
24
                cancel: "input,textarea,button,select,option",
25
                distance: 1,
26
                delay: 0
27
        },
28
        _mouseInit: function() {
29
                var that = this;
30

    
31
                this.element
32
                        .bind("mousedown."+this.widgetName, function(event) {
33
                                return that._mouseDown(event);
34
                        })
35
                        .bind("click."+this.widgetName, function(event) {
36
                                if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
37
                                        $.removeData(event.target, that.widgetName + ".preventClickEvent");
38
                                        event.stopImmediatePropagation();
39
                                        return false;
40
                                }
41
                        });
42

    
43
                this.started = false;
44
        },
45

    
46
        // TODO: make sure destroying one instance of mouse doesn't mess with
47
        // other instances of mouse
48
        _mouseDestroy: function() {
49
                this.element.unbind("."+this.widgetName);
50
                if ( this._mouseMoveDelegate ) {
51
                        $(document)
52
                                .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
53
                                .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
54
                }
55
        },
56

    
57
        _mouseDown: function(event) {
58
                // don't let more than one widget handle mouseStart
59
                if( mouseHandled ) { return; }
60

    
61
                // we may have missed mouseup (out of window)
62
                (this._mouseStarted && this._mouseUp(event));
63

    
64
                this._mouseDownEvent = event;
65

    
66
                var that = this,
67
                        btnIsLeft = (event.which === 1),
68
                        // event.target.nodeName works around a bug in IE 8 with
69
                        // disabled inputs (#7620)
70
                        elIsCancel = (typeof this.options.cancel === "string" && event.target.nodeName ? $(event.target).closest(this.options.cancel).length : false);
71
                if (!btnIsLeft || elIsCancel || !this._mouseCapture(event)) {
72
                        return true;
73
                }
74

    
75
                this.mouseDelayMet = !this.options.delay;
76
                if (!this.mouseDelayMet) {
77
                        this._mouseDelayTimer = setTimeout(function() {
78
                                that.mouseDelayMet = true;
79
                        }, this.options.delay);
80
                }
81

    
82
                if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
83
                        this._mouseStarted = (this._mouseStart(event) !== false);
84
                        if (!this._mouseStarted) {
85
                                event.preventDefault();
86
                                return true;
87
                        }
88
                }
89

    
90
                // Click event may never have fired (Gecko & Opera)
91
                if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
92
                        $.removeData(event.target, this.widgetName + ".preventClickEvent");
93
                }
94

    
95
                // these delegates are required to keep context
96
                this._mouseMoveDelegate = function(event) {
97
                        return that._mouseMove(event);
98
                };
99
                this._mouseUpDelegate = function(event) {
100
                        return that._mouseUp(event);
101
                };
102
                $(document)
103
                        .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
104
                        .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
105

    
106
                event.preventDefault();
107

    
108
                mouseHandled = true;
109
                return true;
110
        },
111

    
112
        _mouseMove: function(event) {
113
                // IE mouseup check - mouseup happened when mouse was out of window
114
                if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
115
                        return this._mouseUp(event);
116
                }
117

    
118
                if (this._mouseStarted) {
119
                        this._mouseDrag(event);
120
                        return event.preventDefault();
121
                }
122

    
123
                if (this._mouseDistanceMet(event) && this._mouseDelayMet(event)) {
124
                        this._mouseStarted =
125
                                (this._mouseStart(this._mouseDownEvent, event) !== false);
126
                        (this._mouseStarted ? this._mouseDrag(event) : this._mouseUp(event));
127
                }
128

    
129
                return !this._mouseStarted;
130
        },
131

    
132
        _mouseUp: function(event) {
133
                $(document)
134
                        .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
135
                        .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
136

    
137
                if (this._mouseStarted) {
138
                        this._mouseStarted = false;
139

    
140
                        if (event.target === this._mouseDownEvent.target) {
141
                                $.data(event.target, this.widgetName + ".preventClickEvent", true);
142
                        }
143

    
144
                        this._mouseStop(event);
145
                }
146

    
147
                return false;
148
        },
149

    
150
        _mouseDistanceMet: function(event) {
151
                return (Math.max(
152
                                Math.abs(this._mouseDownEvent.pageX - event.pageX),
153
                                Math.abs(this._mouseDownEvent.pageY - event.pageY)
154
                        ) >= this.options.distance
155
                );
156
        },
157

    
158
        _mouseDelayMet: function(/* event */) {
159
                return this.mouseDelayMet;
160
        },
161

    
162
        // These are placeholder methods, to be overriden by extending plugin
163
        _mouseStart: function(/* event */) {},
164
        _mouseDrag: function(/* event */) {},
165
        _mouseStop: function(/* event */) {},
166
        _mouseCapture: function(/* event */) { return true; }
167
});
168

    
169
})(jQuery);