* called when we are being resized - check if the one Column Mode needs to be turned on/off * and remember the prev columns we used, or get our count from parent, as well as check for cellHeight==='auto' (square) * or `sizeToContent` gridItem options.
(clientWidth = this.el?.clientWidth)
| 2025 | * or `sizeToContent` gridItem options. |
| 2026 | */ |
| 2027 | public onResize(clientWidth = this.el?.clientWidth): GridStack { |
| 2028 | if (!clientWidth) return; // return if we're gone or no size yet (will get called again) |
| 2029 | if (this.prevWidth === clientWidth) return; // no-op |
| 2030 | this.prevWidth = clientWidth |
| 2031 | // console.log('onResize ', clientWidth); |
| 2032 | |
| 2033 | this.batchUpdate(); |
| 2034 | |
| 2035 | // see if we're nested and take our column count from our parent.... |
| 2036 | let columnChanged = false; |
| 2037 | if (this._autoColumn && this.parentGridNode) { |
| 2038 | if (this.opts.column !== this.parentGridNode.w) { |
| 2039 | this.column(this.parentGridNode.w, this.opts.layout || 'list'); |
| 2040 | columnChanged = true; |
| 2041 | } |
| 2042 | } else { |
| 2043 | // else check for dynamic column |
| 2044 | columnChanged = this.checkDynamicColumn(); |
| 2045 | } |
| 2046 | |
| 2047 | // make the cells content square again |
| 2048 | if (this._isAutoCellHeight) this.cellHeight(); |
| 2049 | |
| 2050 | // update any nested grids, or items size |
| 2051 | this.engine.nodes.forEach(n => { |
| 2052 | if (n.subGrid) n.subGrid.onResize() |
| 2053 | }); |
| 2054 | |
| 2055 | if (!this._skipInitialResize) this.resizeToContentCheck(columnChanged); // wait for anim of column changed (DOM reflow before we can size correctly) |
| 2056 | delete this._skipInitialResize; |
| 2057 | |
| 2058 | this.batchUpdate(false); |
| 2059 | |
| 2060 | return this; |
| 2061 | } |
| 2062 | |
| 2063 | /** resizes content for given node (or all) if shouldSizeToContent() is true */ |
| 2064 | private resizeToContentCheck(delay = false, n: GridStackNode = undefined) { |
no test coverage detected