Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't call movable()/resizable() on locked items #1513

Merged
merged 1 commit into from
Dec 2, 2020
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
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Change log
see [nested.html](https://github.com/gridstack/gridstack.js/blob/develop/demo/nested.html) demo.
- `save()` will now work on nested grids, recursively saving info. added flag to also allow saving the current grid options + children
(needed for nested grids) so you can now call new `adddGrid()` to re-create everything from JSON.
- 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)

## 3.3.0 (2020-11-29)

Expand Down
8 changes: 4 additions & 4 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,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 (val && 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) { return }
if (!node || node.locked) { return }
node.noMove = !(val || false);
if (node.noMove) {
GridStackDD.get().draggable(el, 'disable');
Expand All @@ -525,10 +525,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 (val && 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) { return; }
if (!node || node.locked) { return; }
node.noResize = !(val || false);
if (node.noResize) {
GridStackDD.get().resizable(el, 'disable');
Expand Down
23 changes: 15 additions & 8 deletions src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,40 +678,47 @@ export class GridStack {
}

/**
* Disables widgets moving/resizing. This is a shortcut for:
* Temporarily disables widgets moving/resizing.
* If you want a more permanent way (which freezes up resources) use `setStatic(true)` instead.
* Note: no-op for static grid
* This is a shortcut for:
* @example
* grid.enableMove(false);
* grid.enableResize(false);
*/
public disable(): GridStack {
if (this.opts.staticGrid) { return; }
this.enableMove(false);
this.enableResize(false);
this._triggerEvent('disable');
return this;
}

/**
* Enables widgets moving/resizing. This is a shortcut for:
* Re-enables widgets moving/resizing - see disable().
* Note: no-op for static grid.
* This is a shortcut for:
* @example
* grid.enableMove(true);
* grid.enableResize(true);
*/
public enable(): GridStack {
if (this.opts.staticGrid) { return; }
this.enableMove(true);
this.enableResize(true);
this._triggerEvent('enable');
return this;
}

/**
* Enables/disables widget moving.
* Enables/disables widget moving. No-op for static grids.
*
* @param doEnable
* @param includeNewWidgets will force new widgets to be draggable as per
* doEnable`s value by changing the disableDrag grid option (default: true).
*/
public enableMove(doEnable: boolean, includeNewWidgets = true): GridStack {
if (doEnable && 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 @@ -720,13 +727,13 @@ export class GridStack {
}

/**
* Enables/disables widget resizing
* Enables/disables widget resizing. No-op for static grids.
* @param doEnable
* @param includeNewWidgets will force new widgets to be draggable as per
* doEnable`s value by changing the disableResize grid option (default: true).
*/
public enableResize(doEnable: boolean, includeNewWidgets = true): GridStack {
if (doEnable && 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 @@ -1465,13 +1472,13 @@ export class GridStack {
/* eslint-disable @typescript-eslint/no-unused-vars */

/**
* Enables/Disables moving.
* Enables/Disables moving. No-op for static grids.
* @param els widget or selector to modify.
* @param val if true widget will be draggable.
*/
public movable(els: GridStackElement, val: boolean): GridStack { return this; }
/**
* Enables/Disables resizing.
* Enables/Disables resizing. No-op for static grids.
* @param els widget or selector to modify
* @param val if true widget will be resizable.
*/
Expand Down
12 changes: 4 additions & 8 deletions src/h5/gridstack-dd-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ export class GridStackDDNative extends GridStackDD {
public resizable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDDNative {
this._getDDElements(el).forEach(dEl => {
if (opts === 'disable' || opts === 'enable') {
dEl.ddResizable && dEl.ddResizable[opts]();
dEl.ddResizable && dEl.ddResizable[opts](); // can't create DD as it requires options for setupResizable()
} else if (opts === 'destroy') {
if (dEl.ddResizable) {
dEl.cleanResizable();
}
dEl.ddResizable && dEl.cleanResizable();
} else if (opts === 'option') {
dEl.setupResizable({ [key]: value });
} else {
Expand All @@ -51,11 +49,9 @@ export class GridStackDDNative extends GridStackDD {
public draggable(el: GridItemHTMLElement, opts: DDOpts, key?: DDKey, value?: DDValue): GridStackDDNative {
this._getDDElements(el).forEach(dEl => {
if (opts === 'disable' || opts === 'enable') {
dEl.ddDraggable && dEl.ddDraggable[opts]();
dEl.ddDraggable && dEl.ddDraggable[opts](); // can't create DD as it requires options for setupDraggable()
} else if (opts === 'destroy') {
if (dEl.ddDraggable) { // error to call destroy if not there
dEl.cleanDraggable();
}
dEl.ddDraggable && dEl.cleanDraggable();
} else if (opts === 'option') {
dEl.setupDraggable({ [key]: value });
} else {
Expand Down