Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/216/destroy param #346

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

Merged
merged 2 commits into from
Feb 22, 2016
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ Changes
- add `setAnimation` method to API
- add `setGridWidth` method ([#227](https://github.com/troolee/gridstack.js/issues/227))
- add `removable`/`removeTimeout`
- add `detachGrid` parameter to `destroy` method ([#216](https://github.com/troolee/gridstack.js/issues/216))

#### v0.2.4 (2016-02-15)

Expand Down
8 changes: 6 additions & 2 deletions dist/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,14 @@
this._updateContainerHeight();
};

GridStack.prototype.destroy = function() {
GridStack.prototype.destroy = function(detachGrid) {
$(window).off('resize', this.onResizeHandler);
this.disable();
this.container.remove();
if (typeof detachGrid != 'undefined' && !detachGrid) {
this.removeAll(true);
} else {
this.container.remove();
}
Utils.removeStylesheet(this._stylesId);
if (this.grid) {
this.grid = null;
Expand Down
2 changes: 1 addition & 1 deletion dist/gridstack.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/gridstack.min.map

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gridstack.js API
- [cellHeight(val)](#cellheightval)
- [cellWidth()](#cellwidth)
- [commit()](#commit)
- [destroy()](#destroy)
- [destroy([detachGrid])](#destroydetachgrid)
- [disable()](#disable)
- [enable()](#enable)
- [enableMove(doEnable, includeNewWidgets)](#enablemovedoenable-includenewwidgets)
Expand All @@ -38,8 +38,8 @@ gridstack.js API
- [minWidth(el, val)](#minwidthel-val)
- [movable(el, val)](#movableel-val)
- [move(el, x, y)](#moveel-x-y)
- [removeWidget(el, detachNode)](#removewidgetel-detachnode)
- [removeAll()](#removeall)
- [removeWidget(el[, detachNode])](#removewidgetel-detachnode)
- [removeAll([detachNode])](#removealldetachnode)
- [resize(el, width, height)](#resizeel-width-height)
- [resizable(el, val)](#resizableel-val)
- [setAnimation(doAnimate)](#setanimationdoanimate)
Expand Down Expand Up @@ -220,10 +220,14 @@ Gets current cell width.

Finishes batch updates. Updates DOM nodes. You must call it after `batchUpdate`.

### destroy()
### destroy([detachGrid])

Destroys a grid instance.

Parameters:

- `detachGrid` - if `false` nodes and grid will not be removed from the DOM (Optional. Default `true`).

### disable()

Disables widgets moving/resizing. This is a shortcut for:
Expand Down Expand Up @@ -340,19 +344,23 @@ Parameters:
- `el` - widget to move
- `x`, `y` - new position. If value is `null` or `undefined` it will be ignored.

### removeWidget(el, detachNode)
### removeWidget(el[, detachNode])

Removes widget from the grid.

Parameters:

- `el` - widget to remove.
- `detachNode` - if `false` DOM node won't be removed from the tree (Optional. Default `true`).
- `detachNode` - if `false` node won't be removed from the DOM (Optional. Default `true`).

### removeAll()
### removeAll([detachNode])

Removes all widgets from the grid.

Parameters:

- `detachNode` - if `false` nodes won't be removed from the DOM (Optional. Default `true`).

### resize(el, width, height)

Changes widget size
Expand Down
8 changes: 6 additions & 2 deletions src/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,14 @@
this._updateContainerHeight();
};

GridStack.prototype.destroy = function() {
GridStack.prototype.destroy = function(detachGrid) {
$(window).off('resize', this.onResizeHandler);
this.disable();
this.container.remove();
if (typeof detachGrid != 'undefined' && !detachGrid) {
this.removeAll(true);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be false? Otherwise, when detachGrid === false, we won't remove the grid container, but we will remove all of the widgets.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely correct. This should be this.removeAll(false). We're in the process of adding in unit tests, and clearly have not added this yet. Apologies for the mixup - I'll fix this and have it pushed out momentarily. Thanks for finding and reporting this bug - saved someone lots of frustration down the road. I hope this didn't cause you much issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been updated. Thank you again for finding this!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! Thanks for the quick turnaround.

} else {
this.container.remove();
}
Utils.removeStylesheet(this._stylesId);
if (this.grid) {
this.grid = null;
Expand Down