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 source
1 (function (){
2 function collectElementsByAttr(elm, attr, val) {
3 var e = document.getElementsByTagName(elm);
4 if (!e) return null;
5 var list = [];
6 for (var i of e) {
7 if (i.getAttribute(attr) == val)
8 list.push(i)
9 }
10 return list;
11 }
12 function insertRedirect(e) {
13 var articleId, textarea = document.getElementById("text");
14 var p = e.target, checked = p.checked;
15 while (p = p.parentNode)
16 if (p.nodeName.match(/^td$/i)) break;
17 if (!p) return;
18 while (p = p.nextSibling)
19 if (p.nodeName.match(/^td$/i)) break;
20 if (!p) return;
21 articleId = p.getAttribute("id");
22 if (textarea && articleId) {
23 var tv = textarea.value, lines;
24 if (tv)
25 lines = tv.split("\n");
26 else
27 lines = [""];
28 var re = new RegExp("[, ]*#"+articleId+"(?![0-9])");
29 checked = (p.nodeName.match(/^input$/)
30 ? p.checked // checkbox obeys its status
31 : !lines[0].match(re)) // a-elment toggles redirection
32 if (checked) {
33 if (!lines[0].match(re)) {
34 var re2 = new RegExp(/>#[#0-9, ]+[0-9]/);
35 if (lines[0].match(re2))
36 lines[0] = lines[0].replace(
37 re2, '$&, '+'#'+articleId);
38 else {
39 if (lines[0] > "") lines[0] = " "+lines[0];
40 lines[0] = ">#"+articleId+lines[0];
41 }
42 }
43 } else { // Remove #xxxxx
44 if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's
45 lines[0] = lines[0].replace(
46 new RegExp("^>#"+articleId+"[ ,]*"), ">").replace(
47 new RegExp("[ ,]*#"+articleId), "");
48 else {
49 lines[0] = lines[0].replace(
50 new RegExp(">#"+articleId+"[ ,]*"), "");
51 }
52 }
53 lines[0] = lines[0].replace(/^> *$/, '');
54 textarea.value = lines.join("\n");
55 }
56 }
57 function reverseChecks() {
58 var names = collectElementsByAttr("input", "name", "usel");
59 for (let u of names) {
60 u.checked = !u.checked;
61 }
62 }
63 function initBlogs() {
64 var el, check = collectElementsByAttr("input", "name", "notifyto");
65 if (check)
66 for (let i of check) {
67 i.addEventListener("click", insertRedirect, null);
68 }
69 for (let i of document.getElementsByTagName("a"))
70 if (i.getAttribute("href").match(/^#[0-9]+$/))
71 if (RegExp.lastMatch == i.innerHTML)
72 i.addEventListener("click", insertRedirect, null)
73 }
74 function initGrpAction() {
75 var rev = document.getElementById("reverse");
76 if (!rev) return; // Is not grpAction page
77 if (rev.tagName.match(/span/i)) {
78 rev.textContent = " 反転 ";
79 rev.addEventListener("click", reverseChecks, null);
80 }
81 var emailbtn = document.getElementById("email");
82 emailbtn.addEventListener("click", function(ev){
83 if (!ev.target.checked) return;
84 var x = collectElementsByAttr("div", "class", "foldtabs");
85 if (x && x[0] && x[0].style) {
86 x[0].style.height = "10em";
87 }
88 let myuid = document.getElementById("myuid");
89 if (myuid) {
90 let usel = collectElementsByAttr("input", "name", "usel");
91 if (usel) {
92 for (u of usel) {
93 if (u.value == myuid.value)
94 u.checked = true;
95 }
96 }
97 }
98 }, null);
99 }
100 function init() {
101 initGrpAction();
102 initBlogs();
103 }
104 document.addEventListener('DOMContentLoaded', init, null);
105 })();