Révision 503b3f7b
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/jquery_update/replace/ui/ui/jquery.ui.selectable.js | ||
---|---|---|
1 |
/* |
|
2 |
* jQuery UI Selectable 1.8.11 |
|
1 |
/*! |
|
2 |
* jQuery UI Selectable 1.10.2 |
|
3 |
* http://jqueryui.com |
|
3 | 4 |
* |
4 |
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
|
5 |
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
5 |
* Copyright 2013 jQuery Foundation and other contributors
|
|
6 |
* Released under the MIT license.
|
|
6 | 7 |
* http://jquery.org/license |
7 | 8 |
* |
8 |
* http://docs.jquery.com/UI/Selectables
|
|
9 |
* http://api.jqueryui.com/selectable/
|
|
9 | 10 |
* |
10 | 11 |
* Depends: |
11 | 12 |
* jquery.ui.core.js |
... | ... | |
15 | 16 |
(function( $, undefined ) { |
16 | 17 |
|
17 | 18 |
$.widget("ui.selectable", $.ui.mouse, { |
19 |
version: "1.10.2", |
|
18 | 20 |
options: { |
19 |
appendTo: 'body',
|
|
21 |
appendTo: "body",
|
|
20 | 22 |
autoRefresh: true, |
21 | 23 |
distance: 0, |
22 |
filter: '*', |
|
23 |
tolerance: 'touch' |
|
24 |
filter: "*", |
|
25 |
tolerance: "touch", |
|
26 |
|
|
27 |
// callbacks |
|
28 |
selected: null, |
|
29 |
selecting: null, |
|
30 |
start: null, |
|
31 |
stop: null, |
|
32 |
unselected: null, |
|
33 |
unselecting: null |
|
24 | 34 |
}, |
25 | 35 |
_create: function() { |
26 |
var self = this; |
|
36 |
var selectees, |
|
37 |
that = this; |
|
27 | 38 |
|
28 | 39 |
this.element.addClass("ui-selectable"); |
29 | 40 |
|
30 | 41 |
this.dragged = false; |
31 | 42 |
|
32 | 43 |
// cache selectee children based on filter |
33 |
var selectees; |
|
34 | 44 |
this.refresh = function() { |
35 |
selectees = $(self.options.filter, self.element[0]); |
|
45 |
selectees = $(that.options.filter, that.element[0]); |
|
46 |
selectees.addClass("ui-selectee"); |
|
36 | 47 |
selectees.each(function() { |
37 |
var $this = $(this);
|
|
38 |
var pos = $this.offset();
|
|
48 |
var $this = $(this),
|
|
49 |
pos = $this.offset();
|
|
39 | 50 |
$.data(this, "selectable-item", { |
40 | 51 |
element: this, |
41 | 52 |
$element: $this, |
... | ... | |
44 | 55 |
right: pos.left + $this.outerWidth(), |
45 | 56 |
bottom: pos.top + $this.outerHeight(), |
46 | 57 |
startselected: false, |
47 |
selected: $this.hasClass('ui-selected'),
|
|
48 |
selecting: $this.hasClass('ui-selecting'),
|
|
49 |
unselecting: $this.hasClass('ui-unselecting')
|
|
58 |
selected: $this.hasClass("ui-selected"),
|
|
59 |
selecting: $this.hasClass("ui-selecting"),
|
|
60 |
unselecting: $this.hasClass("ui-unselecting")
|
|
50 | 61 |
}); |
51 | 62 |
}); |
52 | 63 |
}; |
... | ... | |
59 | 70 |
this.helper = $("<div class='ui-selectable-helper'></div>"); |
60 | 71 |
}, |
61 | 72 |
|
62 |
destroy: function() { |
|
73 |
_destroy: function() {
|
|
63 | 74 |
this.selectees |
64 | 75 |
.removeClass("ui-selectee") |
65 | 76 |
.removeData("selectable-item"); |
66 | 77 |
this.element |
67 |
.removeClass("ui-selectable ui-selectable-disabled") |
|
68 |
.removeData("selectable") |
|
69 |
.unbind(".selectable"); |
|
78 |
.removeClass("ui-selectable ui-selectable-disabled"); |
|
70 | 79 |
this._mouseDestroy(); |
71 |
|
|
72 |
return this; |
|
73 | 80 |
}, |
74 | 81 |
|
75 | 82 |
_mouseStart: function(event) { |
76 |
var self = this; |
|
83 |
var that = this, |
|
84 |
options = this.options; |
|
77 | 85 |
|
78 | 86 |
this.opos = [event.pageX, event.pageY]; |
79 | 87 |
|
80 |
if (this.options.disabled) |
|
88 |
if (this.options.disabled) {
|
|
81 | 89 |
return; |
82 |
|
|
83 |
var options = this.options; |
|
90 |
} |
|
84 | 91 |
|
85 | 92 |
this.selectees = $(options.filter, this.element[0]); |
86 | 93 |
|
... | ... | |
89 | 96 |
$(options.appendTo).append(this.helper); |
90 | 97 |
// position helper (lasso) |
91 | 98 |
this.helper.css({ |
92 |
"left": event.clientX,
|
|
93 |
"top": event.clientY,
|
|
99 |
"left": event.pageX,
|
|
100 |
"top": event.pageY,
|
|
94 | 101 |
"width": 0, |
95 | 102 |
"height": 0 |
96 | 103 |
}); |
... | ... | |
99 | 106 |
this.refresh(); |
100 | 107 |
} |
101 | 108 |
|
102 |
this.selectees.filter('.ui-selected').each(function() {
|
|
109 |
this.selectees.filter(".ui-selected").each(function() {
|
|
103 | 110 |
var selectee = $.data(this, "selectable-item"); |
104 | 111 |
selectee.startselected = true; |
105 |
if (!event.metaKey) { |
|
106 |
selectee.$element.removeClass('ui-selected');
|
|
112 |
if (!event.metaKey && !event.ctrlKey) {
|
|
113 |
selectee.$element.removeClass("ui-selected");
|
|
107 | 114 |
selectee.selected = false; |
108 |
selectee.$element.addClass('ui-unselecting');
|
|
115 |
selectee.$element.addClass("ui-unselecting");
|
|
109 | 116 |
selectee.unselecting = true; |
110 | 117 |
// selectable UNSELECTING callback |
111 |
self._trigger("unselecting", event, {
|
|
118 |
that._trigger("unselecting", event, {
|
|
112 | 119 |
unselecting: selectee.element |
113 | 120 |
}); |
114 | 121 |
} |
115 | 122 |
}); |
116 | 123 |
|
117 |
$(event.target).parents().andSelf().each(function() { |
|
118 |
var selectee = $.data(this, "selectable-item"); |
|
124 |
$(event.target).parents().addBack().each(function() { |
|
125 |
var doSelect, |
|
126 |
selectee = $.data(this, "selectable-item"); |
|
119 | 127 |
if (selectee) { |
120 |
var doSelect = !event.metaKey || !selectee.$element.hasClass('ui-selected');
|
|
128 |
doSelect = (!event.metaKey && !event.ctrlKey) || !selectee.$element.hasClass("ui-selected");
|
|
121 | 129 |
selectee.$element |
122 | 130 |
.removeClass(doSelect ? "ui-unselecting" : "ui-selected") |
123 | 131 |
.addClass(doSelect ? "ui-selecting" : "ui-unselecting"); |
... | ... | |
126 | 134 |
selectee.selected = doSelect; |
127 | 135 |
// selectable (UN)SELECTING callback |
128 | 136 |
if (doSelect) { |
129 |
self._trigger("selecting", event, {
|
|
137 |
that._trigger("selecting", event, {
|
|
130 | 138 |
selecting: selectee.element |
131 | 139 |
}); |
132 | 140 |
} else { |
133 |
self._trigger("unselecting", event, {
|
|
141 |
that._trigger("unselecting", event, {
|
|
134 | 142 |
unselecting: selectee.element |
135 | 143 |
}); |
136 | 144 |
} |
... | ... | |
141 | 149 |
}, |
142 | 150 |
|
143 | 151 |
_mouseDrag: function(event) { |
144 |
var self = this; |
|
152 |
|
|
145 | 153 |
this.dragged = true; |
146 | 154 |
|
147 |
if (this.options.disabled) |
|
155 |
if (this.options.disabled) {
|
|
148 | 156 |
return; |
157 |
} |
|
149 | 158 |
|
150 |
var options = this.options; |
|
159 |
var tmp, |
|
160 |
that = this, |
|
161 |
options = this.options, |
|
162 |
x1 = this.opos[0], |
|
163 |
y1 = this.opos[1], |
|
164 |
x2 = event.pageX, |
|
165 |
y2 = event.pageY; |
|
151 | 166 |
|
152 |
var x1 = this.opos[0], y1 = this.opos[1], x2 = event.pageX, y2 = event.pageY; |
|
153 |
if (x1 > x2) { var tmp = x2; x2 = x1; x1 = tmp; } |
|
154 |
if (y1 > y2) { var tmp = y2; y2 = y1; y1 = tmp; } |
|
167 |
if (x1 > x2) { tmp = x2; x2 = x1; x1 = tmp; } |
|
168 |
if (y1 > y2) { tmp = y2; y2 = y1; y1 = tmp; } |
|
155 | 169 |
this.helper.css({left: x1, top: y1, width: x2-x1, height: y2-y1}); |
156 | 170 |
|
157 | 171 |
this.selectees.each(function() { |
158 |
var selectee = $.data(this, "selectable-item"); |
|
172 |
var selectee = $.data(this, "selectable-item"), |
|
173 |
hit = false; |
|
174 |
|
|
159 | 175 |
//prevent helper from being selected if appendTo: selectable |
160 |
if (!selectee || selectee.element == self.element[0])
|
|
176 |
if (!selectee || selectee.element === that.element[0]) {
|
|
161 | 177 |
return; |
162 |
var hit = false; |
|
163 |
if (options.tolerance == 'touch') { |
|
178 |
} |
|
179 |
|
|
180 |
if (options.tolerance === "touch") { |
|
164 | 181 |
hit = ( !(selectee.left > x2 || selectee.right < x1 || selectee.top > y2 || selectee.bottom < y1) ); |
165 |
} else if (options.tolerance == 'fit') {
|
|
182 |
} else if (options.tolerance === "fit") {
|
|
166 | 183 |
hit = (selectee.left > x1 && selectee.right < x2 && selectee.top > y1 && selectee.bottom < y2); |
167 | 184 |
} |
168 | 185 |
|
169 | 186 |
if (hit) { |
170 | 187 |
// SELECT |
171 | 188 |
if (selectee.selected) { |
172 |
selectee.$element.removeClass('ui-selected');
|
|
189 |
selectee.$element.removeClass("ui-selected");
|
|
173 | 190 |
selectee.selected = false; |
174 | 191 |
} |
175 | 192 |
if (selectee.unselecting) { |
176 |
selectee.$element.removeClass('ui-unselecting');
|
|
193 |
selectee.$element.removeClass("ui-unselecting");
|
|
177 | 194 |
selectee.unselecting = false; |
178 | 195 |
} |
179 | 196 |
if (!selectee.selecting) { |
180 |
selectee.$element.addClass('ui-selecting');
|
|
197 |
selectee.$element.addClass("ui-selecting");
|
|
181 | 198 |
selectee.selecting = true; |
182 | 199 |
// selectable SELECTING callback |
183 |
self._trigger("selecting", event, {
|
|
200 |
that._trigger("selecting", event, {
|
|
184 | 201 |
selecting: selectee.element |
185 | 202 |
}); |
186 | 203 |
} |
187 | 204 |
} else { |
188 | 205 |
// UNSELECT |
189 | 206 |
if (selectee.selecting) { |
190 |
if (event.metaKey && selectee.startselected) {
|
|
191 |
selectee.$element.removeClass('ui-selecting');
|
|
207 |
if ((event.metaKey || event.ctrlKey) && selectee.startselected) {
|
|
208 |
selectee.$element.removeClass("ui-selecting");
|
|
192 | 209 |
selectee.selecting = false; |
193 |
selectee.$element.addClass('ui-selected');
|
|
210 |
selectee.$element.addClass("ui-selected");
|
|
194 | 211 |
selectee.selected = true; |
195 | 212 |
} else { |
196 |
selectee.$element.removeClass('ui-selecting');
|
|
213 |
selectee.$element.removeClass("ui-selecting");
|
|
197 | 214 |
selectee.selecting = false; |
198 | 215 |
if (selectee.startselected) { |
199 |
selectee.$element.addClass('ui-unselecting');
|
|
216 |
selectee.$element.addClass("ui-unselecting");
|
|
200 | 217 |
selectee.unselecting = true; |
201 | 218 |
} |
202 | 219 |
// selectable UNSELECTING callback |
203 |
self._trigger("unselecting", event, {
|
|
220 |
that._trigger("unselecting", event, {
|
|
204 | 221 |
unselecting: selectee.element |
205 | 222 |
}); |
206 | 223 |
} |
207 | 224 |
} |
208 | 225 |
if (selectee.selected) { |
209 |
if (!event.metaKey && !selectee.startselected) { |
|
210 |
selectee.$element.removeClass('ui-selected');
|
|
226 |
if (!event.metaKey && !event.ctrlKey && !selectee.startselected) {
|
|
227 |
selectee.$element.removeClass("ui-selected");
|
|
211 | 228 |
selectee.selected = false; |
212 | 229 |
|
213 |
selectee.$element.addClass('ui-unselecting');
|
|
230 |
selectee.$element.addClass("ui-unselecting");
|
|
214 | 231 |
selectee.unselecting = true; |
215 | 232 |
// selectable UNSELECTING callback |
216 |
self._trigger("unselecting", event, {
|
|
233 |
that._trigger("unselecting", event, {
|
|
217 | 234 |
unselecting: selectee.element |
218 | 235 |
}); |
219 | 236 |
} |
... | ... | |
225 | 242 |
}, |
226 | 243 |
|
227 | 244 |
_mouseStop: function(event) { |
228 |
var self = this;
|
|
245 |
var that = this;
|
|
229 | 246 |
|
230 | 247 |
this.dragged = false; |
231 | 248 |
|
232 |
var options = this.options; |
|
233 |
|
|
234 |
$('.ui-unselecting', this.element[0]).each(function() { |
|
249 |
$(".ui-unselecting", this.element[0]).each(function() { |
|
235 | 250 |
var selectee = $.data(this, "selectable-item"); |
236 |
selectee.$element.removeClass('ui-unselecting');
|
|
251 |
selectee.$element.removeClass("ui-unselecting");
|
|
237 | 252 |
selectee.unselecting = false; |
238 | 253 |
selectee.startselected = false; |
239 |
self._trigger("unselected", event, {
|
|
254 |
that._trigger("unselected", event, {
|
|
240 | 255 |
unselected: selectee.element |
241 | 256 |
}); |
242 | 257 |
}); |
243 |
$('.ui-selecting', this.element[0]).each(function() {
|
|
258 |
$(".ui-selecting", this.element[0]).each(function() {
|
|
244 | 259 |
var selectee = $.data(this, "selectable-item"); |
245 |
selectee.$element.removeClass('ui-selecting').addClass('ui-selected');
|
|
260 |
selectee.$element.removeClass("ui-selecting").addClass("ui-selected");
|
|
246 | 261 |
selectee.selecting = false; |
247 | 262 |
selectee.selected = true; |
248 | 263 |
selectee.startselected = true; |
249 |
self._trigger("selected", event, {
|
|
264 |
that._trigger("selected", event, {
|
|
250 | 265 |
selected: selectee.element |
251 | 266 |
}); |
252 | 267 |
}); |
... | ... | |
259 | 274 |
|
260 | 275 |
}); |
261 | 276 |
|
262 |
$.extend($.ui.selectable, { |
|
263 |
version: "1.8.11" |
|
264 |
}); |
|
265 |
|
|
266 | 277 |
})(jQuery); |
Formats disponibles : Unified diff
Weekly update of contrib modules