annotate s4-main.js @ 889:5843755e3b30

The beginning of AJAX operations Frozen/Running can be toggled by ajax button
author HIROSE Yuuji <yuuji@gentei.org>
date Thu, 24 Dec 2020 19:42:58 +0900
parents 3e09ac711f69
children c1a5d137740d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
889
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
1 // 愛
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
2 (function (){
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
3 function collectElementsByAttr(elm, attr, val) {
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
4 var e = document.getElementsByTagName(elm);
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
5 if (!e) return null;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
6 var list = [];
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
7 for (var i of e) {
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
8 if (i.getAttribute(attr) == val)
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
9 list.push(i)
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
10 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
11 return list;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
12 }
675
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
13 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
14 // N begins with 1
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
15 var i=0;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
16 var le = elem.toLowerCase();
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
17 for (var c of parent.childNodes) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
18 if (!c.tagName) continue;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
19 if (c.tagName.toLowerCase() == le) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
20 if (++i >= n) return c;
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 }
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
23 return null;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
24 }
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
25 function insertRedirect(e) {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
26 var articleId, textarea = document.getElementById("text");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
27 var p = e.target, checked = p.checked;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
28 while (p = p.parentNode)
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
29 if (p.nodeName.match(/^td$/i)) break;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
30 if (!p) return;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
31 while (p = p.nextSibling)
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
32 if (p.nodeName.match(/^td$/i)) break;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
33 if (!p) return;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
34 articleId = p.getAttribute("id");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
35 if (textarea && articleId) {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
36 var tv = textarea.value, lines;
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
37 if (tv)
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
38 lines = tv.split("\n");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
39 else
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
40 lines = [""];
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
41 var re = new RegExp("[, ]*#"+articleId+"(?![0-9])");
590
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
42 checked = (p.nodeName.match(/^input$/)
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
43 ? p.checked // checkbox obeys its status
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
44 : !lines[0].match(re)) // a-elment toggles redirection
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
45 if (checked) {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
46 if (!lines[0].match(re)) {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
47 var re2 = new RegExp(/>#[#0-9, ]+[0-9]/);
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
48 if (lines[0].match(re2))
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
49 lines[0] = lines[0].replace(
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
50 re2, '$&, '+'#'+articleId);
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
51 else {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
52 if (lines[0] > "") lines[0] = " "+lines[0];
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
53 lines[0] = ">#"+articleId+lines[0];
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
54 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
55 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
56 } else { // Remove #xxxxx
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
57 if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
58 lines[0] = lines[0].replace(
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
59 new RegExp("^>#"+articleId+"[ ,]*"), ">").replace(
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
60 new RegExp("[ ,]*#"+articleId), "");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
61 else {
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
62 lines[0] = lines[0].replace(
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
63 new RegExp(">#"+articleId+"[ ,]*"), "");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
64 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
65 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
66 lines[0] = lines[0].replace(/^> *$/, '');
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
67 textarea.value = lines.join("\n");
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
68 }
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
69 }
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
70 function reverseChecks() {
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
71 var names = collectElementsByAttr("input", "name", "usel");
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
72 for (let u of names) {
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
73 u.checked = !u.checked;
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 }
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
76 function renumberOL(str, start) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
77 var stra = str.split("\n");
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
78
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
79 for (var i=1; i<stra.length; i++) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
80 if (stra[i].match(/^[1-9][0-9]*\. /)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
81 let orig=stra[i];
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
82 stra[i] = (++start)+". "+RegExp.rightContext;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
83 } else if (stra[i].match(/^ /)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
84 continue;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
85 } else
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
86 break;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
87 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
88 return stra.join("\n");
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
89 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
90 function submitThisForm(input) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
91 for (var elm=input.parentNode; elm; elm = elm.parentNode) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
92 if (elm.nodeName.match(/form/i)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
93 elm.submit();
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
94 return true;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
95 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
96 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
97 return false;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
98 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
99 function helpMarkdownBS(e) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
100 var area = e.target, pos = area.selectionStart, text = area.value;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
101 if (area.selectionStart != area.selectionEnd) return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
102 if (pos<2) return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
103 if (text.substr(pos-1, 2)=="\n\n") return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
104 var bol = text.lastIndexOf("\n", pos-1),
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
105 eol = text.indexOf("\n", pos);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
106 if (bol<=0 || bol==eol) return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
107 var thisline = text.substring(bol+1, eol==-1 ? text.length : eol);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
108 thisline = text.substring(bol+1, pos);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
109 if (thisline == "* ") {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
110 area.setSelectionRange(pos-2, pos);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
111 } else if (thisline.match(/^[1-9][0-9]*\. $/)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
112 area.setSelectionRange(pos-RegExp.lastMatch.length, pos);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
113 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
114 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
115 function helpMarkdownEnter(e) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
116 if (e.keyCode == 13 && !e.shiftKey) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
117 if (e.metaKey && submitThisForm(e.target)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
118 e.preventDefault();
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
119 return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
120 }
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
121 var area = e.target;
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
122 var pos = area.selectionStart, text = area.value;
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
123 if (pos==0) return;
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
124 var last = text.lastIndexOf("\n", pos-1);
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
125 var rest = text.substring(pos), rest0=rest;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
126 var line = last ? text.substring(last+1, pos) : text;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
127 var next = rest.substring(rest.indexOf("\n"))||rest;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
128 next=next.substring(1);
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
129 var tail = text.substring(pos-2, pos), br = (tail==" ");
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
130 var add = "", offset = 1;
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
131 if (line.startsWith("* ")) {
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
132 add = "* ";
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
133 offset += add.length;
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
134 if (br) {
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
135 add = " " + "\n" + add;
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
136 }
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
137 } else if (line.match(/^([1-9][0-9]*)\. /)) {
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
138 var ln = parseInt(RegExp.$1), nn=ln+1,
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
139 len = RegExp.lastMatch.length;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
140 add = nn+". ";
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
141 let toeol = text.substr(pos, text.indexOf("\n"));
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
142 if (br) {
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
143 if (next.startsWith(add)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
144 add=" ".repeat(len);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
145 nn = ln;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
146 } else {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
147 add = " ".repeat(len)+ "\n" + add;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
148 offset -= len+1;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
149 }
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
150 }
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
151 if (next.match(/^[1-9][0-9]*\. /))
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
152 rest = renumberOL(rest, nn);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
153 offset += add.length;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
154 } else if (line.match(/^\|( *).+\|/)) {
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
155 add = "|" + RegExp.$1 + " |";
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
156 offset += add.length-2;
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
157 } else {
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
158 return;
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
159 }
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
160 e.preventDefault();
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
161 if (!document.execCommand("insertText", false, "\n"+add)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
162 //Firefox
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
163 area.selectionEnd = area.value.length;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
164 area.setRangeText("\n"+add+rest);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
165 area.selectionEnd = null;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
166 } else {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
167 area.selectionEnd = area.value.length;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
168 area.setSelectionRange(area.selectionStart, area.value.length);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
169 document.execCommand("insertText", false, rest);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
170 area.selectionEnd = null;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
171 area.focus();
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
172 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
173 area.selectionStart = pos+offset;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
174 return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
175 if (document.execCommand("insertText", false, "\n"+add)) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
176 //area.setSelectionRange(area.selectionStart, text.length);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
177 // alert("rest=["+rest+"], add=["+add+"]");
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
178 alert(text.substring(pos, area.value.length));
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
179 if (rest != rest0) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
180 area.setSelectionRange(pos, area.value.length);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
181 return;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
182 document.execCommand("delete");
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
183 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
184 document.execCommand("insertText", false, rest);
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
185 } else {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
186 // Firefox cannot use insertText in textarea...
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
187 area.value = text.substring(0, pos) + "\n" + add + rest;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
188 }
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
189 //area.setSelectionRange(pos+length(add));
847
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
190 area.selectionStart=area.selectionEnd = (pos + offset);
a9e147e355fd Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents: 846
diff changeset
191
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
192 }
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
193 }
852
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
194 function helpMarkdown(e) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
195 switch (e.keyCode) {
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
196 case 8: helpMarkdownBS(e); break;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
197 case 13: helpMarkdownEnter(e); break;
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
198 }
3e09ac711f69 Renumbering text modified
HIROSE Yuuji <yuuji@gentei.org>
parents: 847
diff changeset
199 }
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
200 /* Init event listeners */
837
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
201 function addFileInput() {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
202 var inpfile = collectElementsByAttr("input", "name", "image");
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
203 if (!inpfile) return;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
204 var filled = true;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
205 var i, ih;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
206 for (i of inpfile) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
207 if (! i.value) filled=false;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
208 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
209 if (filled) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
210 ih = i.parentNode.innerHTML;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
211 if (ih) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
212 var inpf = ih.substring(ih.indexOf("<input")),
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
213 newi = "<br>"+inpf.substring(0, inpf.indexOf(">")+1);
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
214 i.insertAdjacentHTML("afterend", newi)
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
215 // alert(newi);
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
216 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
217 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
218 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
219 function initFileInput() { // Multiplies "input type=file"
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
220 var el, morefile = document.getElementById("morefile");
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
221 if (morefile) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
222 for (el of collectElementsByAttr("input", "name", "image")) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
223 el.addEventListener("change", function(ev) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
224 if (ev.target.value > "" && ev.target.files.length == 1)
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
225 morefile.style.visibility = "visible";
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
226 // No need to hide again, sure?
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
227 });
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
228 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
229 morefile.addEventListener("click", addFileInput, null);
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
230 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
231 // When renaming, select basename part
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
232 for (el of collectElementsByAttr("input", "class", "mv")) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
233 el.addEventListener("focus", function(ev) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
234 var i = ev.target;
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
235 if (i) {
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
236 i.setSelectionRange(0, i.value.lastIndexOf("."));
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
237 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
238 });
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
239 }
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
240 }
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
241 function initTextarea() {
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
242 var te = collectElementsByAttr("textarea", "name", "text");
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
243 if (!te || !te[0]) return;
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
244 te[0].addEventListener("keydown", helpMarkdown, false);
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
245 }
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
246 function initBlogs() {
837
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
247 // Auto-complete #xxxx
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
248 var check = collectElementsByAttr("input", "name", "notifyto");
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
249 if (check)
590
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
250 for (let i of check) {
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
251 i.addEventListener("click", insertRedirect, null);
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
252 }
590
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
253 for (let i of document.getElementsByTagName("a"))
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
254 if (i.getAttribute("href").match(/^#[0-9]+$/))
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
255 if (RegExp.lastMatch == i.innerHTML)
f480fa97fba6 Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents: 586
diff changeset
256 i.addEventListener("click", insertRedirect, null)
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
257 }
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
258 function initGrpAction() {
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
259 var rev = document.getElementById("reverse");
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
260 if (!rev) return; // Is not grpAction page
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
261 if (rev.tagName.match(/span/i)) {
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
262 rev.textContent = " 反転 ";
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
263 rev.addEventListener("click", reverseChecks, null);
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
264 }
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
265 var emailbtn = document.getElementById("email");
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
266 emailbtn.addEventListener("click", function(ev){
675
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
267 // Enlarge box and Select user's checkbox
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
268 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
269 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
270 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
271 x[0].style.height = "10em";
42bf03cb3712 Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents: 667
diff changeset
272 }
667
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
273 let myuid = document.getElementById("myuid");
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
274 if (myuid) {
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
275 let usel = collectElementsByAttr("input", "name", "usel");
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
276 if (usel) {
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
277 for (u of usel) {
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
278 if (u.value == myuid.value)
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
279 u.checked = true;
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
280 }
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
281 }
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
282 }
9ee0e242c25a Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents: 659
diff changeset
283 }, null);
675
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
284 var teamsel = document.getElementById("selteam");
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
285 if (teamsel) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
286 var usel, p, team;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
287 // Select all members of the team
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
288 teamsel.addEventListener("change", function(ev) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
289 var teamname = teamsel.value,
676
cd6f0badcff4 \b cannot be used for Japanese boundary...
HIROSE Yuuji <yuuji@gentei.org>
parents: 675
diff changeset
290 selected = new RegExp('(^| )'+teamname+"($|,)");
675
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
291 usel = collectElementsByAttr("input", "name", "usel");
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
292 if (!usel) return;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
293 for (u of usel) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
294 p = u.parentNode; // should be label
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
295 if (!p) continue;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
296 if (teamname == "TEAM") { // Reset all checks
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
297 u.checked = false; // when "TEAM" is selected
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
298 } else {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
299 p = p.parentNode.parentNode;// should be tr
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
300 team = nthChildOf(p, 3, "td")
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
301 if (team && team.textContent
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
302 && team.textContent.match(selected)) {
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
303 u.checked = true;
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
304 }
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
305 }
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
306 }
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
307 }, null);
9c54908814be Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents: 673
diff changeset
308 }
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
309 }
889
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
310 function initGrphome() {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
311 console.log("initGrphome");
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
312 let btn = document.querySelectorAll("button.toggle-frozen");
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
313 if (!btn) return;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
314 let url = document.URL,
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
315 mypath = url.substring(url.lastIndexOf("/"));
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
316 if (mypath.match(/(.*)\/(.*)/)) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
317 mypath = RegExp.$2;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
318 mypath = mypath.substring(0, mypath.lastIndexOf("?"));
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
319 //alert("mypath="+mypath);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
320 } else return;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
321
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
322 function toggleFrozen(e, rowid) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
323 let tgt = mypath+"?blog_setfrozen+"+rowid;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
324 let tr = e.target.parentNode.parentNode;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
325 fetch(tgt, {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
326 method: "POST",
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
327 headers: {'Content-Type': 'text/html; charset=utf-8'},
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
328 }).then(function(resp) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
329 return resp.text();
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
330 }).then(function(tbody) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
331 try {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
332 var json = JSON.parse(tbody);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
333 } catch (e) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
334 return;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
335 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
336 let state = json.state, newstate;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
337 if (json.alert) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
338 alert(json.alert)
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
339 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
340 if (state.match(/frozen/i)) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
341 newstate = "凍結";
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
342 } else {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
343 newstate = null;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
344 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
345 tr.setAttribute("class", newstate);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
346 });
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
347 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
348 for (let b of btn) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
349 let rowid = null;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
350 let td=b.parentNode, tr = td.parentNode;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
351 for (let a of tr.querySelectorAll("a[href]")) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
352 if (a.getAttribute("href").match(/\?replyblog\+([0-9]+)/)) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
353 rowid = parseInt(RegExp.$1);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
354 break;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
355 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
356 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
357 if (rowid && rowid>0) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
358 b.addEventListener("click", function(e) {
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
359 if (!btn) return;
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
360 toggleFrozen(e, rowid);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
361 }, false);
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
362 b.setAttribute("title", "稼動/凍結をその場で切り替えます\n\
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
363 Toggle Running/Frozen ("+rowid+")");
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
364 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
365 }
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
366 }
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
367 function init() {
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
368 initGrpAction();
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
369 initBlogs();
837
a6462eea48be Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents: 676
diff changeset
370 initFileInput();
846
9c4e16c173db Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents: 837
diff changeset
371 initTextarea();
889
5843755e3b30 The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents: 852
diff changeset
372 initGrphome();
659
a36a2c3b3056 GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents: 590
diff changeset
373 }
586
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
374 document.addEventListener('DOMContentLoaded', init, null);
a03bfd5d242a First trial of js interaction.
HIROSE Yuuji <yuuji@gentei.org>
parents:
diff changeset
375 })();

yatex.org