Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/gridstack-engine-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
14 changes: 7 additions & 7 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand Down
20 changes: 10 additions & 10 deletions src/gridstack-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}

Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
Expand Down
50 changes: 25 additions & 25 deletions src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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']);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/h5/dd-base-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/h5/dd-droppable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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<DragEvent>(event, { target: this.el, type: 'drop' });
if (this.option.drop) {
Expand Down
2 changes: 1 addition & 1 deletion src/h5/gridstack-dd-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading