Skip to content

Commit 38e027a

Browse files
author
Alain Dumesny
committed
code cleanup
* changed all == to ===, != to !== (no unwanted side affect)
1 parent aca2a3a commit 38e027a

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

src/gridstack.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
width = Math.max.apply(Math, widths);
4747
}
4848

49-
dir = dir != -1 ? 1 : -1;
49+
dir = dir !== -1 ? 1 : -1;
5050
return Utils.sortBy(nodes, function(n) { return dir * (n.x + n.y * width); });
5151
},
5252

@@ -76,18 +76,18 @@
7676
},
7777

7878
toBool: function(v) {
79-
if (typeof v == 'boolean') {
79+
if (typeof v === 'boolean') {
8080
return v;
8181
}
82-
if (typeof v == 'string') {
82+
if (typeof v === 'string') {
8383
v = v.toLowerCase();
84-
return !(v === '' || v == 'no' || v == 'false' || v == '0');
84+
return !(v === '' || v === 'no' || v === 'false' || v === '0');
8585
}
8686
return Boolean(v);
8787
},
8888

8989
_collisionNodeCheck: function(n) {
90-
return n != this.node && Utils.isIntercepted(n, this.nn);
90+
return n !== this.node && Utils.isIntercepted(n, this.nn);
9191
},
9292

9393
_didCollide: function(bn) {
@@ -186,7 +186,7 @@
186186
},
187187
getScrollParent: function(el) {
188188
var returnEl;
189-
if (el == null) {
189+
if (el === null) {
190190
returnEl = null;
191191
} else if (el.scrollHeight > el.clientHeight) {
192192
returnEl = el;
@@ -208,7 +208,7 @@
208208
var offsetDiffDown = rect.bottom - innerHeightOrClientHeight;
209209
var offsetDiffUp = rect.top;
210210
var scrollEl = Utils.getScrollParent(el);
211-
if (scrollEl != null) {
211+
if (scrollEl !== null) {
212212
var prevScroll = scrollEl.scrollTop;
213213
if (rect.top < 0 && distance < 0) {
214214
// moving up
@@ -324,7 +324,7 @@
324324
}
325325
while (true) {
326326
var collisionNode = this.nodes.find(Utils._collisionNodeCheck, {node: node, nn: nn});
327-
if (typeof collisionNode == 'undefined') {
327+
if (typeof collisionNode === 'undefined') {
328328
return;
329329
}
330330
this.moveNode(collisionNode, collisionNode.x, node.y + node.height,
@@ -349,7 +349,7 @@
349349

350350
if (this.float) {
351351
this.nodes.forEach(function(n, i) {
352-
if (n._updating || typeof n._origY == 'undefined' || n.y == n._origY) {
352+
if (n._updating || typeof n._origY === 'undefined' || n.y === n._origY) {
353353
return;
354354
}
355355

@@ -379,13 +379,13 @@
379379
var collisionNode = this.nodes
380380
.slice(0, i)
381381
.find(Utils._didCollide, {n: n, newY: newY});
382-
canBeMoved = typeof collisionNode == 'undefined';
382+
canBeMoved = typeof collisionNode === 'undefined';
383383
}
384384

385385
if (!canBeMoved) {
386386
break;
387387
}
388-
n._dirty = n.y != newY;
388+
n._dirty = n.y !== newY;
389389
n.y = newY;
390390
}
391391
}, this);
@@ -462,10 +462,10 @@
462462
GridStackEngine.prototype.addNode = function(node, triggerAddEvent) {
463463
node = this._prepareNode(node);
464464

465-
if (typeof node.maxWidth != 'undefined') { node.width = Math.min(node.width, node.maxWidth); }
466-
if (typeof node.maxHeight != 'undefined') { node.height = Math.min(node.height, node.maxHeight); }
467-
if (typeof node.minWidth != 'undefined') { node.width = Math.max(node.width, node.minWidth); }
468-
if (typeof node.minHeight != 'undefined') { node.height = Math.max(node.height, node.minHeight); }
465+
if (typeof node.maxWidth !== 'undefined') { node.width = Math.min(node.width, node.maxWidth); }
466+
if (typeof node.maxHeight !== 'undefined') { node.height = Math.min(node.height, node.maxHeight); }
467+
if (typeof node.minWidth !== 'undefined') { node.width = Math.max(node.width, node.minWidth); }
468+
if (typeof node.minHeight !== 'undefined') { node.height = Math.max(node.height, node.minHeight); }
469469

470470
node._id = ++idSeq;
471471
node._dirty = true;
@@ -488,7 +488,7 @@
488488
}
489489

490490
this.nodes.push(node);
491-
if (typeof triggerAddEvent != 'undefined' && triggerAddEvent) {
491+
if (typeof triggerAddEvent !== 'undefined' && triggerAddEvent) {
492492
this._addedNodes.push(Utils.clone(node));
493493
}
494494

@@ -524,7 +524,7 @@
524524
this.float,
525525
0,
526526
this.nodes.map(function(n) {
527-
if (n == node) {
527+
if (n === node) {
528528
clonedNode = $.extend({}, n);
529529
return clonedNode;
530530
}
@@ -541,7 +541,7 @@
541541

542542
if (hasLocked) {
543543
res &= !Boolean(clone.nodes.find(function(n) {
544-
return n != clonedNode && Boolean(n.locked) && Boolean(n._dirty);
544+
return n !== clonedNode && Boolean(n.locked) && Boolean(n._dirty);
545545
}));
546546
}
547547
if (this.height) {
@@ -567,17 +567,17 @@
567567
};
568568

569569
GridStackEngine.prototype.isNodeChangedPosition = function(node, x, y, width, height) {
570-
if (typeof x != 'number') { x = node.x; }
571-
if (typeof y != 'number') { y = node.y; }
572-
if (typeof width != 'number') { width = node.width; }
573-
if (typeof height != 'number') { height = node.height; }
570+
if (typeof x !== 'number') { x = node.x; }
571+
if (typeof y !== 'number') { y = node.y; }
572+
if (typeof width !== 'number') { width = node.width; }
573+
if (typeof height !== 'number') { height = node.height; }
574574

575-
if (typeof node.maxWidth != 'undefined') { width = Math.min(width, node.maxWidth); }
576-
if (typeof node.maxHeight != 'undefined') { height = Math.min(height, node.maxHeight); }
577-
if (typeof node.minWidth != 'undefined') { width = Math.max(width, node.minWidth); }
578-
if (typeof node.minHeight != 'undefined') { height = Math.max(height, node.minHeight); }
575+
if (typeof node.maxWidth !== 'undefined') { width = Math.min(width, node.maxWidth); }
576+
if (typeof node.maxHeight !== 'undefined') { height = Math.min(height, node.maxHeight); }
577+
if (typeof node.minWidth !== 'undefined') { width = Math.max(width, node.minWidth); }
578+
if (typeof node.minHeight !== 'undefined') { height = Math.max(height, node.minHeight); }
579579

580-
if (node.x == x && node.y == y && node.width == width && node.height == height) {
580+
if (node.x === x && node.y === y && node.width === width && node.height === height) {
581581
return false;
582582
}
583583
return true;
@@ -587,21 +587,21 @@
587587
if (!this.isNodeChangedPosition(node, x, y, width, height)) {
588588
return node;
589589
}
590-
if (typeof x != 'number') { x = node.x; }
591-
if (typeof y != 'number') { y = node.y; }
592-
if (typeof width != 'number') { width = node.width; }
593-
if (typeof height != 'number') { height = node.height; }
590+
if (typeof x !== 'number') { x = node.x; }
591+
if (typeof y !== 'number') { y = node.y; }
592+
if (typeof width !== 'number') { width = node.width; }
593+
if (typeof height !== 'number') { height = node.height; }
594594

595-
if (typeof node.maxWidth != 'undefined') { width = Math.min(width, node.maxWidth); }
596-
if (typeof node.maxHeight != 'undefined') { height = Math.min(height, node.maxHeight); }
597-
if (typeof node.minWidth != 'undefined') { width = Math.max(width, node.minWidth); }
598-
if (typeof node.minHeight != 'undefined') { height = Math.max(height, node.minHeight); }
595+
if (typeof node.maxWidth !== 'undefined') { width = Math.min(width, node.maxWidth); }
596+
if (typeof node.maxHeight !== 'undefined') { height = Math.min(height, node.maxHeight); }
597+
if (typeof node.minWidth !== 'undefined') { width = Math.max(width, node.minWidth); }
598+
if (typeof node.minHeight !== 'undefined') { height = Math.max(height, node.minHeight); }
599599

600-
if (node.x == x && node.y == y && node.width == width && node.height == height) {
600+
if (node.x === x && node.y === y && node.width === width && node.height === height) {
601601
return node;
602602
}
603603

604-
var resizing = node.width != width;
604+
var resizing = node.width !== width;
605605
node._dirty = true;
606606

607607
node.x = x;
@@ -1084,7 +1084,7 @@
10841084
var self = this;
10851085
var getHeight;
10861086

1087-
if (typeof maxHeight == 'undefined') {
1087+
if (typeof maxHeight === 'undefined') {
10881088
maxHeight = this._styles._max;
10891089
}
10901090
this._initStyles();
@@ -1214,12 +1214,12 @@
12141214
var width;
12151215
var height;
12161216

1217-
if (event.type != 'drag') {
1217+
if (event.type !== 'drag') {
12181218
width = Math.round(ui.size.width / cellWidth);
12191219
height = Math.round(ui.size.height / cellHeight);
12201220
}
12211221

1222-
if (event.type == 'drag') {
1222+
if (event.type === 'drag') {
12231223
var distance = ui.position.top - node._prevYPix;
12241224
node._prevYPix = ui.position.top;
12251225
Utils.updateScrollPosition(el[0], ui, distance);
@@ -1258,7 +1258,7 @@
12581258
node._temporaryRemoved = false;
12591259
}
12601260
}
1261-
} else if (event.type == 'resize') {
1261+
} else if (event.type === 'resize') {
12621262
if (x < 0) {
12631263
return;
12641264
}
@@ -1278,7 +1278,7 @@
12781278
self.grid.moveNode(node, x, y, width, height);
12791279
self._updateContainerHeight();
12801280

1281-
if (event.type == 'resize') {
1281+
if (event.type === 'resize') {
12821282
$(event.target).trigger('gsresize', node);
12831283
}
12841284
};
@@ -1311,7 +1311,7 @@
13111311
self.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1));
13121312
self.dd.resizable(el, 'option', 'minHeight', (strictCellHeight * minHeight) + (minHeight - 1) * verticalMargin);
13131313

1314-
if (event.type == 'resizestart') {
1314+
if (event.type === 'resizestart') {
13151315
o.find('.grid-stack-item').trigger('resizestart');
13161316
}
13171317
};
@@ -1361,14 +1361,14 @@
13611361
self.grid.endUpdate();
13621362

13631363
var nestedGrids = o.find('.grid-stack');
1364-
if (nestedGrids.length && event.type == 'resizestop') {
1364+
if (nestedGrids.length && event.type === 'resizestop') {
13651365
nestedGrids.each(function(index, el) {
13661366
$(el).data('gridstack').onResizeHandler();
13671367
});
13681368
o.find('.grid-stack-item').trigger('resizestop');
13691369
o.find('.grid-stack-item').trigger('gsresizestop');
13701370
}
1371-
if (event.type == 'resizestop') {
1371+
if (event.type === 'resizestop') {
13721372
self.container.trigger('gsresizestop', o);
13731373
}
13741374
};
@@ -1399,7 +1399,7 @@
13991399
};
14001400

14011401
GridStack.prototype._prepareElement = function(el, triggerAddEvent) {
1402-
triggerAddEvent = typeof triggerAddEvent != 'undefined' ? triggerAddEvent : false;
1402+
triggerAddEvent = typeof triggerAddEvent !== 'undefined' ? triggerAddEvent : false;
14031403
var self = this;
14041404
el = $(el);
14051405

@@ -1444,16 +1444,16 @@
14441444

14451445
el = $(el);
14461446
// Note: passing null removes the attr in jquery
1447-
if (typeof x != 'undefined') { el.attr('data-gs-x', x); }
1448-
if (typeof y != 'undefined') { el.attr('data-gs-y', y); }
1449-
if (typeof width != 'undefined') { el.attr('data-gs-width', width); }
1450-
if (typeof height != 'undefined') { el.attr('data-gs-height', height); }
1451-
if (typeof autoPosition != 'undefined') { el.attr('data-gs-auto-position', autoPosition ? 'yes' : null); }
1452-
if (typeof minWidth != 'undefined') { el.attr('data-gs-min-width', minWidth); }
1453-
if (typeof maxWidth != 'undefined') { el.attr('data-gs-max-width', maxWidth); }
1454-
if (typeof minHeight != 'undefined') { el.attr('data-gs-min-height', minHeight); }
1455-
if (typeof maxHeight != 'undefined') { el.attr('data-gs-max-height', maxHeight); }
1456-
if (typeof id != 'undefined') { el.attr('data-gs-id', id); }
1447+
if (typeof x !== 'undefined') { el.attr('data-gs-x', x); }
1448+
if (typeof y !== 'undefined') { el.attr('data-gs-y', y); }
1449+
if (typeof width !== 'undefined') { el.attr('data-gs-width', width); }
1450+
if (typeof height !== 'undefined') { el.attr('data-gs-height', height); }
1451+
if (typeof autoPosition !== 'undefined') { el.attr('data-gs-auto-position', autoPosition ? 'yes' : null); }
1452+
if (typeof minWidth !== 'undefined') { el.attr('data-gs-min-width', minWidth); }
1453+
if (typeof maxWidth !== 'undefined') { el.attr('data-gs-max-width', maxWidth); }
1454+
if (typeof minHeight !== 'undefined') { el.attr('data-gs-min-height', minHeight); }
1455+
if (typeof maxHeight !== 'undefined') { el.attr('data-gs-max-height', maxHeight); }
1456+
if (typeof id !== 'undefined') { el.attr('data-gs-id', id); }
14571457
this.container.append(el);
14581458
this._prepareElement(el, true);
14591459
this._triggerAddEvent();
@@ -1509,7 +1509,7 @@
15091509
GridStack.prototype.destroy = function(detachGrid) {
15101510
$(window).off('resize', this.onResizeHandler);
15111511
this.disable();
1512-
if (typeof detachGrid != 'undefined' && !detachGrid) {
1512+
if (typeof detachGrid !== 'undefined' && !detachGrid) {
15131513
this.removeAll(false);
15141514
this.container.removeData('gridstack');
15151515
} else {
@@ -1527,7 +1527,7 @@
15271527
el.each(function(index, el) {
15281528
el = $(el);
15291529
var node = el.data('_gridstack_node');
1530-
if (typeof node == 'undefined' || node === null) {
1530+
if (typeof node === 'undefined' || node === null) {
15311531
return;
15321532
}
15331533

@@ -1547,7 +1547,7 @@
15471547
el.each(function(index, el) {
15481548
el = $(el);
15491549
var node = el.data('_gridstack_node');
1550-
if (typeof node == 'undefined' || node === null) {
1550+
if (typeof node === 'undefined' || node === null) {
15511551
return;
15521552
}
15531553

@@ -1594,7 +1594,7 @@
15941594
el.each(function(index, el) {
15951595
el = $(el);
15961596
var node = el.data('_gridstack_node');
1597-
if (typeof node == 'undefined' || node === null) {
1597+
if (typeof node === 'undefined' || node === null) {
15981598
return;
15991599
}
16001600

@@ -1675,7 +1675,7 @@
16751675
GridStack.prototype._updateElement = function(el, callback) {
16761676
el = $(el).first();
16771677
var node = el.data('_gridstack_node');
1678-
if (typeof node == 'undefined' || node === null) {
1678+
if (typeof node === 'undefined' || node === null) {
16791679
return;
16801680
}
16811681

@@ -1694,35 +1694,35 @@
16941694

16951695
GridStack.prototype.resize = function(el, width, height) {
16961696
this._updateElement(el, function(el, node) {
1697-
width = (width !== null && typeof width != 'undefined') ? width : node.width;
1698-
height = (height !== null && typeof height != 'undefined') ? height : node.height;
1697+
width = (width !== null && typeof width !== 'undefined') ? width : node.width;
1698+
height = (height !== null && typeof height !== 'undefined') ? height : node.height;
16991699

17001700
this.grid.moveNode(node, node.x, node.y, width, height);
17011701
});
17021702
};
17031703

17041704
GridStack.prototype.move = function(el, x, y) {
17051705
this._updateElement(el, function(el, node) {
1706-
x = (x !== null && typeof x != 'undefined') ? x : node.x;
1707-
y = (y !== null && typeof y != 'undefined') ? y : node.y;
1706+
x = (x !== null && typeof x !== 'undefined') ? x : node.x;
1707+
y = (y !== null && typeof y !== 'undefined') ? y : node.y;
17081708

17091709
this.grid.moveNode(node, x, y, node.width, node.height);
17101710
});
17111711
};
17121712

17131713
GridStack.prototype.update = function(el, x, y, width, height) {
17141714
this._updateElement(el, function(el, node) {
1715-
x = (x !== null && typeof x != 'undefined') ? x : node.x;
1716-
y = (y !== null && typeof y != 'undefined') ? y : node.y;
1717-
width = (width !== null && typeof width != 'undefined') ? width : node.width;
1718-
height = (height !== null && typeof height != 'undefined') ? height : node.height;
1715+
x = (x !== null && typeof x !== 'undefined') ? x : node.x;
1716+
y = (y !== null && typeof y !== 'undefined') ? y : node.y;
1717+
width = (width !== null && typeof width !== 'undefined') ? width : node.width;
1718+
height = (height !== null && typeof height !== 'undefined') ? height : node.height;
17191719

17201720
this.grid.moveNode(node, x, y, width, height);
17211721
});
17221722
};
17231723

17241724
GridStack.prototype.verticalMargin = function(val, noUpdate) {
1725-
if (typeof val == 'undefined') {
1725+
if (typeof val === 'undefined') {
17261726
return this.opts.verticalMargin;
17271727
}
17281728

@@ -1742,7 +1742,7 @@
17421742
/** set/get the current cell height value */
17431743
GridStack.prototype.cellHeight = function(val, noUpdate) {
17441744
// getter - returns the opts stored height else compute it...
1745-
if (typeof val == 'undefined') {
1745+
if (typeof val === 'undefined') {
17461746
if (this.opts.cellHeight && this.opts.cellHeight !== 'auto') {
17471747
return this.opts.cellHeight;
17481748
}
@@ -1771,7 +1771,7 @@
17711771
};
17721772

17731773
GridStack.prototype.getCellFromPixel = function(position, useOffset) {
1774-
var containerPos = (typeof useOffset != 'undefined' && useOffset) ?
1774+
var containerPos = (typeof useOffset !== 'undefined' && useOffset) ?
17751775
this.container.offset() : this.container.position();
17761776
var relativeLeft = position.left - containerPos.left;
17771777
var relativeTop = position.top - containerPos.top;

0 commit comments

Comments
 (0)