Skip to content

Commit 972cf41

Browse files
authored
Merge pull request #1513 from adumesny/develop
don't call movable()/resizable() on locked items
2 parents 1385b56 + d74bd46 commit 972cf41

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Change log
4848
see [nested.html](https://github.com/gridstack/gridstack.js/blob/develop/demo/nested.html) demo.
4949
- `save()` will now work on nested grids, recursively saving info. added flag to also allow saving the current grid options + children
5050
(needed for nested grids) so you can now call new `adddGrid()` to re-create everything from JSON.
51+
- fix [1505](https://github.com/gridstack/gridstack.js/issues/1505) don't call `movable()`/`resizable()` on locked items error. thanks [@infime](https://github.com/infime)
5152

5253
## 3.3.0 (2020-11-29)
5354

src/gridstack-dd.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,10 @@ GridStack.prototype._prepareDragDropByNode = function(node: GridStackNode): Grid
502502
* @param val if true widget will be draggable.
503503
*/
504504
GridStack.prototype.movable = function(els: GridStackElement, val: boolean): GridStack {
505-
if (val && this.opts.staticGrid) { return this; } // can't move a static grid!
505+
if (this.opts.staticGrid) { return this; } // can't move a static grid!
506506
GridStack.getElements(els).forEach(el => {
507507
let node = el.gridstackNode;
508-
if (!node) { return }
508+
if (!node || node.locked) { return }
509509
node.noMove = !(val || false);
510510
if (node.noMove) {
511511
GridStackDD.get().draggable(el, 'disable');
@@ -525,10 +525,10 @@ GridStack.prototype.movable = function(els: GridStackElement, val: boolean): Gri
525525
* @param val if true widget will be resizable.
526526
*/
527527
GridStack.prototype.resizable = function(els: GridStackElement, val: boolean): GridStack {
528-
if (val && this.opts.staticGrid) { return this; } // can't resize a static grid!
528+
if (this.opts.staticGrid) { return this; } // can't resize a static grid!
529529
GridStack.getElements(els).forEach(el => {
530530
let node = el.gridstackNode;
531-
if (!node) { return; }
531+
if (!node || node.locked) { return; }
532532
node.noResize = !(val || false);
533533
if (node.noResize) {
534534
GridStackDD.get().resizable(el, 'disable');

src/gridstack.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -678,40 +678,47 @@ export class GridStack {
678678
}
679679

680680
/**
681-
* Disables widgets moving/resizing. This is a shortcut for:
681+
* Temporarily disables widgets moving/resizing.
682+
* If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
683+
* Note: no-op for static grid
684+
* This is a shortcut for:
682685
* @example
683686
* grid.enableMove(false);
684687
* grid.enableResize(false);
685688
*/
686689
public disable(): GridStack {
690+
if (this.opts.staticGrid) { return; }
687691
this.enableMove(false);
688692
this.enableResize(false);
689693
this._triggerEvent('disable');
690694
return this;
691695
}
692696

693697
/**
694-
* Enables widgets moving/resizing. This is a shortcut for:
698+
* Re-enables widgets moving/resizing - see disable().
699+
* Note: no-op for static grid.
700+
* This is a shortcut for:
695701
* @example
696702
* grid.enableMove(true);
697703
* grid.enableResize(true);
698704
*/
699705
public enable(): GridStack {
706+
if (this.opts.staticGrid) { return; }
700707
this.enableMove(true);
701708
this.enableResize(true);
702709
this._triggerEvent('enable');
703710
return this;
704711
}
705712

706713
/**
707-
* Enables/disables widget moving.
714+
* Enables/disables widget moving. No-op for static grids.
708715
*
709716
* @param doEnable
710717
* @param includeNewWidgets will force new widgets to be draggable as per
711718
* doEnable`s value by changing the disableDrag grid option (default: true).
712719
*/
713720
public enableMove(doEnable: boolean, includeNewWidgets = true): GridStack {
714-
if (doEnable && this.opts.staticGrid) { return this; } // can't move a static grid!
721+
if (this.opts.staticGrid) { return this; } // can't move a static grid!
715722
this.getGridItems().forEach(el => this.movable(el, doEnable));
716723
if (includeNewWidgets) {
717724
this.opts.disableDrag = !doEnable;
@@ -720,13 +727,13 @@ export class GridStack {
720727
}
721728

722729
/**
723-
* Enables/disables widget resizing
730+
* Enables/disables widget resizing. No-op for static grids.
724731
* @param doEnable
725732
* @param includeNewWidgets will force new widgets to be draggable as per
726733
* doEnable`s value by changing the disableResize grid option (default: true).
727734
*/
728735
public enableResize(doEnable: boolean, includeNewWidgets = true): GridStack {
729-
if (doEnable && this.opts.staticGrid) { return this; } // can't size a static grid!
736+
if (this.opts.staticGrid) { return this; } // can't size a static grid!
730737
this.getGridItems().forEach(el => this.resizable(el, doEnable));
731738
if (includeNewWidgets) {
732739
this.opts.disableResize = !doEnable;
@@ -1465,13 +1472,13 @@ export class GridStack {
14651472
/* eslint-disable @typescript-eslint/no-unused-vars */
14661473

14671474
/**
1468-
* Enables/Disables moving.
1475+
* Enables/Disables moving. No-op for static grids.
14691476
* @param els widget or selector to modify.
14701477
* @param val if true widget will be draggable.
14711478
*/
14721479
public movable(els: GridStackElement, val: boolean): GridStack { return this; }
14731480
/**
1474-
* Enables/Disables resizing.
1481+
* Enables/Disables resizing. No-op for static grids.
14751482
* @param els widget or selector to modify
14761483
* @param val if true widget will be resizable.
14771484
*/

src/h5/gridstack-dd-native.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ export class GridStackDDNative extends GridStackDD {
2424
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDDNative {
2525
this._getDDElements(el).forEach(dEl => {
2626
if (opts === 'disable' || opts === 'enable') {
27-
dEl.ddResizable && dEl.ddResizable[opts]();
27+
dEl.ddResizable && dEl.ddResizable[opts](); // can't create DD as it requires options for setupResizable()
2828
} else if (opts === 'destroy') {
29-
if (dEl.ddResizable) {
30-
dEl.cleanResizable();
31-
}
29+
dEl.ddResizable && dEl.cleanResizable();
3230
} else if (opts === 'option') {
3331
dEl.setupResizable({ [key]: value });
3432
} else {
@@ -51,11 +49,9 @@ export class GridStackDDNative extends GridStackDD {
5149
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDDNative {
5250
this._getDDElements(el).forEach(dEl => {
5351
if (opts === 'disable' || opts === 'enable') {
54-
dEl.ddDraggable && dEl.ddDraggable[opts]();
52+
dEl.ddDraggable && dEl.ddDraggable[opts](); // can't create DD as it requires options for setupDraggable()
5553
} else if (opts === 'destroy') {
56-
if (dEl.ddDraggable) { // error to call destroy if not there
57-
dEl.cleanDraggable();
58-
}
54+
dEl.ddDraggable && dEl.cleanDraggable();
5955
} else if (opts === 'option') {
6056
dEl.setupDraggable({ [key]: value });
6157
} else {

0 commit comments

Comments
 (0)