Mercurial > hgrepos > hgweb.cgi > s4
view s4-main.js @ 673:42bf03cb3712
Enlarge div of form field when bring them visible
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 13 May 2020 07:30:55 +0900 |
parents | 9ee0e242c25a |
children | 9c54908814be |
line wrap: on
line source
(function (){ function collectElementsByAttr(elm, attr, val) { var e = document.getElementsByTagName(elm); if (!e) return null; var list = []; for (var i of e) { if (i.getAttribute(attr) == val) list.push(i) } return list; } function insertRedirect(e) { var articleId, textarea = document.getElementById("text"); var p = e.target, checked = p.checked; while (p = p.parentNode) if (p.nodeName.match(/^td$/i)) break; if (!p) return; while (p = p.nextSibling) if (p.nodeName.match(/^td$/i)) break; if (!p) return; articleId = p.getAttribute("id"); if (textarea && articleId) { var tv = textarea.value, lines; if (tv) lines = tv.split("\n"); else lines = [""]; var re = new RegExp("[, ]*#"+articleId+"(?![0-9])"); checked = (p.nodeName.match(/^input$/) ? p.checked // checkbox obeys its status : !lines[0].match(re)) // a-elment toggles redirection if (checked) { if (!lines[0].match(re)) { var re2 = new RegExp(/>#[#0-9, ]+[0-9]/); if (lines[0].match(re2)) lines[0] = lines[0].replace( re2, '$&, '+'#'+articleId); else { if (lines[0] > "") lines[0] = " "+lines[0]; lines[0] = ">#"+articleId+lines[0]; } } } else { // Remove #xxxxx if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's lines[0] = lines[0].replace( new RegExp("^>#"+articleId+"[ ,]*"), ">").replace( new RegExp("[ ,]*#"+articleId), ""); else { lines[0] = lines[0].replace( new RegExp(">#"+articleId+"[ ,]*"), ""); } } lines[0] = lines[0].replace(/^> *$/, ''); textarea.value = lines.join("\n"); } } function reverseChecks() { var names = collectElementsByAttr("input", "name", "usel"); for (let u of names) { u.checked = !u.checked; } } function initBlogs() { var el, check = collectElementsByAttr("input", "name", "notifyto"); if (check) for (let i of check) { i.addEventListener("click", insertRedirect, null); } for (let i of document.getElementsByTagName("a")) if (i.getAttribute("href").match(/^#[0-9]+$/)) if (RegExp.lastMatch == i.innerHTML) i.addEventListener("click", insertRedirect, null) } function initGrpAction() { var rev = document.getElementById("reverse"); if (!rev) return; // Is not grpAction page if (rev.tagName.match(/span/i)) { rev.textContent = " 反転 "; rev.addEventListener("click", reverseChecks, null); } var emailbtn = document.getElementById("email"); emailbtn.addEventListener("click", function(ev){ if (!ev.target.checked) return; var x = collectElementsByAttr("div", "class", "foldtabs"); if (x && x[0] && x[0].style) { x[0].style.height = "10em"; } let myuid = document.getElementById("myuid"); if (myuid) { let usel = collectElementsByAttr("input", "name", "usel"); if (usel) { for (u of usel) { if (u.value == myuid.value) u.checked = true; } } } }, null); } function init() { initGrpAction(); initBlogs(); } document.addEventListener('DOMContentLoaded', init, null); })();