@internal call to read any default attributes from element
(el: HTMLElement, clearDefaultAttr = true)
| 1961 | |
| 1962 | /** @internal call to read any default attributes from element */ |
| 1963 | protected _readAttr(el: HTMLElement, clearDefaultAttr = true): GridStackWidget { |
| 1964 | const n: GridStackNode = {}; |
| 1965 | n.x = Utils.toNumber(el.getAttribute('gs-x')); |
| 1966 | n.y = Utils.toNumber(el.getAttribute('gs-y')); |
| 1967 | n.w = Utils.toNumber(el.getAttribute('gs-w')); |
| 1968 | n.h = Utils.toNumber(el.getAttribute('gs-h')); |
| 1969 | n.autoPosition = Utils.toBool(el.getAttribute('gs-auto-position')); |
| 1970 | n.noResize = Utils.toBool(el.getAttribute('gs-no-resize')); |
| 1971 | n.noMove = Utils.toBool(el.getAttribute('gs-no-move')); |
| 1972 | n.locked = Utils.toBool(el.getAttribute('gs-locked')); |
| 1973 | const attr = el.getAttribute('gs-size-to-content'); |
| 1974 | if (attr) { |
| 1975 | if (attr === 'true' || attr === 'false') n.sizeToContent = Utils.toBool(attr); |
| 1976 | else n.sizeToContent = parseInt(attr, 10); |
| 1977 | } |
| 1978 | n.id = el.getAttribute('gs-id'); |
| 1979 | |
| 1980 | // read but never written out |
| 1981 | n.maxW = Utils.toNumber(el.getAttribute('gs-max-w')); |
| 1982 | n.minW = Utils.toNumber(el.getAttribute('gs-min-w')); |
| 1983 | n.maxH = Utils.toNumber(el.getAttribute('gs-max-h')); |
| 1984 | n.minH = Utils.toNumber(el.getAttribute('gs-min-h')); |
| 1985 | |
| 1986 | // v8.x optimization to reduce un-needed attr that don't render or are default CSS |
| 1987 | if (clearDefaultAttr) { |
| 1988 | if (n.w === 1) el.removeAttribute('gs-w'); |
| 1989 | if (n.h === 1) el.removeAttribute('gs-h'); |
| 1990 | if (n.maxW) el.removeAttribute('gs-max-w'); |
| 1991 | if (n.minW) el.removeAttribute('gs-min-w'); |
| 1992 | if (n.maxH) el.removeAttribute('gs-max-h'); |
| 1993 | if (n.minH) el.removeAttribute('gs-min-h'); |
| 1994 | } |
| 1995 | |
| 1996 | // remove any key not found (null or false which is default, unless sizeToContent=false override) |
| 1997 | for (const key in n) { |
| 1998 | if (!n.hasOwnProperty(key)) return; |
| 1999 | if (!n[key] && n[key] !== 0 && key !== 'sizeToContent') { // 0 can be valid value (x,y only really) |
| 2000 | delete n[key]; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | return n; |
| 2005 | } |
| 2006 | |
| 2007 | /** @internal */ |
| 2008 | protected _setStaticClass(): GridStack { |
no test coverage detected