MCPcopy
hub / github.com/e-oj/Magic-Grid / positionItems

Method positionItems

src/index.js:156–198  ·  view source on GitHub ↗

* Positions each item in the grid, based * on their corresponding column's height * and index then stretches the container to * the height of the grid.

()

Source from the content-addressed store, hash-verified

154 * the height of the grid.
155 */
156 positionItems () {
157
158 if(this.isPositioning){
159 return;
160 }
161
162 this.isPositioning = true;
163
164 let { cols, wSpace } = this.setup();
165 let maxHeight = 0;
166 let colWidth = this.colWidth();
167 let items = this.items();
168
169 wSpace = this.center ? Math.floor(wSpace / 2) : 0;
170
171 this.initStyles();
172
173 for (let i = 0; i < items.length; i++) {
174 let col = this.nextCol(cols, i);
175 let item = items[i];
176 let topGutter = col.height ? this.gutter : 0;
177 let left = col.index * colWidth + wSpace + "px";
178 let top = col.height + topGutter + "px";
179
180 if(this.useTransform){
181 item.style.transform = `translate(${left}, ${top})`;
182 }
183 else{
184 item.style.top = top;
185 item.style.left = left;
186 }
187
188 col.height += item.getBoundingClientRect().height + topGutter;
189
190 if(col.height > maxHeight){
191 maxHeight = col.height;
192 }
193 }
194
195 this.container.style.height = maxHeight + this.gutter + "px";
196 this.isPositioning = false;
197 this.emit(POSITIONING_COMPLETE_EVENT);
198 }
199
200 /**
201 * Checks if every item has been loaded

Callers 4

listenMethod · 0.95
addItemsFunction · 0.80
removeItemsFunction · 0.80

Calls 6

setupMethod · 0.95
colWidthMethod · 0.95
itemsMethod · 0.95
initStylesMethod · 0.95
nextColMethod · 0.95
emitMethod · 0.80

Tested by

no test coverage detected