add or remove the grid element size event handler
(forceRemove = false)
| 2086 | |
| 2087 | /** add or remove the grid element size event handler */ |
| 2088 | protected _updateResizeEvent(forceRemove = false): GridStack { |
| 2089 | // only add event if we're not nested (parent will call us) and we're auto sizing cells or supporting dynamic column (i.e. doing work) |
| 2090 | // or supporting new sizeToContent option. |
| 2091 | const trackSize = !this.parentGridNode && (this._isAutoCellHeight || this.opts.sizeToContent || this.opts.columnOpts |
| 2092 | || this.engine.nodes.find(n => n.sizeToContent)); |
| 2093 | |
| 2094 | if (!forceRemove && trackSize && !this.resizeObserver) { |
| 2095 | this._sizeThrottle = Utils.throttle(() => this.onResize(), this.opts.cellHeightThrottle); |
| 2096 | this.resizeObserver = new ResizeObserver(() => this._sizeThrottle()); |
| 2097 | this.resizeObserver.observe(this.el); |
| 2098 | this._skipInitialResize = true; // makeWidget will originally have called on startup |
| 2099 | } else if ((forceRemove || !trackSize) && this.resizeObserver) { |
| 2100 | this.resizeObserver.disconnect(); |
| 2101 | delete this.resizeObserver; |
| 2102 | delete this._sizeThrottle; |
| 2103 | } |
| 2104 | |
| 2105 | return this; |
| 2106 | } |
| 2107 | |
| 2108 | /** @internal convert a potential selector into actual element */ |
| 2109 | public static getElement(els: GridStackElement = '.grid-stack-item'): GridItemHTMLElement { return Utils.getElement(els) } |
no test coverage detected