Skip to content

Commit 8017391

Browse files
authored
Merge pull request #2122 from adumesny/master
disable/enable recursive by default
2 parents c6f4500 + 188618f commit 8017391

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Change log
7979

8080
## 7.1.1-dev (TBD)
8181
* fix [#939](https://github.com/gridstack/gridstack.js/issues/2039) 'prototype' undefined error for dd-gridstack.js
82+
* add [#939](https://github.com/gridstack/gridstack.js/issues/2105) disable/enable are methods now recursive by default
8283

8384
## 7.1.1 (2022-11-13)
8485
* fix [#939](https://github.com/gridstack/gridstack.js/issues/939) editable elements focus (regression in v6). Thank you [@Gezdy](https://github.com/Gezdy)

src/gridstack.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,13 +1087,18 @@ export class GridStack {
10871087
* Toggle the grid static state, which permanently removes/add Drag&Drop support, unlike disable()/enable() that just turns it off/on.
10881088
* Also toggle the grid-stack-static class.
10891089
* @param val if true the grid become static.
1090+
* @param updateClass true (default) if css class gets updated
1091+
* @param recurse true (default) if sub-grids also get updated
10901092
*/
1091-
public setStatic(val: boolean, updateClass = true): GridStack {
1093+
public setStatic(val: boolean, updateClass = true, recurse = true): GridStack {
10921094
if (this.opts.staticGrid === val) return this;
10931095
this.opts.staticGrid = val;
10941096
this._setupRemoveDrop();
10951097
this._setupAcceptWidget();
1096-
this.engine.nodes.forEach(n => this._prepareDragDropByNode(n)); // either delete or init Drag&drop
1098+
this.engine.nodes.forEach(n => {
1099+
this._prepareDragDropByNode(n); // either delete or init Drag&drop
1100+
if (n.subGrid && recurse) (n.subGrid as GridStack).setStatic(val, updateClass, recurse);
1101+
});
10971102
if (updateClass) { this._setStaticClass(); }
10981103
return this;
10991104
}
@@ -1675,11 +1680,12 @@ export class GridStack {
16751680
* @example
16761681
* grid.enableMove(false);
16771682
* grid.enableResize(false);
1683+
* @param recurse true (default) if sub-grids also get updated
16781684
*/
1679-
public disable(): GridStack {
1685+
public disable(recurse = true): GridStack {
16801686
if (this.opts.staticGrid) return;
1681-
this.enableMove(false);
1682-
this.enableResize(false);// @ts-ignore
1687+
this.enableMove(false, recurse);
1688+
this.enableResize(false, recurse);// @ts-ignore
16831689
this._triggerEvent('disable');
16841690
return this;
16851691
}
@@ -1690,32 +1696,41 @@ export class GridStack {
16901696
* @example
16911697
* grid.enableMove(true);
16921698
* grid.enableResize(true);
1699+
* @param recurse true (default) if sub-grids also get updated
16931700
*/
1694-
public enable(): GridStack {
1701+
public enable(recurse = true): GridStack {
16951702
if (this.opts.staticGrid) return;
1696-
this.enableMove(true);
1697-
this.enableResize(true);// @ts-ignore
1703+
this.enableMove(true, recurse);
1704+
this.enableResize(true, recurse);// @ts-ignore
16981705
this._triggerEvent('enable');
16991706
return this;
17001707
}
17011708

17021709
/**
17031710
* Enables/disables widget moving. No-op for static grids.
1711+
* @param recurse true (default) if sub-grids also get updated
17041712
*/
1705-
public enableMove(doEnable: boolean): GridStack {
1713+
public enableMove(doEnable: boolean, recurse = true): GridStack {
17061714
if (this.opts.staticGrid) return this; // can't move a static grid!
17071715
this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
1708-
this.engine.nodes.forEach(n => this.movable(n.el, doEnable));
1716+
this.engine.nodes.forEach(n => {
1717+
this.movable(n.el, doEnable);
1718+
if (n.subGrid && recurse) (n.subGrid as GridStack).enableMove(doEnable, recurse);
1719+
});
17091720
return this;
17101721
}
17111722

17121723
/**
17131724
* Enables/disables widget resizing. No-op for static grids.
1725+
* @param recurse true (default) if sub-grids also get updated
17141726
*/
1715-
public enableResize(doEnable: boolean): GridStack {
1727+
public enableResize(doEnable: boolean, recurse = true): GridStack {
17161728
if (this.opts.staticGrid) return this; // can't size a static grid!
17171729
this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
1718-
this.engine.nodes.forEach(n => this.resizable(n.el, doEnable));
1730+
this.engine.nodes.forEach(n => {
1731+
this.resizable(n.el, doEnable);
1732+
if (n.subGrid && recurse) (n.subGrid as GridStack).enableResize(doEnable, recurse);
1733+
});
17191734
return this;
17201735
}
17211736

0 commit comments

Comments
 (0)