|
46 | 46 | width = Math.max.apply(Math, widths); |
47 | 47 | } |
48 | 48 |
|
49 | | - dir = dir != -1 ? 1 : -1; |
| 49 | + dir = dir !== -1 ? 1 : -1; |
50 | 50 | return Utils.sortBy(nodes, function(n) { return dir * (n.x + n.y * width); }); |
51 | 51 | }, |
52 | 52 |
|
|
76 | 76 | }, |
77 | 77 |
|
78 | 78 | toBool: function(v) { |
79 | | - if (typeof v == 'boolean') { |
| 79 | + if (typeof v === 'boolean') { |
80 | 80 | return v; |
81 | 81 | } |
82 | | - if (typeof v == 'string') { |
| 82 | + if (typeof v === 'string') { |
83 | 83 | v = v.toLowerCase(); |
84 | | - return !(v === '' || v == 'no' || v == 'false' || v == '0'); |
| 84 | + return !(v === '' || v === 'no' || v === 'false' || v === '0'); |
85 | 85 | } |
86 | 86 | return Boolean(v); |
87 | 87 | }, |
88 | 88 |
|
89 | 89 | _collisionNodeCheck: function(n) { |
90 | | - return n != this.node && Utils.isIntercepted(n, this.nn); |
| 90 | + return n !== this.node && Utils.isIntercepted(n, this.nn); |
91 | 91 | }, |
92 | 92 |
|
93 | 93 | _didCollide: function(bn) { |
|
186 | 186 | }, |
187 | 187 | getScrollParent: function(el) { |
188 | 188 | var returnEl; |
189 | | - if (el == null) { |
| 189 | + if (el === null) { |
190 | 190 | returnEl = null; |
191 | 191 | } else if (el.scrollHeight > el.clientHeight) { |
192 | 192 | returnEl = el; |
|
208 | 208 | var offsetDiffDown = rect.bottom - innerHeightOrClientHeight; |
209 | 209 | var offsetDiffUp = rect.top; |
210 | 210 | var scrollEl = Utils.getScrollParent(el); |
211 | | - if (scrollEl != null) { |
| 211 | + if (scrollEl !== null) { |
212 | 212 | var prevScroll = scrollEl.scrollTop; |
213 | 213 | if (rect.top < 0 && distance < 0) { |
214 | 214 | // moving up |
|
324 | 324 | } |
325 | 325 | while (true) { |
326 | 326 | var collisionNode = this.nodes.find(Utils._collisionNodeCheck, {node: node, nn: nn}); |
327 | | - if (typeof collisionNode == 'undefined') { |
| 327 | + if (typeof collisionNode === 'undefined') { |
328 | 328 | return; |
329 | 329 | } |
330 | 330 | this.moveNode(collisionNode, collisionNode.x, node.y + node.height, |
|
349 | 349 |
|
350 | 350 | if (this.float) { |
351 | 351 | 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) { |
353 | 353 | return; |
354 | 354 | } |
355 | 355 |
|
|
379 | 379 | var collisionNode = this.nodes |
380 | 380 | .slice(0, i) |
381 | 381 | .find(Utils._didCollide, {n: n, newY: newY}); |
382 | | - canBeMoved = typeof collisionNode == 'undefined'; |
| 382 | + canBeMoved = typeof collisionNode === 'undefined'; |
383 | 383 | } |
384 | 384 |
|
385 | 385 | if (!canBeMoved) { |
386 | 386 | break; |
387 | 387 | } |
388 | | - n._dirty = n.y != newY; |
| 388 | + n._dirty = n.y !== newY; |
389 | 389 | n.y = newY; |
390 | 390 | } |
391 | 391 | }, this); |
|
462 | 462 | GridStackEngine.prototype.addNode = function(node, triggerAddEvent) { |
463 | 463 | node = this._prepareNode(node); |
464 | 464 |
|
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); } |
469 | 469 |
|
470 | 470 | node._id = ++idSeq; |
471 | 471 | node._dirty = true; |
|
488 | 488 | } |
489 | 489 |
|
490 | 490 | this.nodes.push(node); |
491 | | - if (typeof triggerAddEvent != 'undefined' && triggerAddEvent) { |
| 491 | + if (typeof triggerAddEvent !== 'undefined' && triggerAddEvent) { |
492 | 492 | this._addedNodes.push(Utils.clone(node)); |
493 | 493 | } |
494 | 494 |
|
|
524 | 524 | this.float, |
525 | 525 | 0, |
526 | 526 | this.nodes.map(function(n) { |
527 | | - if (n == node) { |
| 527 | + if (n === node) { |
528 | 528 | clonedNode = $.extend({}, n); |
529 | 529 | return clonedNode; |
530 | 530 | } |
|
541 | 541 |
|
542 | 542 | if (hasLocked) { |
543 | 543 | 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); |
545 | 545 | })); |
546 | 546 | } |
547 | 547 | if (this.height) { |
|
567 | 567 | }; |
568 | 568 |
|
569 | 569 | 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; } |
574 | 574 |
|
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); } |
579 | 579 |
|
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) { |
581 | 581 | return false; |
582 | 582 | } |
583 | 583 | return true; |
|
587 | 587 | if (!this.isNodeChangedPosition(node, x, y, width, height)) { |
588 | 588 | return node; |
589 | 589 | } |
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; } |
594 | 594 |
|
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); } |
599 | 599 |
|
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) { |
601 | 601 | return node; |
602 | 602 | } |
603 | 603 |
|
604 | | - var resizing = node.width != width; |
| 604 | + var resizing = node.width !== width; |
605 | 605 | node._dirty = true; |
606 | 606 |
|
607 | 607 | node.x = x; |
|
1084 | 1084 | var self = this; |
1085 | 1085 | var getHeight; |
1086 | 1086 |
|
1087 | | - if (typeof maxHeight == 'undefined') { |
| 1087 | + if (typeof maxHeight === 'undefined') { |
1088 | 1088 | maxHeight = this._styles._max; |
1089 | 1089 | } |
1090 | 1090 | this._initStyles(); |
|
1214 | 1214 | var width; |
1215 | 1215 | var height; |
1216 | 1216 |
|
1217 | | - if (event.type != 'drag') { |
| 1217 | + if (event.type !== 'drag') { |
1218 | 1218 | width = Math.round(ui.size.width / cellWidth); |
1219 | 1219 | height = Math.round(ui.size.height / cellHeight); |
1220 | 1220 | } |
1221 | 1221 |
|
1222 | | - if (event.type == 'drag') { |
| 1222 | + if (event.type === 'drag') { |
1223 | 1223 | var distance = ui.position.top - node._prevYPix; |
1224 | 1224 | node._prevYPix = ui.position.top; |
1225 | 1225 | Utils.updateScrollPosition(el[0], ui, distance); |
|
1258 | 1258 | node._temporaryRemoved = false; |
1259 | 1259 | } |
1260 | 1260 | } |
1261 | | - } else if (event.type == 'resize') { |
| 1261 | + } else if (event.type === 'resize') { |
1262 | 1262 | if (x < 0) { |
1263 | 1263 | return; |
1264 | 1264 | } |
|
1278 | 1278 | self.grid.moveNode(node, x, y, width, height); |
1279 | 1279 | self._updateContainerHeight(); |
1280 | 1280 |
|
1281 | | - if (event.type == 'resize') { |
| 1281 | + if (event.type === 'resize') { |
1282 | 1282 | $(event.target).trigger('gsresize', node); |
1283 | 1283 | } |
1284 | 1284 | }; |
|
1311 | 1311 | self.dd.resizable(el, 'option', 'minWidth', cellWidth * (node.minWidth || 1)); |
1312 | 1312 | self.dd.resizable(el, 'option', 'minHeight', (strictCellHeight * minHeight) + (minHeight - 1) * verticalMargin); |
1313 | 1313 |
|
1314 | | - if (event.type == 'resizestart') { |
| 1314 | + if (event.type === 'resizestart') { |
1315 | 1315 | o.find('.grid-stack-item').trigger('resizestart'); |
1316 | 1316 | } |
1317 | 1317 | }; |
|
1361 | 1361 | self.grid.endUpdate(); |
1362 | 1362 |
|
1363 | 1363 | var nestedGrids = o.find('.grid-stack'); |
1364 | | - if (nestedGrids.length && event.type == 'resizestop') { |
| 1364 | + if (nestedGrids.length && event.type === 'resizestop') { |
1365 | 1365 | nestedGrids.each(function(index, el) { |
1366 | 1366 | $(el).data('gridstack').onResizeHandler(); |
1367 | 1367 | }); |
1368 | 1368 | o.find('.grid-stack-item').trigger('resizestop'); |
1369 | 1369 | o.find('.grid-stack-item').trigger('gsresizestop'); |
1370 | 1370 | } |
1371 | | - if (event.type == 'resizestop') { |
| 1371 | + if (event.type === 'resizestop') { |
1372 | 1372 | self.container.trigger('gsresizestop', o); |
1373 | 1373 | } |
1374 | 1374 | }; |
|
1399 | 1399 | }; |
1400 | 1400 |
|
1401 | 1401 | GridStack.prototype._prepareElement = function(el, triggerAddEvent) { |
1402 | | - triggerAddEvent = typeof triggerAddEvent != 'undefined' ? triggerAddEvent : false; |
| 1402 | + triggerAddEvent = typeof triggerAddEvent !== 'undefined' ? triggerAddEvent : false; |
1403 | 1403 | var self = this; |
1404 | 1404 | el = $(el); |
1405 | 1405 |
|
|
1444 | 1444 |
|
1445 | 1445 | el = $(el); |
1446 | 1446 | // 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); } |
1457 | 1457 | this.container.append(el); |
1458 | 1458 | this._prepareElement(el, true); |
1459 | 1459 | this._triggerAddEvent(); |
|
1509 | 1509 | GridStack.prototype.destroy = function(detachGrid) { |
1510 | 1510 | $(window).off('resize', this.onResizeHandler); |
1511 | 1511 | this.disable(); |
1512 | | - if (typeof detachGrid != 'undefined' && !detachGrid) { |
| 1512 | + if (typeof detachGrid !== 'undefined' && !detachGrid) { |
1513 | 1513 | this.removeAll(false); |
1514 | 1514 | this.container.removeData('gridstack'); |
1515 | 1515 | } else { |
|
1527 | 1527 | el.each(function(index, el) { |
1528 | 1528 | el = $(el); |
1529 | 1529 | var node = el.data('_gridstack_node'); |
1530 | | - if (typeof node == 'undefined' || node === null) { |
| 1530 | + if (typeof node === 'undefined' || node === null) { |
1531 | 1531 | return; |
1532 | 1532 | } |
1533 | 1533 |
|
|
1547 | 1547 | el.each(function(index, el) { |
1548 | 1548 | el = $(el); |
1549 | 1549 | var node = el.data('_gridstack_node'); |
1550 | | - if (typeof node == 'undefined' || node === null) { |
| 1550 | + if (typeof node === 'undefined' || node === null) { |
1551 | 1551 | return; |
1552 | 1552 | } |
1553 | 1553 |
|
|
1594 | 1594 | el.each(function(index, el) { |
1595 | 1595 | el = $(el); |
1596 | 1596 | var node = el.data('_gridstack_node'); |
1597 | | - if (typeof node == 'undefined' || node === null) { |
| 1597 | + if (typeof node === 'undefined' || node === null) { |
1598 | 1598 | return; |
1599 | 1599 | } |
1600 | 1600 |
|
|
1675 | 1675 | GridStack.prototype._updateElement = function(el, callback) { |
1676 | 1676 | el = $(el).first(); |
1677 | 1677 | var node = el.data('_gridstack_node'); |
1678 | | - if (typeof node == 'undefined' || node === null) { |
| 1678 | + if (typeof node === 'undefined' || node === null) { |
1679 | 1679 | return; |
1680 | 1680 | } |
1681 | 1681 |
|
|
1694 | 1694 |
|
1695 | 1695 | GridStack.prototype.resize = function(el, width, height) { |
1696 | 1696 | 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; |
1699 | 1699 |
|
1700 | 1700 | this.grid.moveNode(node, node.x, node.y, width, height); |
1701 | 1701 | }); |
1702 | 1702 | }; |
1703 | 1703 |
|
1704 | 1704 | GridStack.prototype.move = function(el, x, y) { |
1705 | 1705 | 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; |
1708 | 1708 |
|
1709 | 1709 | this.grid.moveNode(node, x, y, node.width, node.height); |
1710 | 1710 | }); |
1711 | 1711 | }; |
1712 | 1712 |
|
1713 | 1713 | GridStack.prototype.update = function(el, x, y, width, height) { |
1714 | 1714 | 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; |
1719 | 1719 |
|
1720 | 1720 | this.grid.moveNode(node, x, y, width, height); |
1721 | 1721 | }); |
1722 | 1722 | }; |
1723 | 1723 |
|
1724 | 1724 | GridStack.prototype.verticalMargin = function(val, noUpdate) { |
1725 | | - if (typeof val == 'undefined') { |
| 1725 | + if (typeof val === 'undefined') { |
1726 | 1726 | return this.opts.verticalMargin; |
1727 | 1727 | } |
1728 | 1728 |
|
|
1742 | 1742 | /** set/get the current cell height value */ |
1743 | 1743 | GridStack.prototype.cellHeight = function(val, noUpdate) { |
1744 | 1744 | // getter - returns the opts stored height else compute it... |
1745 | | - if (typeof val == 'undefined') { |
| 1745 | + if (typeof val === 'undefined') { |
1746 | 1746 | if (this.opts.cellHeight && this.opts.cellHeight !== 'auto') { |
1747 | 1747 | return this.opts.cellHeight; |
1748 | 1748 | } |
|
1771 | 1771 | }; |
1772 | 1772 |
|
1773 | 1773 | GridStack.prototype.getCellFromPixel = function(position, useOffset) { |
1774 | | - var containerPos = (typeof useOffset != 'undefined' && useOffset) ? |
| 1774 | + var containerPos = (typeof useOffset !== 'undefined' && useOffset) ? |
1775 | 1775 | this.container.offset() : this.container.position(); |
1776 | 1776 | var relativeLeft = position.left - containerPos.left; |
1777 | 1777 | var relativeTop = position.top - containerPos.top; |
|
0 commit comments