corrade-http-templates – Blame information for rev 57
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
57 | office | 1 | /*! |
2 | * jQuery UI Selectable 1.12.1 |
||
3 | * http://jqueryui.com |
||
4 | * |
||
5 | * Copyright jQuery Foundation and other contributors |
||
6 | * Released under the MIT license. |
||
7 | * http://jquery.org/license |
||
8 | */ |
||
9 | |||
10 | //>>label: Selectable |
||
11 | //>>group: Interactions |
||
12 | //>>description: Allows groups of elements to be selected with the mouse. |
||
13 | //>>docs: http://api.jqueryui.com/selectable/ |
||
14 | //>>demos: http://jqueryui.com/selectable/ |
||
15 | //>>css.structure: ../../themes/base/selectable.css |
||
16 | |||
17 | ( function( factory ) { |
||
18 | if ( typeof define === "function" && define.amd ) { |
||
19 | |||
20 | // AMD. Register as an anonymous module. |
||
21 | define( [ |
||
22 | "jquery", |
||
23 | "./mouse", |
||
24 | "../version", |
||
25 | "../widget" |
||
26 | ], factory ); |
||
27 | } else { |
||
28 | |||
29 | // Browser globals |
||
30 | factory( jQuery ); |
||
31 | } |
||
32 | }( function( $ ) { |
||
33 | |||
34 | return $.widget( "ui.selectable", $.ui.mouse, { |
||
35 | version: "1.12.1", |
||
36 | options: { |
||
37 | appendTo: "body", |
||
38 | autoRefresh: true, |
||
39 | distance: 0, |
||
40 | filter: "*", |
||
41 | tolerance: "touch", |
||
42 | |||
43 | // Callbacks |
||
44 | selected: null, |
||
45 | selecting: null, |
||
46 | start: null, |
||
47 | stop: null, |
||
48 | unselected: null, |
||
49 | unselecting: null |
||
50 | }, |
||
51 | _create: function() { |
||
52 | var that = this; |
||
53 | |||
54 | this._addClass( "ui-selectable" ); |
||
55 | |||
56 | this.dragged = false; |
||
57 | |||
58 | // Cache selectee children based on filter |
||
59 | this.refresh = function() { |
||
60 | that.elementPos = $( that.element[ 0 ] ).offset(); |
||
61 | that.selectees = $( that.options.filter, that.element[ 0 ] ); |
||
62 | that._addClass( that.selectees, "ui-selectee" ); |
||
63 | that.selectees.each( function() { |
||
64 | var $this = $( this ), |
||
65 | selecteeOffset = $this.offset(), |
||
66 | pos = { |
||
67 | left: selecteeOffset.left - that.elementPos.left, |
||
68 | top: selecteeOffset.top - that.elementPos.top |
||
69 | }; |
||
70 | $.data( this, "selectable-item", { |
||
71 | element: this, |
||
72 | $element: $this, |
||
73 | left: pos.left, |
||
74 | top: pos.top, |
||
75 | right: pos.left + $this.outerWidth(), |
||
76 | bottom: pos.top + $this.outerHeight(), |
||
77 | startselected: false, |
||
78 | selected: $this.hasClass( "ui-selected" ), |
||
79 | selecting: $this.hasClass( "ui-selecting" ), |
||
80 | unselecting: $this.hasClass( "ui-unselecting" ) |
||
81 | } ); |
||
82 | } ); |
||
83 | }; |
||
84 | this.refresh(); |
||
85 | |||
86 | this._mouseInit(); |
||
87 | |||
88 | this.helper = $( "<div>" ); |
||
89 | this._addClass( this.helper, "ui-selectable-helper" ); |
||
90 | }, |
||
91 | |||
92 | _destroy: function() { |
||
93 | this.selectees.removeData( "selectable-item" ); |
||
94 | this._mouseDestroy(); |
||
95 | }, |
||
96 | |||
97 | _mouseStart: function( event ) { |
||
98 | var that = this, |
||
99 | options = this.options; |
||
100 | |||
101 | this.opos = [ event.pageX, event.pageY ]; |
||
102 | this.elementPos = $( this.element[ 0 ] ).offset(); |
||
103 | |||
104 | if ( this.options.disabled ) { |
||
105 | return; |
||
106 | } |
||
107 | |||
108 | this.selectees = $( options.filter, this.element[ 0 ] ); |
||
109 | |||
110 | this._trigger( "start", event ); |
||
111 | |||
112 | $( options.appendTo ).append( this.helper ); |
||
113 | |||
114 | // position helper (lasso) |
||
115 | this.helper.css( { |
||
116 | "left": event.pageX, |
||
117 | "top": event.pageY, |
||
118 | "width": 0, |
||
119 | "height": 0 |
||
120 | } ); |
||
121 | |||
122 | if ( options.autoRefresh ) { |
||
123 | this.refresh(); |
||
124 | } |
||
125 | |||
126 | this.selectees.filter( ".ui-selected" ).each( function() { |
||
127 | var selectee = $.data( this, "selectable-item" ); |
||
128 | selectee.startselected = true; |
||
129 | if ( !event.metaKey && !event.ctrlKey ) { |
||
130 | that._removeClass( selectee.$element, "ui-selected" ); |
||
131 | selectee.selected = false; |
||
132 | that._addClass( selectee.$element, "ui-unselecting" ); |
||
133 | selectee.unselecting = true; |
||
134 | |||
135 | // selectable UNSELECTING callback |
||
136 | that._trigger( "unselecting", event, { |
||
137 | unselecting: selectee.element |
||
138 | } ); |
||
139 | } |
||
140 | } ); |
||
141 | |||
142 | $( event.target ).parents().addBack().each( function() { |
||
143 | var doSelect, |
||
144 | selectee = $.data( this, "selectable-item" ); |
||
145 | if ( selectee ) { |
||
146 | doSelect = ( !event.metaKey && !event.ctrlKey ) || |
||
147 | !selectee.$element.hasClass( "ui-selected" ); |
||
148 | that._removeClass( selectee.$element, doSelect ? "ui-unselecting" : "ui-selected" ) |
||
149 | ._addClass( selectee.$element, doSelect ? "ui-selecting" : "ui-unselecting" ); |
||
150 | selectee.unselecting = !doSelect; |
||
151 | selectee.selecting = doSelect; |
||
152 | selectee.selected = doSelect; |
||
153 | |||
154 | // selectable (UN)SELECTING callback |
||
155 | if ( doSelect ) { |
||
156 | that._trigger( "selecting", event, { |
||
157 | selecting: selectee.element |
||
158 | } ); |
||
159 | } else { |
||
160 | that._trigger( "unselecting", event, { |
||
161 | unselecting: selectee.element |
||
162 | } ); |
||
163 | } |
||
164 | return false; |
||
165 | } |
||
166 | } ); |
||
167 | |||
168 | }, |
||
169 | |||
170 | _mouseDrag: function( event ) { |
||
171 | |||
172 | this.dragged = true; |
||
173 | |||
174 | if ( this.options.disabled ) { |
||
175 | return; |
||
176 | } |
||
177 | |||
178 | var tmp, |
||
179 | that = this, |
||
180 | options = this.options, |
||
181 | x1 = this.opos[ 0 ], |
||
182 | y1 = this.opos[ 1 ], |
||
183 | x2 = event.pageX, |
||
184 | y2 = event.pageY; |
||
185 | |||
186 | if ( x1 > x2 ) { tmp = x2; x2 = x1; x1 = tmp; } |
||
187 | if ( y1 > y2 ) { tmp = y2; y2 = y1; y1 = tmp; } |
||
188 | this.helper.css( { left: x1, top: y1, width: x2 - x1, height: y2 - y1 } ); |
||
189 | |||
190 | this.selectees.each( function() { |
||
191 | var selectee = $.data( this, "selectable-item" ), |
||
192 | hit = false, |
||
193 | offset = {}; |
||
194 | |||
195 | //prevent helper from being selected if appendTo: selectable |
||
196 | if ( !selectee || selectee.element === that.element[ 0 ] ) { |
||
197 | return; |
||
198 | } |
||
199 | |||
200 | offset.left = selectee.left + that.elementPos.left; |
||
201 | offset.right = selectee.right + that.elementPos.left; |
||
202 | offset.top = selectee.top + that.elementPos.top; |
||
203 | offset.bottom = selectee.bottom + that.elementPos.top; |
||
204 | |||
205 | if ( options.tolerance === "touch" ) { |
||
206 | hit = ( !( offset.left > x2 || offset.right < x1 || offset.top > y2 || |
||
207 | offset.bottom < y1 ) ); |
||
208 | } else if ( options.tolerance === "fit" ) { |
||
209 | hit = ( offset.left > x1 && offset.right < x2 && offset.top > y1 && |
||
210 | offset.bottom < y2 ); |
||
211 | } |
||
212 | |||
213 | if ( hit ) { |
||
214 | |||
215 | // SELECT |
||
216 | if ( selectee.selected ) { |
||
217 | that._removeClass( selectee.$element, "ui-selected" ); |
||
218 | selectee.selected = false; |
||
219 | } |
||
220 | if ( selectee.unselecting ) { |
||
221 | that._removeClass( selectee.$element, "ui-unselecting" ); |
||
222 | selectee.unselecting = false; |
||
223 | } |
||
224 | if ( !selectee.selecting ) { |
||
225 | that._addClass( selectee.$element, "ui-selecting" ); |
||
226 | selectee.selecting = true; |
||
227 | |||
228 | // selectable SELECTING callback |
||
229 | that._trigger( "selecting", event, { |
||
230 | selecting: selectee.element |
||
231 | } ); |
||
232 | } |
||
233 | } else { |
||
234 | |||
235 | // UNSELECT |
||
236 | if ( selectee.selecting ) { |
||
237 | if ( ( event.metaKey || event.ctrlKey ) && selectee.startselected ) { |
||
238 | that._removeClass( selectee.$element, "ui-selecting" ); |
||
239 | selectee.selecting = false; |
||
240 | that._addClass( selectee.$element, "ui-selected" ); |
||
241 | selectee.selected = true; |
||
242 | } else { |
||
243 | that._removeClass( selectee.$element, "ui-selecting" ); |
||
244 | selectee.selecting = false; |
||
245 | if ( selectee.startselected ) { |
||
246 | that._addClass( selectee.$element, "ui-unselecting" ); |
||
247 | selectee.unselecting = true; |
||
248 | } |
||
249 | |||
250 | // selectable UNSELECTING callback |
||
251 | that._trigger( "unselecting", event, { |
||
252 | unselecting: selectee.element |
||
253 | } ); |
||
254 | } |
||
255 | } |
||
256 | if ( selectee.selected ) { |
||
257 | if ( !event.metaKey && !event.ctrlKey && !selectee.startselected ) { |
||
258 | that._removeClass( selectee.$element, "ui-selected" ); |
||
259 | selectee.selected = false; |
||
260 | |||
261 | that._addClass( selectee.$element, "ui-unselecting" ); |
||
262 | selectee.unselecting = true; |
||
263 | |||
264 | // selectable UNSELECTING callback |
||
265 | that._trigger( "unselecting", event, { |
||
266 | unselecting: selectee.element |
||
267 | } ); |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | } ); |
||
272 | |||
273 | return false; |
||
274 | }, |
||
275 | |||
276 | _mouseStop: function( event ) { |
||
277 | var that = this; |
||
278 | |||
279 | this.dragged = false; |
||
280 | |||
281 | $( ".ui-unselecting", this.element[ 0 ] ).each( function() { |
||
282 | var selectee = $.data( this, "selectable-item" ); |
||
283 | that._removeClass( selectee.$element, "ui-unselecting" ); |
||
284 | selectee.unselecting = false; |
||
285 | selectee.startselected = false; |
||
286 | that._trigger( "unselected", event, { |
||
287 | unselected: selectee.element |
||
288 | } ); |
||
289 | } ); |
||
290 | $( ".ui-selecting", this.element[ 0 ] ).each( function() { |
||
291 | var selectee = $.data( this, "selectable-item" ); |
||
292 | that._removeClass( selectee.$element, "ui-selecting" ) |
||
293 | ._addClass( selectee.$element, "ui-selected" ); |
||
294 | selectee.selecting = false; |
||
295 | selectee.selected = true; |
||
296 | selectee.startselected = true; |
||
297 | that._trigger( "selected", event, { |
||
298 | selected: selectee.element |
||
299 | } ); |
||
300 | } ); |
||
301 | this._trigger( "stop", event ); |
||
302 | |||
303 | this.helper.remove(); |
||
304 | |||
305 | return false; |
||
306 | } |
||
307 | |||
308 | } ); |
||
309 | |||
310 | } ) ); |