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 85ad3d82 Assos Assos
/*!
2 503b3f7b Assos Assos
 * jQuery UI Mouse 1.10.2
3
 * http://jqueryui.com
4 85ad3d82 Assos Assos
 *
5 503b3f7b Assos Assos
 * Copyright 2013 jQuery Foundation and other contributors
6
 * Released under the MIT license.
7 85ad3d82 Assos Assos
 * http://jquery.org/license
8
 *
9 503b3f7b Assos Assos
 * http://api.jqueryui.com/mouse/
10 85ad3d82 Assos Assos
 *
11
 * Depends:
12
 *        jquery.ui.widget.js
13
 */
14
(function( $, undefined ) {
15
16 503b3f7b Assos Assos
var mouseHandled = false;
17
$( document ).mouseup( function() {
18
        mouseHandled = false;
19
});
20
21 85ad3d82 Assos Assos
$.widget("ui.mouse", {
22 503b3f7b Assos Assos
        version: "1.10.2",
23 85ad3d82 Assos Assos
        options: {
24 503b3f7b Assos Assos
                cancel: "input,textarea,button,select,option",
25 85ad3d82 Assos Assos
                distance: 1,
26
                delay: 0
27
        },
28
        _mouseInit: function() {
29 503b3f7b Assos Assos
                var that = this;
30 85ad3d82 Assos Assos
31
                this.element
32 503b3f7b Assos Assos
                        .bind("mousedown."+this.widgetName, function(event) {
33
                                return that._mouseDown(event);
34 85ad3d82 Assos Assos
                        })
35 503b3f7b Assos Assos
                        .bind("click."+this.widgetName, function(event) {
36
                                if (true === $.data(event.target, that.widgetName + ".preventClickEvent")) {
37
                                        $.removeData(event.target, that.widgetName + ".preventClickEvent");
38 85ad3d82 Assos Assos
                                        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 503b3f7b Assos Assos
                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 85ad3d82 Assos Assos
        },
56
57
        _mouseDown: function(event) {
58
                // don't let more than one widget handle mouseStart
59 503b3f7b Assos Assos
                if( mouseHandled ) { return; }
60 85ad3d82 Assos Assos
61
                // we may have missed mouseup (out of window)
62
                (this._mouseStarted && this._mouseUp(event));
63
64
                this._mouseDownEvent = event;
65
66 503b3f7b Assos Assos
                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 85ad3d82 Assos Assos
                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 503b3f7b Assos Assos
                                that.mouseDelayMet = true;
79 85ad3d82 Assos Assos
                        }, 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 503b3f7b Assos Assos
                if (true === $.data(event.target, this.widgetName + ".preventClickEvent")) {
92
                        $.removeData(event.target, this.widgetName + ".preventClickEvent");
93 85ad3d82 Assos Assos
                }
94
95
                // these delegates are required to keep context
96
                this._mouseMoveDelegate = function(event) {
97 503b3f7b Assos Assos
                        return that._mouseMove(event);
98 85ad3d82 Assos Assos
                };
99
                this._mouseUpDelegate = function(event) {
100 503b3f7b Assos Assos
                        return that._mouseUp(event);
101 85ad3d82 Assos Assos
                };
102
                $(document)
103 503b3f7b Assos Assos
                        .bind("mousemove."+this.widgetName, this._mouseMoveDelegate)
104
                        .bind("mouseup."+this.widgetName, this._mouseUpDelegate);
105 85ad3d82 Assos Assos
106
                event.preventDefault();
107 503b3f7b Assos Assos
108
                mouseHandled = true;
109 85ad3d82 Assos Assos
                return true;
110
        },
111
112
        _mouseMove: function(event) {
113
                // IE mouseup check - mouseup happened when mouse was out of window
114 503b3f7b Assos Assos
                if ($.ui.ie && ( !document.documentMode || document.documentMode < 9 ) && !event.button) {
115 85ad3d82 Assos Assos
                        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 503b3f7b Assos Assos
                        .unbind("mousemove."+this.widgetName, this._mouseMoveDelegate)
135
                        .unbind("mouseup."+this.widgetName, this._mouseUpDelegate);
136 85ad3d82 Assos Assos
137
                if (this._mouseStarted) {
138
                        this._mouseStarted = false;
139
140 503b3f7b Assos Assos
                        if (event.target === this._mouseDownEvent.target) {
141
                                $.data(event.target, this.widgetName + ".preventClickEvent", true);
142 85ad3d82 Assos Assos
                        }
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 503b3f7b Assos Assos
        _mouseDelayMet: function(/* event */) {
159 85ad3d82 Assos Assos
                return this.mouseDelayMet;
160
        },
161
162
        // These are placeholder methods, to be overriden by extending plugin
163 503b3f7b Assos Assos
        _mouseStart: function(/* event */) {},
164
        _mouseDrag: function(/* event */) {},
165
        _mouseStop: function(/* event */) {},
166
        _mouseCapture: function(/* event */) { return true; }
167 85ad3d82 Assos Assos
});
168
169
})(jQuery);