Skip to content

Commit 0e80063

Browse files
committed
Dev: Make droppable pass JSHint with no local settings overrides
1 parent 5bae9a4 commit 0e80063

File tree

1 file changed

+135
-71
lines changed

1 file changed

+135
-71
lines changed

ui/jquery.ui.droppable.js

+135-71
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
(function( $, undefined ) {
1818

19-
/*jshint onevar: false, curly: false, eqeqeq: false, laxbreak: true */
2019
$.widget("ui.droppable", {
2120
version: "@VERSION",
2221
widgetEventPrefix: "drop",
@@ -31,8 +30,11 @@ $.widget("ui.droppable", {
3130
},
3231
_create: function() {
3332

34-
var o = this.options, accept = o.accept;
35-
this.isover = 0; this.isout = 1;
33+
var o = this.options,
34+
accept = o.accept;
35+
36+
this.isover = false;
37+
this.isout = true;
3638

3739
this.accept = $.isFunction(accept) ? accept : function(d) {
3840
return d.is(accept);
@@ -50,17 +52,21 @@ $.widget("ui.droppable", {
5052
},
5153

5254
_destroy: function() {
53-
var drop = $.ui.ddmanager.droppables[this.options.scope];
54-
for ( var i = 0; i < drop.length; i++ )
55-
if ( drop[i] == this )
55+
var i = 0,
56+
drop = $.ui.ddmanager.droppables[this.options.scope];
57+
58+
for ( ; i < drop.length; i++ ) {
59+
if ( drop[i] === this ) {
5660
drop.splice(i, 1);
61+
}
62+
}
5763

5864
this.element.removeClass("ui-droppable ui-droppable-disabled");
5965
},
6066

6167
_setOption: function(key, value) {
6268

63-
if(key == 'accept') {
69+
if(key === 'accept') {
6470
this.accept = $.isFunction(value) ? value : function(d) {
6571
return d.is(value);
6672
};
@@ -70,23 +76,37 @@ $.widget("ui.droppable", {
7076

7177
_activate: function(event) {
7278
var draggable = $.ui.ddmanager.current;
73-
if(this.options.activeClass) this.element.addClass(this.options.activeClass);
74-
(draggable && this._trigger('activate', event, this.ui(draggable)));
79+
if(this.options.activeClass) {
80+
this.element.addClass(this.options.activeClass);
81+
}
82+
if(draggable){
83+
this._trigger('activate', event, this.ui(draggable));
84+
}
7585
},
7686

7787
_deactivate: function(event) {
7888
var draggable = $.ui.ddmanager.current;
79-
if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
80-
(draggable && this._trigger('deactivate', event, this.ui(draggable)));
89+
if(this.options.activeClass) {
90+
this.element.removeClass(this.options.activeClass);
91+
}
92+
if(draggable){
93+
this._trigger('deactivate', event, this.ui(draggable));
94+
}
8195
},
8296

8397
_over: function(event) {
8498

8599
var draggable = $.ui.ddmanager.current;
86-
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
100+
101+
// Bail if draggable and droppable are same element
102+
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
103+
return;
104+
}
87105

88106
if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
89-
if(this.options.hoverClass) this.element.addClass(this.options.hoverClass);
107+
if(this.options.hoverClass) {
108+
this.element.addClass(this.options.hoverClass);
109+
}
90110
this._trigger('over', event, this.ui(draggable));
91111
}
92112

@@ -95,36 +115,52 @@ $.widget("ui.droppable", {
95115
_out: function(event) {
96116

97117
var draggable = $.ui.ddmanager.current;
98-
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element
118+
119+
// Bail if draggable and droppable are same element
120+
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
121+
return;
122+
}
99123

100124
if (this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
101-
if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
125+
if(this.options.hoverClass) {
126+
this.element.removeClass(this.options.hoverClass);
127+
}
102128
this._trigger('out', event, this.ui(draggable));
103129
}
104130

105131
},
106132

107133
_drop: function(event,custom) {
108134

109-
var draggable = custom || $.ui.ddmanager.current;
110-
if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element
135+
var draggable = custom || $.ui.ddmanager.current,
136+
childrenIntersection = false;
137+
138+
// Bail if draggable and droppable are same element
139+
if (!draggable || (draggable.currentItem || draggable.element)[0] === this.element[0]) {
140+
return false;
141+
}
111142

112-
var childrenIntersection = false;
113143
this.element.find(":data(ui-droppable)").not(".ui-draggable-dragging").each(function() {
114144
var inst = $.data(this, 'ui-droppable');
115145
if(
116-
inst.options.greedy
117-
&& !inst.options.disabled
118-
&& inst.options.scope == draggable.options.scope
119-
&& inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element))
120-
&& $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
146+
inst.options.greedy &&
147+
!inst.options.disabled &&
148+
inst.options.scope === draggable.options.scope &&
149+
inst.accept.call(inst.element[0], (draggable.currentItem || draggable.element)) &&
150+
$.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)
121151
) { childrenIntersection = true; return false; }
122152
});
123-
if(childrenIntersection) return false;
153+
if(childrenIntersection) {
154+
return false;
155+
}
124156

125157
if(this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
126-
if(this.options.activeClass) this.element.removeClass(this.options.activeClass);
127-
if(this.options.hoverClass) this.element.removeClass(this.options.hoverClass);
158+
if(this.options.activeClass) {
159+
this.element.removeClass(this.options.activeClass);
160+
}
161+
if(this.options.hoverClass) {
162+
this.element.removeClass(this.options.hoverClass);
163+
}
128164
this._trigger('drop', event, this.ui(draggable));
129165
return this.element;
130166
}
@@ -146,27 +182,28 @@ $.widget("ui.droppable", {
146182

147183
$.ui.intersect = function(draggable, droppable, toleranceMode) {
148184

149-
if (!droppable.offset) return false;
185+
if (!droppable.offset) {
186+
return false;
187+
}
150188

151-
var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
152-
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height;
153-
var l = droppable.offset.left, r = l + droppable.proportions.width,
189+
var draggableLeft, draggableTop,
190+
x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width,
191+
y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height,
192+
l = droppable.offset.left, r = l + droppable.proportions.width,
154193
t = droppable.offset.top, b = t + droppable.proportions.height;
155194

156195
switch (toleranceMode) {
157196
case 'fit':
158-
return (l <= x1 && x2 <= r
159-
&& t <= y1 && y2 <= b);
197+
return (l <= x1 && x2 <= r && t <= y1 && y2 <= b);
160198
case 'intersect':
161-
return (l < x1 + (draggable.helperProportions.width / 2) // Right Half
162-
&& x2 - (draggable.helperProportions.width / 2) < r // Left Half
163-
&& t < y1 + (draggable.helperProportions.height / 2) // Bottom Half
164-
&& y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
199+
return (l < x1 + (draggable.helperProportions.width / 2) && // Right Half
200+
x2 - (draggable.helperProportions.width / 2) < r && // Left Half
201+
t < y1 + (draggable.helperProportions.height / 2) && // Bottom Half
202+
y2 - (draggable.helperProportions.height / 2) < b ); // Top Half
165203
case 'pointer':
166-
var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left),
167-
draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top),
168-
isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
169-
return isOver;
204+
draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left);
205+
draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top);
206+
return $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width);
170207
case 'touch':
171208
return (
172209
(y1 >= t && y1 <= b) || // Top edge touching
@@ -191,23 +228,35 @@ $.ui.ddmanager = {
191228
droppables: { 'default': [] },
192229
prepareOffsets: function(t, event) {
193230

194-
var m = $.ui.ddmanager.droppables[t.options.scope] || [];
195-
var type = event ? event.type : null; // workaround for #2317
196-
var list = (t.currentItem || t.element).find(":data(ui-droppable)").andSelf();
231+
var i, j,
232+
m = $.ui.ddmanager.droppables[t.options.scope] || [],
233+
type = event ? event.type : null, // workaround for #2317
234+
list = (t.currentItem || t.element).find(":data(ui-droppable)").andSelf();
197235

198-
droppablesLoop: for (var i = 0; i < m.length; i++) {
236+
droppablesLoop: for (i = 0; i < m.length; i++) {
237+
238+
//No disabled and non-accepted
239+
if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) {
240+
continue;
241+
}
199242

200-
if(m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0],(t.currentItem || t.element)))) continue; //No disabled and non-accepted
201243
// Filter out elements in the current dragged item
202-
for (var j=0; j < list.length; j++) {
203-
if(list[j] == m[i].element[0]) {
244+
for (j=0; j < list.length; j++) {
245+
if(list[j] === m[i].element[0]) {
204246
m[i].proportions.height = 0;
205247
continue droppablesLoop;
206248
}
207249
}
208-
m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue
209250

210-
if(type == "mousedown") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables
251+
m[i].visible = m[i].element.css("display") !== "none";
252+
if(!m[i].visible) {
253+
continue;
254+
}
255+
256+
//Activate the droppable if used directly from draggables
257+
if(type === "mousedown") {
258+
m[i]._activate.call(m[i], event);
259+
}
211260

212261
m[i].offset = m[i].element.offset();
213262
m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
@@ -220,12 +269,16 @@ $.ui.ddmanager = {
220269
var dropped = false;
221270
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
222271

223-
if(!this.options) return;
224-
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance))
272+
if(!this.options) {
273+
return;
274+
}
275+
if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) {
225276
dropped = this._drop.call(this, event) || dropped;
277+
}
226278

227279
if (!this.options.disabled && this.visible && this.accept.call(this.element[0],(draggable.currentItem || draggable.element))) {
228-
this.isout = 1; this.isover = 0;
280+
this.isout = true;
281+
this.isover = false;
229282
this._deactivate.call(this, event);
230283
}
231284

@@ -236,51 +289,60 @@ $.ui.ddmanager = {
236289
dragStart: function( draggable, event ) {
237290
//Listen for scrolling so that if the dragging causes scrolling the position of the droppables can be recalculated (see #5003)
238291
draggable.element.parentsUntil( "body" ).bind( "scroll.droppable", function() {
239-
if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
292+
if( !draggable.options.refreshPositions ) {
293+
$.ui.ddmanager.prepareOffsets( draggable, event );
294+
}
240295
});
241296
},
242297
drag: function(draggable, event) {
243298

244299
//If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse.
245-
if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event);
300+
if(draggable.options.refreshPositions) {
301+
$.ui.ddmanager.prepareOffsets(draggable, event);
302+
}
246303

247304
//Run through all droppables and check their positions based on specific tolerance options
248305
$.each($.ui.ddmanager.droppables[draggable.options.scope] || [], function() {
249306

250-
if(this.options.disabled || this.greedyChild || !this.visible) return;
251-
var intersects = $.ui.intersect(draggable, this, this.options.tolerance);
307+
if(this.options.disabled || this.greedyChild || !this.visible) {
308+
return;
309+
}
252310

253-
var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover === 0 ? 'isover' : null);
254-
if(!c) return;
311+
var parentInstance, scope, parent,
312+
intersects = $.ui.intersect(draggable, this, this.options.tolerance),
313+
c = !intersects && this.isover ? 'isout' : (intersects && !this.isover ? 'isover' : null);
314+
if(!c) {
315+
return;
316+
}
255317

256-
var parentInstance;
257318
if (this.options.greedy) {
258319
// find droppable parents with same scope
259-
var scope = this.options.scope;
260-
var parent = this.element.parents(':data(ui-droppable)').filter(function () {
320+
scope = this.options.scope;
321+
parent = this.element.parents(':data(ui-droppable)').filter(function () {
261322
return $.data(this, 'ui-droppable').options.scope === scope;
262323
});
263324

264325
if (parent.length) {
265326
parentInstance = $.data(parent[0], 'ui-droppable');
266-
parentInstance.greedyChild = (c == 'isover' ? 1 : 0);
327+
parentInstance.greedyChild = (c === 'isover');
267328
}
268329
}
269330

270331
// we just moved into a greedy child
271-
if (parentInstance && c == 'isover') {
272-
parentInstance.isover = 0;
273-
parentInstance.isout = 1;
332+
if (parentInstance && c === 'isover') {
333+
parentInstance.isover = false;
334+
parentInstance.isout = true;
274335
parentInstance._out.call(parentInstance, event);
275336
}
276337

277-
this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0;
278-
this[c == "isover" ? "_over" : "_out"].call(this, event);
338+
this[c] = true;
339+
this[c === 'isout' ? 'isover' : 'isout'] = false;
340+
this[c === "isover" ? "_over" : "_out"].call(this, event);
279341

280342
// we just moved out of a greedy child
281-
if (parentInstance && c == 'isout') {
282-
parentInstance.isout = 0;
283-
parentInstance.isover = 1;
343+
if (parentInstance && c === 'isout') {
344+
parentInstance.isout = false;
345+
parentInstance.isover = true;
284346
parentInstance._over.call(parentInstance, event);
285347
}
286348
});
@@ -289,7 +351,9 @@ $.ui.ddmanager = {
289351
dragStop: function( draggable, event ) {
290352
draggable.element.parentsUntil( "body" ).unbind( "scroll.droppable" );
291353
//Call prepareOffsets one final time since IE does not fire return scroll events when overflow was caused by drag (see #5003)
292-
if( !draggable.options.refreshPositions ) $.ui.ddmanager.prepareOffsets( draggable, event );
354+
if( !draggable.options.refreshPositions ) {
355+
$.ui.ddmanager.prepareOffsets( draggable, event );
356+
}
293357
}
294358
};
295359

0 commit comments

Comments
 (0)