* Create the default grid item divs and content (possibly lazy loaded) by using GridStack.renderCB(). * * @param n GridStackNode definition containing widget configuration * @returns the created HTML element with proper grid item structure * * @example * const element = grid.create
(n: GridStackNode)
| 476 | * const element = grid.createWidgetDivs({ w: 2, h: 1, content: 'Hello World' }); |
| 477 | */ |
| 478 | public createWidgetDivs(n: GridStackNode): HTMLElement { |
| 479 | const el = Utils.createDiv(['grid-stack-item', this.opts.itemClass]); |
| 480 | const cont = Utils.createDiv(['grid-stack-item-content'], el); |
| 481 | |
| 482 | if (Utils.lazyLoad(n)) { |
| 483 | if (!n.visibleObservable) { |
| 484 | n.visibleObservable = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) { |
| 485 | n.visibleObservable?.disconnect(); |
| 486 | delete n.visibleObservable; |
| 487 | GridStack.renderCB(cont, n); |
| 488 | n.grid?.prepareDragDrop(n.el); |
| 489 | }}); |
| 490 | window.setTimeout(() => n.visibleObservable?.observe(el)); // wait until callee sets position attributes |
| 491 | } |
| 492 | } else GridStack.renderCB(cont, n); |
| 493 | |
| 494 | return el; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Convert an existing gridItem element into a sub-grid with the given (optional) options, else inherit them |
no test coverage detected