changeset 894:1dc4007d7c20

Shrink columns
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 26 Dec 2020 16:57:20 +0900
parents c1a5d137740d
children c01b13db3bd3
files s4-main.js
diffstat 1 files changed, 35 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/s4-main.js	Sat Dec 26 15:17:56 2020 +0900
+++ b/s4-main.js	Sat Dec 26 16:57:20 2020 +0900
@@ -322,8 +322,7 @@
     }
     function initGrphome() {
 	console.log("initGrphome");
-	let btn = document.querySelectorAll("button.toggle-frozen");
-	if (!btn) return;
+	// (1)Setup Frozen State Changing Button
 	let url = document.URL,
 	    mypath = url.substring(url.lastIndexOf("/"));
 	if (mypath.match(/(.*)\/(.*)/)) {
@@ -363,6 +362,7 @@
 		dispInfoMomentary(info, td);
 	    });
 	}
+	let btn = document.querySelectorAll("button.toggle-frozen");
 	for (let b of btn) {
 	    let rowid = null;
 	    let td=b.parentNode, tr = td.parentNode, fr, ru;
@@ -385,6 +385,39 @@
 Toggle Running/Frozen ("+rowid+")");
 	    }
 	}
+	// (2)Setup Column Collapse Button
+	// INCOMPLETE: Cannot restore original state, but it's enough...
+	function toggleColmnWidth(th) {
+	    let tbl = document.querySelector("table.dumpblogs");
+	    let colname = th.textContent, newwidth;
+	    if (th.style.width) {
+		newwidth = null
+		// https://developer.mozilla.org/ja/docs/Web/CSS/table-layout
+		tbl.style.tableLayout = 'auto';
+		tbl.style.width = null;
+	    } else {
+		newwidth = "2em";
+		tbl.style.tableLayout = 'fixed';
+		tbl.style.width = '100%';
+	    }
+	    th.style.width = newwidth;
+	    th.style.overflow = "hidden";
+	    for (let td of document.querySelectorAll("td."+colname)) {
+		console.log(td.tagName);
+		td.style.width = newwidth;
+		console.log(td.style.width);
+	    }
+	}
+	let row1 = document.querySelector("table.dumpblogs tr:first-child");
+	if (row1) {
+	    let heads = row1.querySelectorAll("th");
+	    for (let h of heads) {
+		h.addEventListener("click", function(e) {
+		    toggleColmnWidth(h);
+		}, false);
+		h.setAttribute("title", "Click to shrink these columns");
+	    }
+	}
     }
     function init() {
 	initGrpAction();

yatex.org