s4

diff s4-main.js @ 893:c1a5d137740d

Display momentary information of frozen state change
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 26 Dec 2020 15:17:56 +0900
parents 5843755e3b30
children 1dc4007d7c20
line diff
     1.1 --- a/s4-main.js	Thu Dec 24 19:42:58 2020 +0900
     1.2 +++ b/s4-main.js	Sat Dec 26 15:17:56 2020 +0900
     1.3 @@ -307,6 +307,19 @@
     1.4  	    }, null);
     1.5  	}
     1.6      }
     1.7 +    function dispInfoMomentary(msg, elem) {
     1.8 +	// Momentarily display MSG in tooltip-baloon relative to ELEM element.
     1.9 +	let help = document.createElement("p");
    1.10 +	elem.style.position = 'relative';
    1.11 +	elem.style.overflow = 'visible';
    1.12 +	help.setAttribute("class", "info-tooltip");
    1.13 +	help.innerHTML = msg;
    1.14 +	elem.appendChild(help);
    1.15 +	setTimeout(() => {
    1.16 +	    help.classList.add("dissolving");
    1.17 +	    setTimeout(() => help.remove(), 3000);
    1.18 +	}, 1000);
    1.19 +    }
    1.20      function initGrphome() {
    1.21  	console.log("initGrphome");
    1.22  	let btn = document.querySelectorAll("button.toggle-frozen");
    1.23 @@ -318,10 +331,12 @@
    1.24  	    mypath = mypath.substring(0, mypath.lastIndexOf("?"));
    1.25  	    //alert("mypath="+mypath);
    1.26  	} else return;
    1.27 +	var ja = navigator.language.match(/ja/i);
    1.28  
    1.29  	function toggleFrozen(e, rowid) {
    1.30  	    let tgt = mypath+"?blog_setfrozen+"+rowid;
    1.31 -	    let tr = e.target.parentNode.parentNode;
    1.32 +	    let td = e.target.parentNode;
    1.33 +	    let tr = td.parentNode;
    1.34  	    fetch(tgt, {
    1.35  		method: "POST",
    1.36  		headers: {'Content-Type': 'text/html; charset=utf-8'},
    1.37 @@ -333,21 +348,28 @@
    1.38  		} catch (e) {
    1.39  		    return;
    1.40  		}
    1.41 -		let state = json.state, newstate;
    1.42 +		let state = json.state, newstate, info;
    1.43  		if (json.alert) {
    1.44  		    alert(json.alert)
    1.45  		}
    1.46  		if (state.match(/frozen/i)) {
    1.47  		    newstate = "凍結";
    1.48 +		    info = ja ? newstate+"に設定しました" : 'Set Frozen';
    1.49  		} else {
    1.50  		    newstate = null;
    1.51 +		    info = ja ? '稼動に設定しました' : 'Set Running';
    1.52  		}
    1.53  		tr.setAttribute("class", newstate);
    1.54 +		dispInfoMomentary(info, td);
    1.55  	    });
    1.56  	}
    1.57  	for (let b of btn) {
    1.58  	    let rowid = null;
    1.59 -	    let td=b.parentNode, tr = td.parentNode;
    1.60 +	    let td=b.parentNode, tr = td.parentNode, fr, ru;
    1.61 +	    ru = ja ? "動" : "Running";
    1.62 +	    fr = ja ? "凍" : "Frozen";
    1.63 +	    b.setAttribute('frozen-marker', fr);
    1.64 +	    b.setAttribute('running-marker', ru);
    1.65  	    for (let a of tr.querySelectorAll("a[href]")) {
    1.66  		if (a.getAttribute("href").match(/\?replyblog\+([0-9]+)/)) {
    1.67  		    rowid = parseInt(RegExp.$1);