Mercurial > hgrepos > hgweb.cgi > s4
annotate s4-main.js @ 677:bdf33fbd977b
Sort team names
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Wed, 13 May 2020 10:48:59 +0900 |
parents | cd6f0badcff4 |
children | a6462eea48be |
rev | line source |
---|---|
586 | 1 (function (){ |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
2 function collectElementsByAttr(elm, attr, val) { |
586 | 3 var e = document.getElementsByTagName(elm); |
4 if (!e) return null; | |
5 var list = []; | |
6 for (var i of e) { | |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
7 if (i.getAttribute(attr) == val) |
586 | 8 list.push(i) |
9 } | |
10 return list; | |
11 } | |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
12 function nthChildOf(parent, n, elem) { // Return Nth child of type ELEM |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
13 // N begins with 1 |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
14 var i=0; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
15 var le = elem.toLowerCase(); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
16 for (var c of parent.childNodes) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
17 if (!c.tagName) continue; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
18 if (c.tagName.toLowerCase() == le) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
19 if (++i >= n) return c; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
20 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
21 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
22 return null; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
23 } |
586 | 24 function insertRedirect(e) { |
25 var articleId, textarea = document.getElementById("text"); | |
26 var p = e.target, checked = p.checked; | |
27 while (p = p.parentNode) | |
28 if (p.nodeName.match(/^td$/i)) break; | |
29 if (!p) return; | |
30 while (p = p.nextSibling) | |
31 if (p.nodeName.match(/^td$/i)) break; | |
32 if (!p) return; | |
33 articleId = p.getAttribute("id"); | |
34 if (textarea && articleId) { | |
35 var tv = textarea.value, lines; | |
36 if (tv) | |
37 lines = tv.split("\n"); | |
38 else | |
39 lines = [""]; | |
40 var re = new RegExp("[, ]*#"+articleId+"(?![0-9])"); | |
590
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
41 checked = (p.nodeName.match(/^input$/) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
42 ? p.checked // checkbox obeys its status |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
43 : !lines[0].match(re)) // a-elment toggles redirection |
586 | 44 if (checked) { |
45 if (!lines[0].match(re)) { | |
46 var re2 = new RegExp(/>#[#0-9, ]+[0-9]/); | |
47 if (lines[0].match(re2)) | |
48 lines[0] = lines[0].replace( | |
49 re2, '$&, '+'#'+articleId); | |
50 else { | |
51 if (lines[0] > "") lines[0] = " "+lines[0]; | |
52 lines[0] = ">#"+articleId+lines[0]; | |
53 } | |
54 } | |
55 } else { // Remove #xxxxx | |
56 if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's | |
57 lines[0] = lines[0].replace( | |
58 new RegExp("^>#"+articleId+"[ ,]*"), ">").replace( | |
59 new RegExp("[ ,]*#"+articleId), ""); | |
60 else { | |
61 lines[0] = lines[0].replace( | |
62 new RegExp(">#"+articleId+"[ ,]*"), ""); | |
63 } | |
64 } | |
65 lines[0] = lines[0].replace(/^> *$/, ''); | |
66 textarea.value = lines.join("\n"); | |
67 } | |
68 } | |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
69 function reverseChecks() { |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
70 var names = collectElementsByAttr("input", "name", "usel"); |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
71 for (let u of names) { |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
72 u.checked = !u.checked; |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
73 } |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
74 } |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
75 function initBlogs() { |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
76 var el, check = collectElementsByAttr("input", "name", "notifyto"); |
586 | 77 if (check) |
590
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
78 for (let i of check) { |
586 | 79 i.addEventListener("click", insertRedirect, null); |
80 } | |
590
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
81 for (let i of document.getElementsByTagName("a")) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
82 if (i.getAttribute("href").match(/^#[0-9]+$/)) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
83 if (RegExp.lastMatch == i.innerHTML) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
84 i.addEventListener("click", insertRedirect, null) |
586 | 85 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
86 function initGrpAction() { |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
87 var rev = document.getElementById("reverse"); |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
88 if (!rev) return; // Is not grpAction page |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
89 if (rev.tagName.match(/span/i)) { |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
90 rev.textContent = " 反転 "; |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
91 rev.addEventListener("click", reverseChecks, null); |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
92 } |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
93 var emailbtn = document.getElementById("email"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
94 emailbtn.addEventListener("click", function(ev){ |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
95 // Enlarge box and Select user's checkbox |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
96 if (!ev.target.checked) return; |
673
42bf03cb3712
Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents:
667
diff
changeset
|
97 var x = collectElementsByAttr("div", "class", "foldtabs"); |
42bf03cb3712
Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents:
667
diff
changeset
|
98 if (x && x[0] && x[0].style) { |
42bf03cb3712
Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents:
667
diff
changeset
|
99 x[0].style.height = "10em"; |
42bf03cb3712
Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents:
667
diff
changeset
|
100 } |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
101 let myuid = document.getElementById("myuid"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
102 if (myuid) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
103 let usel = collectElementsByAttr("input", "name", "usel"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
104 if (usel) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
105 for (u of usel) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
106 if (u.value == myuid.value) |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
107 u.checked = true; |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
108 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
109 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
110 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
111 }, null); |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
112 var teamsel = document.getElementById("selteam"); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
113 if (teamsel) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
114 var usel, p, team; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
115 // Select all members of the team |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
116 teamsel.addEventListener("change", function(ev) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
117 var teamname = teamsel.value, |
676
cd6f0badcff4
\b cannot be used for Japanese boundary...
HIROSE Yuuji <yuuji@gentei.org>
parents:
675
diff
changeset
|
118 selected = new RegExp('(^| )'+teamname+"($|,)"); |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
119 usel = collectElementsByAttr("input", "name", "usel"); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
120 if (!usel) return; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
121 for (u of usel) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
122 p = u.parentNode; // should be label |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
123 if (!p) continue; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
124 if (teamname == "TEAM") { // Reset all checks |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
125 u.checked = false; // when "TEAM" is selected |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
126 } else { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
127 p = p.parentNode.parentNode;// should be tr |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
128 team = nthChildOf(p, 3, "td") |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
129 if (team && team.textContent |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
130 && team.textContent.match(selected)) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
131 u.checked = true; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
132 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
133 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
134 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
135 }, null); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
136 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
137 } |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
138 function init() { |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
139 initGrpAction(); |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
140 initBlogs(); |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
141 } |
586 | 142 document.addEventListener('DOMContentLoaded', init, null); |
143 })(); |