MCPcopy Create free account
hub / github.com/openscopeproject/InteractiveHtmlBom / resizableGrid

Function resizableGrid

InteractiveHtmlBom/web/table-util.js:300–371  ·  view source on GitHub ↗
(tablehead)

Source from the content-addressed store, hash-verified

298}
299
300function resizableGrid(tablehead) {
301 var cols = tablehead.firstElementChild.children;
302 var rowWidth = tablehead.offsetWidth;
303
304 for (var i = 1; i < cols.length; i++) {
305 if (cols[i].classList.contains("bom-checkbox"))
306 continue;
307 cols[i].style.width = ((cols[i].clientWidth - paddingDiff(cols[i])) * 100 / rowWidth) + '%';
308 }
309
310 for (var i = 1; i < cols.length - 1; i++) {
311 var div = document.createElement('div');
312 div.className = "column-width-handle";
313 cols[i].appendChild(div);
314 setListeners(div);
315 }
316
317 function setListeners(div) {
318 var startX, curCol, nxtCol, curColWidth, nxtColWidth, rowWidth;
319
320 div.addEventListener('mousedown', function(e) {
321 e.preventDefault();
322 e.stopPropagation();
323
324 curCol = e.target.parentElement;
325 nxtCol = curCol.nextElementSibling;
326 startX = e.pageX;
327
328 var padding = paddingDiff(curCol);
329
330 rowWidth = curCol.parentElement.offsetWidth;
331 curColWidth = curCol.clientWidth - padding;
332 nxtColWidth = nxtCol.clientWidth - padding;
333 });
334
335 document.addEventListener('mousemove', function(e) {
336 if (startX) {
337 var diffX = e.pageX - startX;
338 diffX = -Math.min(-diffX, curColWidth - 20);
339 diffX = Math.min(diffX, nxtColWidth - 20);
340
341 curCol.style.width = ((curColWidth + diffX) * 100 / rowWidth) + '%';
342 nxtCol.style.width = ((nxtColWidth - diffX) * 100 / rowWidth) + '%';
343 console.log(`${curColWidth + nxtColWidth} ${(curColWidth + diffX) * 100 / rowWidth + (nxtColWidth - diffX) * 100 / rowWidth}`);
344 }
345 });
346
347 document.addEventListener('mouseup', function(e) {
348 curCol = undefined;
349 nxtCol = undefined;
350 startX = undefined;
351 nxtColWidth = undefined;
352 curColWidth = undefined
353 });
354 }
355
356 function paddingDiff(col) {
357

Callers 1

populateBomTableFunction · 0.85

Calls 2

paddingDiffFunction · 0.85
setListenersFunction · 0.85

Tested by

no test coverage detected