Skip to content

Commit 914e372

Browse files
authored
Merge pull request #2350 from adumesny/master
grid NoMove vs item NoMove support
2 parents 5b945e5 + 66ce655 commit 914e372

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

doc/CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Change log
55
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
66
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
77

8+
- [8.2.1-dev (TBD)](#821-dev-tbd)
89
- [8.2.1 (2023-05-26)](#821-2023-05-26)
910
- [8.2.0 (2023-05-24)](#820-2023-05-24)
1011
- [8.1.2 (2023-05-22)](#812-2023-05-22)
@@ -89,6 +90,9 @@ Change log
8990

9091
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
9192

93+
## 8.2.1-dev (TBD)
94+
* fix [#2349](https://github.com/gridstack/gridstack.js/issues/2349) grid NoMove vs item NoMove support
95+
9296
## 8.2.1 (2023-05-26)
9397
* fix: make sure `removeNode()` uses internal _id (unique) and not node itself (since we clone those often)
9498
* fix: after calling `addRemoveCB` make sure we don't makeWidget() (incorrectly) a second time

src/gridstack.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,8 @@ export class GridStack {
11341134
* @param recurse true (default) if sub-grids also get updated
11351135
*/
11361136
public setStatic(val: boolean, updateClass = true, recurse = true): GridStack {
1137-
if (this.opts.staticGrid === val) return this;
1138-
this.opts.staticGrid = val;
1137+
if (!!this.opts.staticGrid === val) return this;
1138+
val ? this.opts.staticGrid = true : delete this.opts.staticGrid;
11391139
this._setupRemoveDrop();
11401140
this._setupAcceptWidget();
11411141
this.engine.nodes.forEach(n => {
@@ -1686,31 +1686,31 @@ export class GridStack {
16861686
* Enables/Disables dragging by the user of specific grid element. If you want all items, and have it affect future items, use enableMove() instead. No-op for static grids.
16871687
* IF you are looking to prevent an item from moving (due to being pushed around by another during collision) use locked property instead.
16881688
* @param els widget or selector to modify.
1689-
* @param val if true widget will be draggable.
1689+
* @param val if true widget will be draggable, assuming the parent grid isn't noMove or static.
16901690
*/
16911691
public movable(els: GridStackElement, val: boolean): GridStack {
16921692
if (this.opts.staticGrid) return this; // can't move a static grid!
16931693
GridStack.getElements(els).forEach(el => {
1694-
let node = el.gridstackNode;
1695-
if (!node) return;
1696-
if (val) delete node.noMove; else node.noMove = true;
1697-
this._prepareDragDropByNode(node); // init DD if need be, and adjust
1694+
let n = el.gridstackNode;
1695+
if (!n) return;
1696+
val ? delete n.noMove : n.noMove = true;
1697+
this._prepareDragDropByNode(n); // init DD if need be, and adjust
16981698
});
16991699
return this;
17001700
}
17011701

17021702
/**
17031703
* Enables/Disables user resizing of specific grid element. If you want all items, and have it affect future items, use enableResize() instead. No-op for static grids.
17041704
* @param els widget or selector to modify
1705-
* @param val if true widget will be resizable.
1705+
* @param val if true widget will be resizable, assuming the parent grid isn't noResize or static.
17061706
*/
17071707
public resizable(els: GridStackElement, val: boolean): GridStack {
17081708
if (this.opts.staticGrid) return this; // can't resize a static grid!
17091709
GridStack.getElements(els).forEach(el => {
1710-
let node = el.gridstackNode;
1711-
if (!node) return;
1712-
if (val) delete node.noResize; else node.noResize = true;
1713-
this._prepareDragDropByNode(node); // init DD if need be, and adjust
1710+
let n = el.gridstackNode;
1711+
if (!n) return;
1712+
val ? delete n.noResize : n.noResize = true;
1713+
this._prepareDragDropByNode(n); // init DD if need be, and adjust
17141714
});
17151715
return this;
17161716
}
@@ -1728,7 +1728,7 @@ export class GridStack {
17281728
public disable(recurse = true): GridStack {
17291729
if (this.opts.staticGrid) return;
17301730
this.enableMove(false, recurse);
1731-
this.enableResize(false, recurse);// @ts-ignore
1731+
this.enableResize(false, recurse);
17321732
this._triggerEvent('disable');
17331733
return this;
17341734
}
@@ -1744,20 +1744,20 @@ export class GridStack {
17441744
public enable(recurse = true): GridStack {
17451745
if (this.opts.staticGrid) return;
17461746
this.enableMove(true, recurse);
1747-
this.enableResize(true, recurse);// @ts-ignore
1747+
this.enableResize(true, recurse);
17481748
this._triggerEvent('enable');
17491749
return this;
17501750
}
17511751

17521752
/**
1753-
* Enables/disables widget moving. No-op for static grids.
1753+
* Enables/disables widget moving. No-op for static grids, and locally defined items still overrule
17541754
* @param recurse true (default) if sub-grids also get updated
17551755
*/
17561756
public enableMove(doEnable: boolean, recurse = true): GridStack {
17571757
if (this.opts.staticGrid) return this; // can't move a static grid!
1758-
this.opts.disableDrag = !doEnable; // FIRST before we update children as grid overrides #1658
1758+
doEnable ? delete this.opts.disableDrag : this.opts.disableDrag = true; // FIRST before we update children as grid overrides #1658
17591759
this.engine.nodes.forEach(n => {
1760-
this.movable(n.el, doEnable);
1760+
this._prepareDragDropByNode(n);
17611761
if (n.subGrid && recurse) n.subGrid.enableMove(doEnable, recurse);
17621762
});
17631763
return this;
@@ -1769,9 +1769,9 @@ export class GridStack {
17691769
*/
17701770
public enableResize(doEnable: boolean, recurse = true): GridStack {
17711771
if (this.opts.staticGrid) return this; // can't size a static grid!
1772-
this.opts.disableResize = !doEnable; // FIRST before we update children as grid overrides #1658
1772+
doEnable ? delete this.opts.disableResize : this.opts.disableResize = true; // FIRST before we update children as grid overrides #1658
17731773
this.engine.nodes.forEach(n => {
1774-
this.resizable(n.el, doEnable);
1774+
this._prepareDragDropByNode(n);
17751775
if (n.subGrid && recurse) n.subGrid.enableResize(doEnable, recurse);
17761776
});
17771777
return this;

0 commit comments

Comments
 (0)