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

addGrid() checks for nested '.grid-stack' div #1689

Merged
merged 1 commit into from
Mar 27, 2021
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
2 changes: 2 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Change log
- fix [#1679](https://github.com/gridstack/gridstack.js/issues/1679) `Resizable: {handles:'w/sw'}` work again in 4.x
- fix [#1658](https://github.com/gridstack/gridstack.js/issues/1658) `enableMove(T/F)` not working correctly
- fix `helper: myFunction` now working for H5 case for `dragInOptions` & `setupDragIn()`
- fix prevent `addGrid()` from creating nested div grid if container already is a '.grid-stack' div

## 4.0.1 (2021-3-20)

- fix [#1669](https://github.com/gridstack/gridstack.js/issues/1669) JQ resize broken
Expand Down
4 changes: 1 addition & 3 deletions src/gridstack-dd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ GridStack.prototype._setupAcceptWidget = function(): GridStack {
if (!node) return;

helper = helper || el;
// let left = event.pageX - gridPos.left;
// let top = event.pageY - gridPos.top;
let rec = helper.getBoundingClientRect();
let left = rec.left - gridPos.left;
let top = rec.top - gridPos.top;
Expand Down Expand Up @@ -532,7 +530,7 @@ GridStack.prototype._leave = function(node: GridStackNode, el: GridItemHTMLEleme

/** @internal called when item is being dragged/resized */
GridStack.prototype._dragOrResize = function(el: GridItemHTMLElement, event: Event, ui: DDUIData, node: GridStackNode, cellWidth: number, cellHeight: number) {
let p = {...node._orig};
let p = {...node._orig}; // could be undefined (_isExternal) which is ok (drag only set x,y and w,h will default to node value)
let resizing: boolean;

if (event.type === 'drag') {
Expand Down
13 changes: 8 additions & 5 deletions src/gridstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ export class GridStack {
public static addGrid(parent: HTMLElement, opt: GridStackOptions = {}): GridStack {
if (!parent) return null;

// create the grid element
let doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = `<div class="grid-stack ${opt.class || ''}"></div>`;
let el = doc.body.children[0] as HTMLElement;
parent.appendChild(el);
// create the grid element, but check if the passed 'parent' already has grid styling and should be used instead
let el = parent;
if (!parent.classList.contains('grid-stack')) {
let doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = `<div class="grid-stack ${opt.class || ''}"></div>`;
el = doc.body.children[0] as HTMLElement;
parent.appendChild(el);
}

// create grid class and load any children
let grid = GridStack.init(opt, el);
Expand Down