MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / _writePosAttr

Method _writePosAttr

src/gridstack.ts:1920–1937  ·  view source on GitHub ↗

@internal write position CSS vars and x,y,w,h attributes (not used for CSS but by users) back to element

(el: HTMLElement, n: GridStackNode)

Source from the content-addressed store, hash-verified

1918
1919 /** @internal write position CSS vars and x,y,w,h attributes (not used for CSS but by users) back to element */
1920 protected _writePosAttr(el: HTMLElement, n: GridStackNode): GridStack {
1921 // Avoid overwriting the inline style of the element during drag/resize, but always update the placeholder
1922 if ((!n._moving && !n._resizing) || this._placeholder === el) {
1923 const xProp = this.opts.rtl ? 'right' : 'left';
1924 // width/height:1 x/y:0 is set by default in the main CSS, so no need to set inlined vars
1925 el.style.top = n.y ? (n.y === 1 ? `var(--gs-cell-height)` : `calc(${n.y} * var(--gs-cell-height))`) : null;
1926 el.style[xProp] = n.x ? (n.x === 1 ? `var(--gs-column-width)` : `calc(${n.x} * var(--gs-column-width))`) : null;
1927 el.style.width = n.w > 1 ? `calc(${n.w} * var(--gs-column-width))` : null;
1928 el.style.height = n.h > 1 ? `calc(${n.h} * var(--gs-cell-height))` : null;
1929 }
1930 // NOTE: those are technically not needed anymore (v12+) as we have CSS vars for everything, but some users depends on them to render item size using CSS
1931 // ALways write x,y otherwise it could be autoPositioned incorrectly #3181
1932 el.setAttribute('gs-x', String(n.x));
1933 el.setAttribute('gs-y', String(n.y));
1934 n.w > 1 ? el.setAttribute('gs-w', String(n.w)) : el.removeAttribute('gs-w');
1935 n.h > 1 ? el.setAttribute('gs-h', String(n.h)) : el.removeAttribute('gs-h');
1936 return this;
1937 }
1938
1939 /** @internal call to write any default attributes back to element */
1940 protected _writeAttr(el: HTMLElement, node: GridStackNode): GridStack {

Callers 5

constructorMethod · 0.95
_writeAttrMethod · 0.95
onEndMovingMethod · 0.95
_onStartMovingMethod · 0.95
_dragOrResizeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected