Skip to content

Commit 5d36e26

Browse files
committed
return code cleanup
1 parent 2141113 commit 5d36e26

File tree

8 files changed

+55
-55
lines changed

8 files changed

+55
-55
lines changed

spec/gridstack-engine-spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('gridstack engine', function() {
99
let w: any = window;
1010

1111
let findNode = function(engine, id) {
12-
return engine.nodes.find(function(i) { return i.id === id; });
12+
return engine.nodes.find((i) => i.id === id);
1313
};
1414

1515
it('should exist setup function.', function() {

src/gridstack-dd.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
170170
})
171171
.on(this.el, 'dropout', (event, el: GridItemHTMLElement) => {
172172
let node = el.gridstackNode;
173-
if (!node) { return; }
173+
if (!node) return;
174174

175175
// clear any added flag now that we are leaving #1484
176176
delete node._added;
@@ -195,7 +195,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
195195
let node = el.gridstackNode;
196196
let wasAdded = !!this.placeholder.parentElement; // skip items not actually added to us because of constrains, but do cleanup #1419
197197
// ignore drop on ourself from ourself - dragend will handle the simple move instead
198-
if (node && node.grid === this) { return false; }
198+
if (node && node.grid === this) return false;
199199

200200
this.placeholder.remove();
201201

@@ -210,7 +210,7 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
210210
oGrid._triggerRemoveEvent();
211211
}
212212

213-
if (!node) { return false; }
213+
if (!node) return false;
214214

215215
// use existing placeholder node as it's already in our list with drop location
216216
if (wasAdded) {
@@ -522,10 +522,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
522522
* @param val if true widget will be draggable.
523523
*/
524524
GridStack.prototype.movable = function(els: GridStackElement, val: boolean): GridStack {
525-
if (this.opts.staticGrid) { return this; } // can't move a static grid!
525+
if (this.opts.staticGrid) return this; // can't move a static grid!
526526
GridStack.getElements(els).forEach(el => {
527527
let node = el.gridstackNode;
528-
if (!node || node.locked) { return }
528+
if (!node || node.locked) return;
529529
node.noMove = !(val || false);
530530
if (node.noMove) {
531531
GridStackDD.get().draggable(el, 'disable');
@@ -545,10 +545,10 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri
545545
* @param val if true widget will be resizable.
546546
*/
547547
GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): GridStack {
548-
if (this.opts.staticGrid) { return this; } // can't resize a static grid!
548+
if (this.opts.staticGrid) return this; // can't resize a static grid!
549549
GridStack.getElements(els).forEach(el => {
550550
let node = el.gridstackNode;
551-
if (!node || node.locked) { return; }
551+
if (!node || node.locked) return;
552552
node.noResize = !(val || false);
553553
if (node.noResize) {
554554
GridStackDD.get().resizable(el, 'disable');

src/gridstack-engine.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class GridStackEngine {
8282
}
8383
while (true) {
8484
let collisionNode = this.nodes.find( n => n !== node && Utils.isIntercepted(n, nn), {node: node, nn: nn});
85-
if (!collisionNode) { return this }
85+
if (!collisionNode) return this;
8686
let moved;
8787
if (collisionNode.locked) {
8888
// if colliding with a locked item, move ourself instead
@@ -92,7 +92,7 @@ export class GridStackEngine {
9292
moved = this.moveNode(collisionNode, collisionNode.x, node.y + node.h,
9393
collisionNode.w, collisionNode.h, true);
9494
}
95-
if (!moved) { return this } // break inf loop if we couldn't move after all (ex: maxRow, fixed)
95+
if (!moved) return this; // break inf loop if we couldn't move after all (ex: maxRow, fixed)
9696
}
9797
}
9898

@@ -106,7 +106,7 @@ export class GridStackEngine {
106106

107107
/** re-layout grid items to reclaim any empty space */
108108
public compact(): GridStackEngine {
109-
if (this.nodes.length === 0) { return this }
109+
if (this.nodes.length === 0) return this;
110110
this.batchUpdate();
111111
this._sortNodes();
112112
let copyNodes = this.nodes;
@@ -124,7 +124,7 @@ export class GridStackEngine {
124124

125125
/** enable/disable floating widgets (default: `false`) See [example](http://gridstackjs.com/demo/float.html) */
126126
public set float(val: boolean) {
127-
if (this._float === val) { return; }
127+
if (this._float === val) return;
128128
this._float = val || false;
129129
if (!val) {
130130
this._packNodes();
@@ -165,7 +165,7 @@ export class GridStackEngine {
165165
});
166166
} else {
167167
this.nodes.forEach((n, i) => {
168-
if (n.locked) { return this }
168+
if (n.locked) return this;
169169
while (n.y > 0) {
170170
let newY = n.y - 1;
171171
let canBeMoved = i === 0;
@@ -284,7 +284,7 @@ export class GridStackEngine {
284284

285285
/** @internal */
286286
private _notify(nodes?: GridStackNode | GridStackNode[], removeDOM = true): GridStackEngine {
287-
if (this.batchMode) { return this }
287+
if (this.batchMode) return this;
288288
nodes = (nodes === undefined ? [] : (Array.isArray(nodes) ? nodes : [nodes]) );
289289
let dirtyNodes = nodes.concat(this.getDirtyNodes());
290290
if (this.onChange) {
@@ -294,7 +294,7 @@ export class GridStackEngine {
294294
}
295295

296296
public cleanNodes(): GridStackEngine {
297-
if (this.batchMode) { return this }
297+
if (this.batchMode) return this;
298298
this.nodes.forEach(n => { delete n._dirty; });
299299
return this;
300300
}
@@ -348,7 +348,7 @@ export class GridStackEngine {
348348

349349
public removeAll(removeDOM = true): GridStackEngine {
350350
delete this._layouts;
351-
if (this.nodes.length === 0) { return this }
351+
if (this.nodes.length === 0) return this;
352352
if (removeDOM) {
353353
this.nodes.forEach(n => { n._id = null; }); // hint that node is being removed
354354
}
@@ -427,7 +427,7 @@ export class GridStackEngine {
427427
}
428428

429429
public moveNode(node: GridStackNode, x: number, y: number, w?: number, h?: number, noPack?: boolean): GridStackNode {
430-
if (node.locked) { return null; }
430+
if (node.locked) return null;
431431
if (typeof x !== 'number') { x = node.x; }
432432
if (typeof y !== 'number') { y = node.y; }
433433
if (typeof w !== 'number') { w = node.w; }
@@ -544,7 +544,7 @@ export class GridStackEngine {
544544
* Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
545545
*/
546546
public updateNodeWidths(oldColumn: number, column: number, nodes: GridStackNode[], layout: ColumnOptions = 'moveScale'): GridStackEngine {
547-
if (!this.nodes.length || oldColumn === column) { return this }
547+
if (!this.nodes.length || oldColumn === column) return this;
548548

549549
// cache the current layout in case they want to go back (like 12 -> 1 -> 12) as it requires original data
550550
this.cacheLayout(this.nodes, oldColumn);

src/gridstack.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class GridStack {
163163
* @param opt grids options used to initialize the grid, and list of children
164164
*/
165165
public static addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack {
166-
if (!parent) { return null; }
166+
if (!parent) return null;
167167

168168
// create the grid element
169169
let doc = document.implementation.createHTMLDocument();
@@ -621,7 +621,7 @@ export class GridStack {
621621
* Note: items will never be outside of the current column boundaries. default (moveScale). Ignored for 1 column
622622
*/
623623
public column(column: number, layout: ColumnOptions = 'moveScale'): GridStack {
624-
if (this.opts.column === column) { return this; }
624+
if (this.opts.column === column) return this;
625625
let oldColumn = this.opts.column;
626626

627627
// 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 {
673673
* @param removeDOM if `false` grid and items HTML elements will not be removed from the DOM (Optional. Default `true`).
674674
*/
675675
public destroy(removeDOM = true): GridStack {
676-
if (!this.el) { return; } // prevent multiple calls
676+
if (!this.el) return; // prevent multiple calls
677677
this._updateWindowResizeEvent(true);
678678
this.setStatic(true); // permanently removes DD
679679
if (!removeDOM) {
@@ -702,7 +702,7 @@ export class GridStack {
702702
* grid.enableResize(false);
703703
*/
704704
public disable(): GridStack {
705-
if (this.opts.staticGrid) { return; }
705+
if (this.opts.staticGrid) return;
706706
this.enableMove(false);
707707
this.enableResize(false);
708708
this._triggerEvent('disable');
@@ -718,7 +718,7 @@ export class GridStack {
718718
* grid.enableResize(true);
719719
*/
720720
public enable(): GridStack {
721-
if (this.opts.staticGrid) { return; }
721+
if (this.opts.staticGrid) return;
722722
this.enableMove(true);
723723
this.enableResize(true);
724724
this._triggerEvent('enable');
@@ -733,7 +733,7 @@ export class GridStack {
733733
* doEnable`s value by changing the disableDrag grid option (default: true).
734734
*/
735735
public enableMove(doEnable: boolean, includeNewWidgets = true): GridStack {
736-
if (this.opts.staticGrid) { return this; } // can't move a static grid!
736+
if (this.opts.staticGrid) return this; // can't move a static grid!
737737
this.getGridItems().forEach(el => this.movable(el, doEnable));
738738
if (includeNewWidgets) {
739739
this.opts.disableDrag = !doEnable;
@@ -748,7 +748,7 @@ export class GridStack {
748748
* doEnable`s value by changing the disableResize grid option (default: true).
749749
*/
750750
public enableResize(doEnable: boolean, includeNewWidgets = true): GridStack {
751-
if (this.opts.staticGrid) { return this; } // can't size a static grid!
751+
if (this.opts.staticGrid) return this; // can't size a static grid!
752752
this.getGridItems().forEach(el => this.resizable(el, doEnable));
753753
if (includeNewWidgets) {
754754
this.opts.disableResize = !doEnable;
@@ -978,7 +978,7 @@ export class GridStack {
978978
* @param val if true the grid become static.
979979
*/
980980
public setStatic(val: boolean): GridStack {
981-
if (this.opts.staticGrid === val) { return this; }
981+
if (this.opts.staticGrid === val) return this;
982982
this.opts.staticGrid = val;
983983
this.engine.nodes.forEach(n => this._prepareDragDropByNode(n)); // either delete Drag&drop or initialize it
984984
this._setStaticClass();
@@ -1002,7 +1002,7 @@ export class GridStack {
10021002
}
10031003

10041004
GridStack.getElements(els).forEach(el => {
1005-
if (!el || !el.gridstackNode) { return; }
1005+
if (!el || !el.gridstackNode) return;
10061006
let n = el.gridstackNode;
10071007
let w = {...opt}; // make a copy we can modify in case they re-use it or multiple items
10081008
delete w.autoPosition;
@@ -1111,7 +1111,7 @@ export class GridStack {
11111111

11121112
/** @internal */
11131113
private _triggerChangeEvent(): GridStack {
1114-
if (this.engine.batchMode) { return this; }
1114+
if (this.engine.batchMode) return this;
11151115
let elements = this.engine.getDirtyNodes(true); // verify they really changed
11161116
if (elements && elements.length) {
11171117
if (!this._ignoreLayoutsNodeChange) {
@@ -1125,7 +1125,7 @@ export class GridStack {
11251125

11261126
/** @internal */
11271127
private _triggerAddEvent(): GridStack {
1128-
if (this.engine.batchMode) { return this }
1128+
if (this.engine.batchMode) return this;
11291129
if (this.engine.addedNodes && this.engine.addedNodes.length > 0) {
11301130
if (!this._ignoreLayoutsNodeChange) {
11311131
this.engine.layoutsNodesChange(this.engine.addedNodes);
@@ -1140,7 +1140,7 @@ export class GridStack {
11401140

11411141
/** @internal */
11421142
public _triggerRemoveEvent(): GridStack {
1143-
if (this.engine.batchMode) { return this; }
1143+
if (this.engine.batchMode) return this;
11441144
if (this.engine.removedNodes && this.engine.removedNodes.length > 0) {
11451145
this._triggerEvent('removed', this.engine.removedNodes);
11461146
this.engine.removedNodes = [];
@@ -1189,7 +1189,7 @@ export class GridStack {
11891189
// insert style to parent (instead of 'head' by default) to support WebComponent
11901190
let styleLocation = this.opts.styleInHead ? undefined : this.el.parentNode as HTMLElement;
11911191
this._styles = Utils.createStylesheet(id, styleLocation);
1192-
if (!this._styles) { return this; }
1192+
if (!this._styles) return this;
11931193
this._styles._id = id;
11941194
this._styles._max = 0;
11951195

@@ -1231,7 +1231,7 @@ export class GridStack {
12311231

12321232
/** @internal */
12331233
private _updateContainerHeight(): GridStack {
1234-
if (!this.engine || this.engine.batchMode) { return this; }
1234+
if (!this.engine || this.engine.batchMode) return this;
12351235
let row = this.getRow(); // checks for minRow already
12361236
// check for css min height
12371237
let cssMinHeight = parseInt(getComputedStyle(this.el)['min-height']);
@@ -1248,7 +1248,7 @@ export class GridStack {
12481248
}
12491249
let cellHeight = this.opts.cellHeight as number;
12501250
let unit = this.opts.cellHeightUnit;
1251-
if (!cellHeight) { return this }
1251+
if (!cellHeight) return this;
12521252
this.el.style.height = row * cellHeight + unit;
12531253
return this;
12541254
}
@@ -1338,7 +1338,7 @@ export class GridStack {
13381338

13391339
// remove any key not found (null or false which is default)
13401340
for (const key in node) {
1341-
if (!node.hasOwnProperty(key)) { return; }
1341+
if (!node.hasOwnProperty(key)) return;
13421342
if (!node[key] && node[key] !== 0) { // 0 can be valid value (x,y only really)
13431343
delete node[key];
13441344
}
@@ -1379,12 +1379,12 @@ export class GridStack {
13791379
}
13801380

13811381
if (!this.opts.disableOneColumnMode && this.el.clientWidth <= this.opts.minWidth) {
1382-
if (this._oneColumnMode) { return this }
1382+
if (this._oneColumnMode) return this;
13831383
this._oneColumnMode = true;
13841384
this.column(1);
13851385
this._resizeNestedGrids(this.el);
13861386
} else {
1387-
if (!this._oneColumnMode) { return this }
1387+
if (!this._oneColumnMode) return this;
13881388
delete this._oneColumnMode;
13891389
this.column(this._prevColumn);
13901390
this._resizeNestedGrids(this.el);
@@ -1497,25 +1497,25 @@ export class GridStack {
14971497
* @param els widget or selector to modify.
14981498
* @param val if true widget will be draggable.
14991499
*/
1500-
public movable(els: GridStackElement, val: boolean): GridStack { return this; }
1500+
public movable(els: GridStackElement, val: boolean): GridStack { return this }
15011501
/**
15021502
* Enables/Disables resizing. No-op for static grids.
15031503
* @param els widget or selector to modify
15041504
* @param val if true widget will be resizable.
15051505
*/
1506-
public resizable(els: GridStackElement, val: boolean): GridStack { return this; }
1506+
public resizable(els: GridStackElement, val: boolean): GridStack { return this }
15071507
/** @internal called to add drag over support to support widgets */
1508-
public _setupAcceptWidget(): GridStack { return this; }
1508+
public _setupAcceptWidget(): GridStack { return this }
15091509
/** @internal called to setup a trash drop zone if the user specifies it */
1510-
public _setupRemoveDrop(): GridStack { return this; }
1510+
public _setupRemoveDrop(): GridStack { return this }
15111511
/** @internal */
1512-
public _setupRemovingTimeout(el: GridItemHTMLElement): GridStack { return this; }
1512+
public _setupRemovingTimeout(el: GridItemHTMLElement): GridStack { return this }
15131513
/** @internal */
1514-
public _clearRemovingTimeout(el: GridItemHTMLElement): GridStack { return this; }
1514+
public _clearRemovingTimeout(el: GridItemHTMLElement): GridStack { return this }
15151515
/** @internal call to setup dragging in from the outside (say toolbar), with options */
15161516
public _setupDragIn(): GridStack {return this; }
15171517
/** @internal prepares the element for drag&drop **/
1518-
public _prepareDragDropByNode(node: GridStackNode): GridStack { return this; }
1518+
public _prepareDragDropByNode(node: GridStackNode): GridStack { return this }
15191519

15201520
// 2.x API that just calls the new and better update() - keep those around for backward compat only...
15211521
/** @internal */

src/h5/dd-base-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export abstract class DDBaseImplement {
3838
}
3939

4040
public triggerEvent(eventName: string, event: Event): boolean|void {
41-
if (this.disabled) { return; }
41+
if (this.disabled) return;
4242
if (!this._eventRegister) {return; } // used when destroy before triggerEvent fire
4343
if (this._eventRegister[eventName]) {
4444
return this._eventRegister[eventName](event);

src/h5/dd-droppable.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt
5050
}
5151

5252
public enable(): void {
53-
if (!this.disabled) { return; }
53+
if (!this.disabled) return;
5454
super.enable();
5555
this.el.classList.remove('ui-droppable-disabled');
5656
this.el.addEventListener('dragenter', this._dragEnter);
5757
}
5858

5959
public disable(): void {
60-
if (this.disabled) { return; }
60+
if (this.disabled) return;
6161
super.disable();
6262
this.el.classList.add('ui-droppable-disabled');
6363
this.el.removeEventListener('dragenter', this._dragEnter);
@@ -107,7 +107,7 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt
107107

108108
/** @internal called when the item is leaving our area, stop tracking if we had acceptable item */
109109
private _dragLeave(event: DragEvent): void {
110-
if (this.el.contains(event.relatedTarget as HTMLElement)) { return; }
110+
if (this.el.contains(event.relatedTarget as HTMLElement)) return;
111111
this._removeLeaveCallbacks();
112112
if (this.acceptable) {
113113
event.preventDefault();
@@ -121,7 +121,7 @@ export class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt
121121

122122
/** @internal item is being dropped on us - call the client drop event */
123123
private _drop(event: DragEvent): void {
124-
if (!this.acceptable) { return; } // should not have received event...
124+
if (!this.acceptable) return; // should not have received event...
125125
event.preventDefault();
126126
const ev = DDUtils.initEvent<DragEvent>(event, { target: this.el, type: 'drop' });
127127
if (this.option.drop) {

src/h5/gridstack-dd-native.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class GridStackDDNative extends GridStackDD {
133133
/** @internal returns a list of DD elements, creating them on the fly by default */
134134
private _getDDElements(els: GridStackElement, create = true): DDElement[] {
135135
let hosts = Utils.getElements(els) as DDElementHost[];
136-
if (!hosts.length) { return []; }
136+
if (!hosts.length) return [];
137137
let list = hosts.map(e => e.ddElement || (create ? DDElement.init(e) : null));
138138
if (!create) { list.filter(d => d); } // remove nulls
139139
return list;

0 commit comments

Comments
 (0)