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

Skip to content

Commit 998ad91

Browse files
authored
Merge pull request gridstack#2969 from adumesny/master
this.createWidgetDivs() instead of static
2 parents 3954fa1 + 271efcc commit 998ad91

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

demo/sizeToContent.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ <h1>sizeToContent options demo</h1>
109109
grid.addWidget({content: `<div>New: ${text}</div>`});
110110
}
111111
function makeWidget() {
112-
let el = GridStack.createWidgetDivs(undefined, {content: `<div>New Make: ${text}</div>`}, grid.el)
112+
let el = grid.createWidgetDivs({content: `<div>New Make: ${text}</div>`}, grid.el)
113113
grid.makeWidget(el, {w:2});
114114
}
115115
function more() {

demo/two.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ <h1>Two grids demo</h1>
107107
// clone the sidepanel item so we drag a copy, and in some case ('manual') create the final widget, else sidebarContent will be used.
108108
function myClone(el) {
109109
if (el.getAttribute('gs-id') === 'manual') {
110-
return GridStack.createWidgetDivs(undefined, {w:2, content:'manual'}); // RenderCB() will be called
110+
return grids[0].createWidgetDivs({w:2, content:'manual'}); // RenderCB() will be called
111111
}
112112
el = el.cloneNode(true);
113113
// el.setAttribute('gs-id', 'foo'); // help debug #2231

src/gridstack.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,6 @@ export class GridStack {
173173
return grid;
174174
}
175175

176-
/** create the default grid item divs, and content possibly lazy loaded calling GridStack.renderCB */
177-
static createWidgetDivs(itemClass: string, n: GridStackNode): HTMLElement {
178-
const el = Utils.createDiv(['grid-stack-item', itemClass]);
179-
const cont = Utils.createDiv(['grid-stack-item-content'], el);
180-
181-
if (Utils.lazyLoad(n)) {
182-
if (!n.visibleObservable) {
183-
n.visibleObservable = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) {
184-
n.visibleObservable?.disconnect();
185-
delete n.visibleObservable;
186-
GridStack.renderCB(cont, n);
187-
n.grid?.prepareDragDrop(n.el);
188-
}});
189-
window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes
190-
}
191-
} else GridStack.renderCB(cont, n);
192-
193-
return el;
194-
}
195-
196176
/** call this method to register your engine instead of the default one.
197177
* See instead `GridStackOptions.engineClass` if you only need to
198178
* replace just one instance.
@@ -487,7 +467,7 @@ export class GridStack {
487467
} else if (GridStack.addRemoveCB) {
488468
el = GridStack.addRemoveCB(this.el, w, true, false);
489469
} else {
490-
el = GridStack.createWidgetDivs(this.opts.itemClass, node);
470+
el = this.createWidgetDivs(node);
491471
}
492472

493473
if (!el) return;
@@ -511,6 +491,26 @@ export class GridStack {
511491
return el;
512492
}
513493

494+
/** create the default grid item divs, and content (possibly lazy loaded) by using GridStack.renderCB() */
495+
public createWidgetDivs(n: GridStackNode): HTMLElement {
496+
const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]);
497+
const cont = Utils.createDiv(['grid-stack-item-content'], el);
498+
499+
if (Utils.lazyLoad(n)) {
500+
if (!n.visibleObservable) {
501+
n.visibleObservable = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) {
502+
n.visibleObservable?.disconnect();
503+
delete n.visibleObservable;
504+
GridStack.renderCB(cont, n);
505+
n.grid?.prepareDragDrop(n.el);
506+
}});
507+
window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes
508+
}
509+
} else GridStack.renderCB(cont, n);
510+
511+
return el;
512+
}
513+
514514
/**
515515
* Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them
516516
* from the parent's subGrid options.

0 commit comments

Comments
 (0)