diff --git a/spec/gridstack-engine-spec.ts b/spec/gridstack-engine-spec.ts index 8628f6d09..b5284c623 100644 --- a/spec/gridstack-engine-spec.ts +++ b/spec/gridstack-engine-spec.ts @@ -9,7 +9,7 @@ describe('gridstack engine', function() { let w: any = window; let findNode = function(engine, id) { - return engine.nodes.find(function(i) { return i.id === id; }); + return engine.nodes.find((i) => i.id === id); }; it('should exist setup function.', function() { diff --git a/src/gridstack-dd.ts b/src/gridstack-dd.ts index f48326cd2..efb1afc90 100644 --- a/src/gridstack-dd.ts +++ b/src/gridstack-dd.ts @@ -170,7 +170,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack { }) .on(this.el, 'dropout', (event, el: GridItemHTMLElement) => { let node = el.gridstackNode; - if (!node) { return; } + if (!node) return; // clear any added flag now that we are leaving #1484 delete node._added; @@ -195,7 +195,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack { let node = el.gridstackNode; let wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419 // ignore drop on ourself from ourself - dragend will handle the simple move instead - if (node && node.grid === this) { return false; } + if (node && node.grid === this) return false; this.placeholder.remove(); @@ -210,7 +210,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack { oGrid._triggerRemoveEvent(); } - if (!node) { return false; } + if (!node) return false; // use existing placeholder node as it's already in our list with drop location if (wasAdded) { @@ -522,10 +522,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid * @param val if true widget will be draggable. */ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): GridStack { - if (this.opts.staticGrid) { return this; } // can't move a static grid! + if (this.opts.staticGrid) return this; // can't move a static grid! GridStack.getElements(els).forEach(el => { let node = el.gridstackNode; - if (!node || node.locked) { return } + if (!node || node.locked) return; node.noMove = !(val || false); if (node.noMove) { GridStackDD.get().draggable(el, 'disable'); @@ -545,10 +545,10 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri * @param val if true widget will be resizable. */ GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): GridStack { - if (this.opts.staticGrid) { return this; } // can't resize a static grid! + if (this.opts.staticGrid) return this; // can't resize a static grid! GridStack.getElements(els).forEach(el => { let node = el.gridstackNode; - if (!node || node.locked) { return; } + if (!node || node.locked) return; node.noResize = !(val || false); if (node.noResize) { GridStackDD.get().resizable(el, 'disable'); diff --git a/src/gridstack-engine.ts b/src/gridstack-engine.ts index cdf25ca7e..765c98863 100644 --- a/src/gridstack-engine.ts +++ b/src/gridstack-engine.ts @@ -82,7 +82,7 @@ export class GridStackEngine { } while (true) { let collisionNode = this.nodes.find( n => n !== node && Utils.isIntercepted(n, nn), {node: node, nn: nn}); - if (!collisionNode) { return this } + if (!collisionNode) return this; let moved; if (collisionNode.locked) { // if colliding with a locked item, move ourself instead @@ -92,7 +92,7 @@ export class GridStackEngine { moved = this.moveNode(collisionNode, collisionNode.x, node.y + node.h, collisionNode.w, collisionNode.h, true); } - if (!moved) { return this } // break inf loop if we couldn't move after all (ex: maxRow, fixed) + if (!moved) return this; // break inf loop if we couldn't move after all (ex: maxRow, fixed) } } @@ -106,7 +106,7 @@ export class GridStackEngine { /** re-layout grid items to reclaim any empty space */ public compact(): GridStackEngine { - if (this.nodes.length === 0) { return this } + if (this.nodes.length === 0) return this; this.batchUpdate(); this._sortNodes(); let copyNodes = this.nodes; @@ -124,7 +124,7 @@ export class GridStackEngine { /** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */ public set float(val: boolean) { - if (this._float === val) { return; } + if (this._float === val) return; this._float = val || false; if (!val) { this._packNodes(); @@ -165,7 +165,7 @@ export class GridStackEngine { }); } else { this.nodes.forEach((n, i) => { - if (n.locked) { return this } + if (n.locked) return this; while (n.y > 0) { let newY = n.y - 1; let canBeMoved = i === 0; @@ -284,7 +284,7 @@ export class GridStackEngine { /** @internal */ private _notify(nodes?: GridStackNode | GridStackNode[], removeDOM = true): GridStackEngine { - if (this.batchMode) { return this } + if (this.batchMode) return this; nodes = (nodes === undefined ? [] : (Array.isArray(nodes) ? nodes : [nodes]) ); let dirtyNodes = nodes.concat(this.getDirtyNodes()); if (this.onChange) { @@ -294,7 +294,7 @@ export class GridStackEngine { } public cleanNodes(): GridStackEngine { - if (this.batchMode) { return this } + if (this.batchMode) return this; this.nodes.forEach(n => { delete n._dirty; }); return this; } @@ -348,7 +348,7 @@ export class GridStackEngine { public removeAll(removeDOM = true): GridStackEngine { delete this._layouts; - if (this.nodes.length === 0) { return this } + if (this.nodes.length === 0) return this; if (removeDOM) { this.nodes.forEach(n => { n._id = null; }); // hint that node is being removed } @@ -427,7 +427,7 @@ export class GridStackEngine { } public moveNode(node: GridStackNode, x: number, y: number, w?: number, h?: number, noPack?: boolean): GridStackNode { - if (node.locked) { return null; } + if (node.locked) return null; if (typeof x !== 'number') { x = node.x; } if (typeof y !== 'number') { y = node.y; } if (typeof w !== 'number') { w = node.w; } @@ -544,7 +544,7 @@ export class GridStackEngine { * Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column */ public updateNodeWidths(oldColumn: number, column: number, nodes: GridStackNode[], layout: ColumnOptions = 'moveScale'): GridStackEngine { - if (!this.nodes.length || oldColumn === column) { return this } + if (!this.nodes.length || oldColumn === column) return this; // cache the current layout in case they want to go back (like 12 -> 1 -> 12) as it requires original data this.cacheLayout(this.nodes, oldColumn); diff --git a/src/gridstack.ts b/src/gridstack.ts index 1dd55a2e3..202ed1ba2 100644 --- a/src/gridstack.ts +++ b/src/gridstack.ts @@ -163,7 +163,7 @@ export class GridStack { * @param opt grids options used to initialize the grid, and list of children */ public static addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack { - if (!parent) { return null; } + if (!parent) return null; // create the grid element let doc = document.implementation.createHTMLDocument(); @@ -621,7 +621,7 @@ export class GridStack { * Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column */ public column(column: number, layout: ColumnOptions = 'moveScale'): GridStack { - if (this.opts.column === column) { return this; } + if (this.opts.column === column) return this; let oldColumn = this.opts.column; // if we go into 1 column mode (which happens if we're sized less than minW unless disableOneColumnMode is on) @@ -673,7 +673,7 @@ export class GridStack { * @param removeDOM if `false` grid and items HTML elements will not be removed from the DOM (Optional. Default `true`). */ public destroy(removeDOM = true): GridStack { - if (!this.el) { return; } // prevent multiple calls + if (!this.el) return; // prevent multiple calls this._updateWindowResizeEvent(true); this.setStatic(true); // permanently removes DD if (!removeDOM) { @@ -702,7 +702,7 @@ export class GridStack { * grid.enableResize(false); */ public disable(): GridStack { - if (this.opts.staticGrid) { return; } + if (this.opts.staticGrid) return; this.enableMove(false); this.enableResize(false); this._triggerEvent('disable'); @@ -718,7 +718,7 @@ export class GridStack { * grid.enableResize(true); */ public enable(): GridStack { - if (this.opts.staticGrid) { return; } + if (this.opts.staticGrid) return; this.enableMove(true); this.enableResize(true); this._triggerEvent('enable'); @@ -733,7 +733,7 @@ export class GridStack { * doEnable`s value by changing the disableDrag grid option (default: true). */ public enableMove(doEnable: boolean, includeNewWidgets = true): GridStack { - if (this.opts.staticGrid) { return this; } // can't move a static grid! + if (this.opts.staticGrid) return this; // can't move a static grid! this.getGridItems().forEach(el => this.movable(el, doEnable)); if (includeNewWidgets) { this.opts.disableDrag = !doEnable; @@ -748,7 +748,7 @@ export class GridStack { * doEnable`s value by changing the disableResize grid option (default: true). */ public enableResize(doEnable: boolean, includeNewWidgets = true): GridStack { - if (this.opts.staticGrid) { return this; } // can't size a static grid! + if (this.opts.staticGrid) return this; // can't size a static grid! this.getGridItems().forEach(el => this.resizable(el, doEnable)); if (includeNewWidgets) { this.opts.disableResize = !doEnable; @@ -978,7 +978,7 @@ export class GridStack { * @param val if true the grid become static. */ public setStatic(val: boolean): GridStack { - if (this.opts.staticGrid === val) { return this; } + if (this.opts.staticGrid === val) return this; this.opts.staticGrid = val; this.engine.nodes.forEach(n => this._prepareDragDropByNode(n)); // either delete Drag&drop or initialize it this._setStaticClass(); @@ -1002,7 +1002,7 @@ export class GridStack { } GridStack.getElements(els).forEach(el => { - if (!el || !el.gridstackNode) { return; } + if (!el || !el.gridstackNode) return; let n = el.gridstackNode; let w = {...opt}; // make a copy we can modify in case they re-use it or multiple items delete w.autoPosition; @@ -1111,7 +1111,7 @@ export class GridStack { /** @internal */ private _triggerChangeEvent(): GridStack { - if (this.engine.batchMode) { return this; } + if (this.engine.batchMode) return this; let elements = this.engine.getDirtyNodes(true); // verify they really changed if (elements && elements.length) { if (!this._ignoreLayoutsNodeChange) { @@ -1125,7 +1125,7 @@ export class GridStack { /** @internal */ private _triggerAddEvent(): GridStack { - if (this.engine.batchMode) { return this } + if (this.engine.batchMode) return this; if (this.engine.addedNodes && this.engine.addedNodes.length > 0) { if (!this._ignoreLayoutsNodeChange) { this.engine.layoutsNodesChange(this.engine.addedNodes); @@ -1140,7 +1140,7 @@ export class GridStack { /** @internal */ public _triggerRemoveEvent(): GridStack { - if (this.engine.batchMode) { return this; } + if (this.engine.batchMode) return this; if (this.engine.removedNodes && this.engine.removedNodes.length > 0) { this._triggerEvent('removed', this.engine.removedNodes); this.engine.removedNodes = []; @@ -1189,7 +1189,7 @@ export class GridStack { // insert style to parent (instead of 'head' by default) to support WebComponent let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement; this._styles = Utils.createStylesheet(id, styleLocation); - if (!this._styles) { return this; } + if (!this._styles) return this; this._styles._id = id; this._styles._max = 0; @@ -1231,7 +1231,7 @@ export class GridStack { /** @internal */ private _updateContainerHeight(): GridStack { - if (!this.engine || this.engine.batchMode) { return this; } + if (!this.engine || this.engine.batchMode) return this; let row = this.getRow(); // checks for minRow already // check for css min height let cssMinHeight = parseInt(getComputedStyle(this.el)['min-height']); @@ -1248,7 +1248,7 @@ export class GridStack { } let cellHeight = this.opts.cellHeight as number; let unit = this.opts.cellHeightUnit; - if (!cellHeight) { return this } + if (!cellHeight) return this; this.el.style.height = row * cellHeight + unit; return this; } @@ -1338,7 +1338,7 @@ export class GridStack { // remove any key not found (null or false which is default) for (const key in node) { - if (!node.hasOwnProperty(key)) { return; } + if (!node.hasOwnProperty(key)) return; if (!node[key] && node[key] !== 0) { // 0 can be valid value (x,y only really) delete node[key]; } @@ -1379,12 +1379,12 @@ export class GridStack { } if (!this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.minWidth) { - if (this._oneColumnMode) { return this } + if (this._oneColumnMode) return this; this._oneColumnMode = true; this.column(1); this._resizeNestedGrids(this.el); } else { - if (!this._oneColumnMode) { return this } + if (!this._oneColumnMode) return this; delete this._oneColumnMode; this.column(this._prevColumn); this._resizeNestedGrids(this.el); @@ -1497,25 +1497,25 @@ export class GridStack { * @param els widget or selector to modify. * @param val if true widget will be draggable. */ - public movable(els: GridStackElement, val: boolean): GridStack { return this; } + public movable(els: GridStackElement, val: boolean): GridStack { return this } /** * Enables/Disables resizing. No-op for static grids. * @param els widget or selector to modify * @param val if true widget will be resizable. */ - public resizable(els: GridStackElement, val: boolean): GridStack { return this; } + public resizable(els: GridStackElement, val: boolean): GridStack { return this } /** @internal called to add drag over support to support widgets */ - public _setupAcceptWidget(): GridStack { return this; } + public _setupAcceptWidget(): GridStack { return this } /** @internal called to setup a trash drop zone if the user specifies it */ - public _setupRemoveDrop(): GridStack { return this; } + public _setupRemoveDrop(): GridStack { return this } /** @internal */ - public _setupRemovingTimeout(el: GridItemHTMLElement): GridStack { return this; } + public _setupRemovingTimeout(el: GridItemHTMLElement): GridStack { return this } /** @internal */ - public _clearRemovingTimeout(el: GridItemHTMLElement): GridStack { return this; } + public _clearRemovingTimeout(el: GridItemHTMLElement): GridStack { return this } /** @internal call to setup dragging in from the outside (say toolbar), with options */ public _setupDragIn(): GridStack {return this; } /** @internal prepares the element for drag&drop **/ - public _prepareDragDropByNode(node: GridStackNode): GridStack { return this; } + public _prepareDragDropByNode(node: GridStackNode): GridStack { return this } // 2.x API that just calls the new and better update() - keep those around for backward compat only... /** @internal */ diff --git a/src/h5/dd-base-impl.ts b/src/h5/dd-base-impl.ts index 43e46059c..9af36259a 100644 --- a/src/h5/dd-base-impl.ts +++ b/src/h5/dd-base-impl.ts @@ -38,7 +38,7 @@ export abstract class DDBaseImplement { } public triggerEvent(eventName: string, event: Event): boolean|void { - if (this.disabled) { return; } + if (this.disabled) return; if (!this._eventRegister) {return; } // used when destroy before triggerEvent fire if (this._eventRegister[eventName]) { return this._eventRegister[eventName](event); diff --git a/src/h5/dd-droppable.ts b/src/h5/dd-droppable.ts index bd5479a1b..b2cf79cb2 100644 --- a/src/h5/dd-droppable.ts +++ b/src/h5/dd-droppable.ts @@ -50,14 +50,14 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt } public enable(): void { - if (!this.disabled) { return; } + if (!this.disabled) return; super.enable(); this.el.classList.remove('ui-droppable-disabled'); this.el.addEventListener('dragenter', this._dragEnter); } public disable(): void { - if (this.disabled) { return; } + if (this.disabled) return; super.disable(); this.el.classList.add('ui-droppable-disabled'); this.el.removeEventListener('dragenter', this._dragEnter); @@ -107,7 +107,7 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt /** @internal called when the item is leaving our area, stop tracking if we had acceptable item */ private _dragLeave(event: DragEvent): void { - if (this.el.contains(event.relatedTarget as HTMLElement)) { return; } + if (this.el.contains(event.relatedTarget as HTMLElement)) return; this._removeLeaveCallbacks(); if (this.acceptable) { event.preventDefault(); @@ -121,7 +121,7 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt /** @internal item is being dropped on us - call the client drop event */ private _drop(event: DragEvent): void { - if (!this.acceptable) { return; } // should not have received event... + if (!this.acceptable) return; // should not have received event... event.preventDefault(); const ev = DDUtils.initEvent(event, { target: this.el, type: 'drop' }); if (this.option.drop) { diff --git a/src/h5/gridstack-dd-native.ts b/src/h5/gridstack-dd-native.ts index 615305d47..1d295a209 100644 --- a/src/h5/gridstack-dd-native.ts +++ b/src/h5/gridstack-dd-native.ts @@ -133,7 +133,7 @@ export class GridStackDDNative extends GridStackDD { /** @internal returns a list of DD elements, creating them on the fly by default */ private _getDDElements(els: GridStackElement, create = true): DDElement[] { let hosts = Utils.getElements(els) as DDElementHost[]; - if (!hosts.length) { return []; } + if (!hosts.length) return []; let list = hosts.map(e => e.ddElement || (create ? DDElement.init(e) : null)); if (!create) { list.filter(d => d); } // remove nulls return list; diff --git a/src/utils.ts b/src/utils.ts index 81da00fc6..0bc9b10fe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -72,7 +72,7 @@ export class Utils { /** convert a potential selector into actual single element */ static getElement(els: GridStackElement): HTMLElement { if (typeof els === 'string') { - if (!els.length) { return null} + if (!els.length) return null; if (els[0] === '#') { return document.getElementById(els.substring(1)); } @@ -198,7 +198,7 @@ export class Utils { sources.forEach(source => { for (const key in source) { - if (!source.hasOwnProperty(key)) { return; } + if (!source.hasOwnProperty(key)) return; if (target[key] === null || target[key] === undefined) { target[key] = source[key]; } else if (typeof source[key] === 'object' && typeof target[key] === 'object') { @@ -213,12 +213,12 @@ export class Utils { /** given 2 objects return true if they have the same values. Checks for Object {} having same fields and values (just 1 level down) */ static same(a: unknown, b: unknown): boolean { - if (typeof a !== 'object') { return a == b; } - if (typeof a !== typeof b) { return false; } + if (typeof a !== 'object') return a == b; + if (typeof a !== typeof b) return false; // else we have object, check just 1 level deep for being same things... - if (Object.keys(a).length !== Object.keys(b).length) { return false; } + if (Object.keys(a).length !== Object.keys(b).length) return false; for (const key in a) { - if (a[key] !== b[key]) { return false; } + if (a[key] !== b[key]) return false; } return true; }