Mercurial > hgrepos > hgweb.cgi > s4
annotate s4-main.js @ 900:1fa8b4440f8f
Update button changed to ajax
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Sat, 02 Jan 2021 19:13:27 +0900 |
parents | a4ad4101064d |
children | 1cff36303150 |
rev | line source |
---|---|
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
1 // 愛 |
586 | 2 (function (){ |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
3 var isOlderJS; // Set in init(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
4 var hasTouchPad = |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
5 (navigator.maxTouchPoints && navigator.maxTouchPoints >0); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
6 var myurl = document.URL, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
7 mypath = myurl.substring(myurl.lastIndexOf("/")); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
8 var art_m_list = []; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
9 if (mypath.match(/(.*)\/(.*)/)) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
10 mypath = RegExp.$2; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
11 mypath = mypath.substring(0, mypath.lastIndexOf("?")); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
12 //alert("mypath="+mypath); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
13 } |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
14 function collectElementsByAttr(elm, attr, val) { |
586 | 15 var e = document.getElementsByTagName(elm); |
16 if (!e) return null; | |
17 var list = []; | |
18 for (var i of e) { | |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
19 if (i.getAttribute(attr) == val) |
586 | 20 list.push(i) |
21 } | |
22 return list; | |
23 } | |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
24 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
|
25 // N begins with 1 |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
26 var i=0; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
27 var le = elem.toLowerCase(); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
28 for (var c of parent.childNodes) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
29 if (!c.tagName) continue; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
30 if (c.tagName.toLowerCase() == le) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
31 if (++i >= n) return c; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
32 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
33 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
34 return null; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
35 } |
586 | 36 function insertRedirect(e) { |
37 var articleId, textarea = document.getElementById("text"); | |
38 var p = e.target, checked = p.checked; | |
39 while (p = p.parentNode) | |
40 if (p.nodeName.match(/^td$/i)) break; | |
41 if (!p) return; | |
42 while (p = p.nextSibling) | |
43 if (p.nodeName.match(/^td$/i)) break; | |
44 if (!p) return; | |
45 articleId = p.getAttribute("id"); | |
46 if (textarea && articleId) { | |
47 var tv = textarea.value, lines; | |
48 if (tv) | |
49 lines = tv.split("\n"); | |
50 else | |
51 lines = [""]; | |
52 var re = new RegExp("[, ]*#"+articleId+"(?![0-9])"); | |
590
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
53 checked = (p.nodeName.match(/^input$/) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
54 ? p.checked // checkbox obeys its status |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
55 : !lines[0].match(re)) // a-elment toggles redirection |
586 | 56 if (checked) { |
57 if (!lines[0].match(re)) { | |
58 var re2 = new RegExp(/>#[#0-9, ]+[0-9]/); | |
59 if (lines[0].match(re2)) | |
60 lines[0] = lines[0].replace( | |
61 re2, '$&, '+'#'+articleId); | |
62 else { | |
63 if (lines[0] > "") lines[0] = " "+lines[0]; | |
64 lines[0] = ">#"+articleId+lines[0]; | |
65 } | |
66 } | |
67 } else { // Remove #xxxxx | |
68 if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's | |
69 lines[0] = lines[0].replace( | |
70 new RegExp("^>#"+articleId+"[ ,]*"), ">").replace( | |
71 new RegExp("[ ,]*#"+articleId), ""); | |
72 else { | |
73 lines[0] = lines[0].replace( | |
74 new RegExp(">#"+articleId+"[ ,]*"), ""); | |
75 } | |
76 } | |
77 lines[0] = lines[0].replace(/^> *$/, ''); | |
78 textarea.value = lines.join("\n"); | |
79 } | |
80 } | |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
81 function registPjaxViewers(aHrefList) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
82 // if (isOlderJS) return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
83 let apos=art_m_list.length; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
84 for (let a of aHrefList) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
85 let href = a.getAttribute("href"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
86 let localvar = apos; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
87 let td = a.parentNode, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
88 tr = td.parentNode, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
89 id = td.id, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
90 text = td.textContent, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
91 author = tr.getElementsByTagName("a"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
92 if (author) author = author[0].getAttribute("title"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
93 if (href.match(/\?showattc\+article_m\+([0-9+])/)) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
94 if (td.innerHTML.match(/x読み取り不可/)) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
95 a.removeAttribute("href"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
96 continue; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
97 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
98 let url = RegExp.lastMatch; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
99 // console.log("pjaxView(e, "+href+", "+apos+")"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
100 a.addEventListener("click", function(e) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
101 // Shoud use closure local variable: localvar |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
102 pjaxView(e, href, localvar); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
103 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
104 apos++; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
105 art_m_list.push({ |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
106 url: href, id: id, author: author, text: text |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
107 }); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
108 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
109 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
110 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
111 var ajaxSubmit; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
112 function replAddNews(newtable) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
113 let newids = [], idlist=[]; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
114 let getArticleID = function (td) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
115 return parseInt(td.parentNode.getElementsByTagName("td")[1].id); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
116 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
117 for (let i of newtable.querySelectorAll("td.repl")) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
118 newids.push(i); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
119 newids = newids.sort((a,b)=> { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
120 return (getArticleID(a) - getArticleID(b)); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
121 }); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
122 for (i of newids) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
123 idlist.push(getArticleID(i)); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
124 console.log("IDList="+idlist.join()); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
125 let cnt=0, ntr; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
126 let current = collectElementsByAttr("td", "class", "repl"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
127 ncur=0, n, icur=0, o, oid, nid, otr; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
128 current = document.querySelectorAll('td[class="repl"]'); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
129 let last=current[current.length-1], |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
130 tbody = last.parentNode.parentNode; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
131 // Now reconstruct articles with merge-sort like method |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
132 outer: for (; ncur<newids.length; ncur++) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
133 n = newids[ncur]; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
134 if (!n.id) continue; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
135 nid = parseInt(n.id); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
136 if (nid<=0) continue; |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
137 ntr = n.parentNode; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
138 for (; icur<current.length; icur++) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
139 o = current[icur]; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
140 otr = o.parentNode; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
141 oid = getArticleID(o); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
142 if (!oid || oid=="") continue; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
143 if (oid >= nid) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
144 ntr.getElementsByTagName("td")[0].classList.add("new"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
145 tbody.insertBefore(ntr, otr); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
146 if (oid==nid) otr.remove(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
147 cnt++; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
148 continue outer; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
149 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
150 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
151 // Append absolutely new articles. |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
152 ntr = n.parentNode; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
153 ntr.getElementsByTagName("td")[0].classList.add("new"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
154 tbody.appendChild(ntr); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
155 ntr.scrollIntoView({behavior: "smooth"}); |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
156 registPjaxViewers(ntr.querySelectorAll("a[href]")); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
157 ntr.classList.add("dissolving"); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
158 let localntr = ntr; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
159 setTimeout(() => { |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
160 localntr.classList.remove("dissolving"); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
161 localntr.classList.add("emerging"); |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
162 }, 100); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
163 cnt++; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
164 } |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
165 ajaxSubmit.textContent = ajaxSubmit.back; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
166 ajaxSubmit.disabled = false; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
167 console.log("Update "+cnt+"rows"); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
168 if (cnt>0) |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
169 try { // Scroll to last updated row |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
170 ntr.scrollIntoView({behavior: "smooth", block: "center"}); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
171 } catch (e1) { |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
172 try { // block: "center" is not supported by older agents |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
173 ntr.scrollIntoView({behavior: "smooth"}); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
174 } catch (e2) {} |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
175 } |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
176 return cnt; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
177 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
178 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
179 function warnFileSize(form) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
180 let szmax = form.querySelector('input[name="filesize_max"]').value; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
181 if (!szmax || szmax=="") return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
182 szmax = parseInt(szmax); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
183 if (szmax <= 0) return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
184 // szmax = 10000 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
185 let ng = "", rcval=false, fileexists=false; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
186 for (let f of form.querySelectorAll('input[type="file"]')) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
187 let thiserr = false |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
188 for (let i of f.files) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
189 fileexists = true; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
190 let fn = i.name, sz = i.size; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
191 console.log("max="+szmax+", fn="+fn+", sz="+sz); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
192 if (sz > szmax) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
193 thiserr = true; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
194 ng += ((ng>"" ? ", " : "")+fn) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
195 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
196 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
197 thiserr ? f.classList.add("warnbg") : f.classList.remove("warnbg"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
198 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
199 if (ng>"") { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
200 rcval = "File-size Limit Error: "+ng+"\n"+ |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
201 "Should be less than "+szmax+"bytes.\n"+ |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
202 szmax+"バイト未満にしてください" |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
203 alert(rcval); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
204 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
205 if (form.text.value == "") { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
206 let w; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
207 if (fileexists) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
208 w = "Fill the text area\n" + |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
209 "添付したファイルに関する説明を入れてください。"; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
210 else |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
211 w = "Enter your comment!\n何か書き込んでね!"; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
212 alert(w); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
213 rcval = (rcval || w); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
214 form.text.classList.add("warnbg"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
215 setTimeout(() => {form.text.classList.remove("warnbg");}, 2000) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
216 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
217 return rcval; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
218 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
219 function ajaxPost(e) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
220 e.preventDefault(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
221 let rowid; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
222 if (!myurl.match(/replyblog\+([0-9]+)/)) return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
223 rowid = RegExp.$1 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
224 let myform = document.querySelector("form.replyblog"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
225 let data = new FormData(myform), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
226 fetchtime = data.get("fetchtime"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
227 if (!fetchtime || fetchtime=="") return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
228 ///*XX*/fetchtime = "2020-06-14T00:00:00";data.set("fetchtime", fetchtime) |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
229 |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
230 ajaxSubmit = e.target; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
231 ajaxSubmit.back = ajaxSubmit.textContent; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
232 if (ajaxSubmit.id == "reload") { |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
233 ajaxSubmit.textContent = "更新中" |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
234 data.set("text", "") |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
235 } else { |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
236 if (warnFileSize(myform)) return; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
237 ajaxSubmit.textContent = "送信中"; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
238 } |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
239 ajaxSubmit.blur(); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
240 ajaxSubmit.disabled = true; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
241 let act = mypath+"?blog_fetch+"+rowid+"+f:"+fetchtime; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
242 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
243 function respUpdate(tbody) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
244 let div = document.createElement("div"), form, newform; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
245 try { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
246 div.innerHTML = tbody; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
247 form = div.querySelector("form"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
248 } catch (er) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
249 alert("Cannot parse fetch data"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
250 return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
251 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
252 let update = replAddNews(form); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
253 let dispelem = myform.querySelector("textarea").parentNode; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
254 newform = new FormData(form); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
255 if (data.get("text") > "") { // Called by submit button |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
256 myform.reset(); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
257 // myform.text.value = ''; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
258 } |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
259 myform.fetchtime.value = newform.get("fetchtime"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
260 myform.id.value = newform.get("id"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
261 if (update && update > 0) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
262 let s = update + " new article" + |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
263 (update>1 ? "s" : "") + " posted"; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
264 dispInfoMomentary(s, dispelem); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
265 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
266 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
267 fetch(act, { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
268 method: "POST", body: data, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
269 credentials: "include" // For older firefox |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
270 }).then((resp) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
271 return resp.text(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
272 }).then((tbody) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
273 respUpdate(tbody); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
274 }) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
275 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
276 function pjaxView(ev, url, mynum) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
277 ev.preventDefault(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
278 let box = document.createElement("div") |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
279 box.setAttribute("class", "pjaxview"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
280 let p1 = document.createElement("p"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
281 bt = document.createElement("button"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
282 sl = document.createElement("button"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
283 sr = document.createElement("button"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
284 loading = document.createElement("span"), |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
285 info = document.createElement("p"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
286 info1 = document.createElement("span"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
287 info2 = document.createElement("span"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
288 iframe = document.createElement("iframe"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
289 var curpos = mynum; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
290 var historyBase = history.length; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
291 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
292 function _setPjaxCurposInfo() { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
293 let len = art_m_list.length; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
294 let cur = art_m_list[curpos] |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
295 info1.textContent = (1+curpos)+" of "+len+" article #"+cur.id+ |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
296 (cur.author ? " by "+cur.author : "") + ":"; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
297 info2.textContent = cur.text.trim(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
298 info2.setAttribute("class", "border textdigest"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
299 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
300 function _resetPjax() { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
301 // All we can do surely is to back 1 page, |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
302 // because we cannot move to desirable entry of history list. |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
303 history.back(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
304 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
305 function setSwipeAct(iframe) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
306 // We cannot use DOMContentLoaded nor iframe.contentWindow here. |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
307 // PDF.js does not construct contentWindow...? |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
308 iframe.addEventListener("load", () => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
309 loading.classList.remove("loading"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
310 if (!hasTouchPad) return; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
311 let ifm = iframe.contentDocument; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
312 let startX, moveX, thresh = 100; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
313 ifm.addEventListener("touchstart", (e) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
314 e.preventDefault(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
315 startX = e.touches[0].pageX; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
316 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
317 ifm.addEventListener("touchmove", (e) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
318 e.preventDefault(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
319 moveX = e.touches[0].pageX; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
320 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
321 ifm.addEventListener("touchend", (e) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
322 if (startX < moveX && startX + thresh < moveX) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
323 switchTo(e, -1); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
324 } else if (startX > moveX && startX - thresh > moveX) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
325 switchTo(e, +1); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
326 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
327 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
328 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
329 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
330 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
331 function switchTo(e, direction) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
332 e.preventDefault(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
333 let len = art_m_list.length, cur, newpos, url; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
334 newpos = (curpos+len+direction)%len; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
335 if (curpos == newpos) return; // No need to switch to same one |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
336 curpos = newpos; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
337 cur = art_m_list[curpos]; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
338 url = cur.url; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
339 // We should remove iframe once to preserve history Object |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
340 // https://inthetechpit.com/2019/04/20/update-iframe-without-affecting-browser-history/ |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
341 let parent = iframe.parentNode; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
342 // alert("D = "+direction); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
343 iframe.remove(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
344 parent.appendChild(iframe); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
345 try { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
346 loading.classList.add("loading"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
347 iframe.src = url; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
348 // iframe.contentDocument.location.replace(url); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
349 // location.replace cannot be used because PDF viewer.js |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
350 // does not have iframe.contentDocument |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
351 } catch (err) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
352 alert("Cannot load "+src+" : "+err.name); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
353 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
354 _setPjaxCurposInfo(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
355 setSwipeAct(iframe); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
356 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
357 function switchToByKey(e) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
358 // alert("KEY="+e.key); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
359 switch (e.key) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
360 case "ArrowLeft": |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
361 switchTo(e, -1); break; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
362 case "ArrowRight": |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
363 switchTo(e, +1); break; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
364 case "Escape": |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
365 history.back(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
366 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
367 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
368 // <div><p> |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
369 // <button> << </button><button>Dismiss</button><button> >> </button> |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
370 // </p><p><span> info1 </span> <span> info2 </span></p> |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
371 // <iframe src="..."></iframe> |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
372 // </div> |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
373 // ==> [ << ][Dissmiss][ >> ] |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
374 // ==> ## of ## article #xxx by AUTHOR |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
375 sl.textContent = " << "; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
376 sr.textContent = " >> "; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
377 sl.addEventListener("click", (e) => {switchTo(e, -1);}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
378 sr.addEventListener("click", (e) => {switchTo(e, +1);}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
379 sl.setAttribute("title", "to="+(mynum-1)); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
380 sr.setAttribute("title", "to="+(mynum+1)); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
381 document.body.appendChild(box); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
382 bt.textContent = "Click to dismiss / もどる"+mynum; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
383 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
384 box.appendChild(p1); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
385 p1.appendChild(sl); p1.appendChild(bt); p1.appendChild(sr); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
386 p1.appendChild(loading); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
387 info.appendChild(info1); info.appendChild(info2); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
388 loading.textContent=" Loading..."; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
389 loading.classList.add("hidden"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
390 loading.classList.add("loading"); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
391 box.appendChild(info); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
392 iframe.src = url; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
393 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
394 document.addEventListener("keydown", switchToByKey); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
395 //box.addEventListener("click", (e) => {_resetPjax();}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
396 bt.addEventListener("click", (e) => {_resetPjax();}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
397 // dp.addEventListener("click", (e) => {_resetPjax();}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
398 info.addEventListener("click", (e) => {_resetPjax();}); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
399 box.appendChild(iframe); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
400 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
401 setSwipeAct(iframe); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
402 |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
403 _setPjaxCurposInfo(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
404 bt.focus(); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
405 setTimeout(() => {box.classList.add("pjaxview2");}, 10); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
406 // Finally update history stack |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
407 if (history.pushState) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
408 let h = location.href.replace(/#.*/, '')+"#pjaxview"; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
409 history.pushState({url: h}, null, h); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
410 window.addEventListener("popstate", (e) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
411 if (box) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
412 box.remove(); box = null; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
413 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
414 }, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
415 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
416 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
417 function reverseChecks() { |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
418 var names = collectElementsByAttr("input", "name", "usel"); |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
419 for (let u of names) { |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
420 u.checked = !u.checked; |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
421 } |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
422 } |
852 | 423 function renumberOL(str, start) { |
424 var stra = str.split("\n"); | |
425 for (var i=1; i<stra.length; i++) { | |
426 if (stra[i].match(/^[1-9][0-9]*\. /)) { | |
427 let orig=stra[i]; | |
428 stra[i] = (++start)+". "+RegExp.rightContext; | |
429 } else if (stra[i].match(/^ /)) { | |
430 continue; | |
431 } else | |
432 break; | |
433 } | |
434 return stra.join("\n"); | |
435 } | |
436 function submitThisForm(input) { | |
437 for (var elm=input.parentNode; elm; elm = elm.parentNode) { | |
438 if (elm.nodeName.match(/form/i)) { | |
439 elm.submit(); | |
440 return true; | |
441 } | |
442 } | |
443 return false; | |
444 } | |
445 function helpMarkdownBS(e) { | |
446 var area = e.target, pos = area.selectionStart, text = area.value; | |
447 if (area.selectionStart != area.selectionEnd) return; | |
448 if (pos<2) return; | |
449 if (text.substr(pos-1, 2)=="\n\n") return; | |
450 var bol = text.lastIndexOf("\n", pos-1), | |
451 eol = text.indexOf("\n", pos); | |
452 if (bol<=0 || bol==eol) return; | |
453 var thisline = text.substring(bol+1, eol==-1 ? text.length : eol); | |
454 thisline = text.substring(bol+1, pos); | |
455 if (thisline == "* ") { | |
456 area.setSelectionRange(pos-2, pos); | |
457 } else if (thisline.match(/^[1-9][0-9]*\. $/)) { | |
458 area.setSelectionRange(pos-RegExp.lastMatch.length, pos); | |
459 } | |
460 } | |
461 function helpMarkdownEnter(e) { | |
462 if (e.keyCode == 13 && !e.shiftKey) { | |
463 if (e.metaKey && submitThisForm(e.target)) { | |
464 e.preventDefault(); | |
465 return; | |
466 } | |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
467 var area = e.target; |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
468 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
|
469 if (pos==0) return; |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
470 var last = text.lastIndexOf("\n", pos-1); |
852 | 471 var rest = text.substring(pos), rest0=rest; |
472 var line = last ? text.substring(last+1, pos) : text; | |
473 var next = rest.substring(rest.indexOf("\n"))||rest; | |
474 next=next.substring(1); | |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
475 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
|
476 var add = "", offset = 1; |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
477 if (line.startsWith("* ")) { |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
478 add = "* "; |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
479 offset += add.length; |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
480 if (br) { |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
481 add = " " + "\n" + add; |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
482 } |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
483 } else if (line.match(/^([1-9][0-9]*)\. /)) { |
852 | 484 var ln = parseInt(RegExp.$1), nn=ln+1, |
485 len = RegExp.lastMatch.length; | |
486 add = nn+". "; | |
487 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
|
488 if (br) { |
852 | 489 if (next.startsWith(add)) { |
490 add=" ".repeat(len); | |
491 nn = ln; | |
492 } else { | |
493 add = " ".repeat(len)+ "\n" + add; | |
494 offset -= len+1; | |
495 } | |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
496 } |
852 | 497 if (next.match(/^[1-9][0-9]*\. /)) |
498 rest = renumberOL(rest, nn); | |
499 offset += add.length; | |
500 } else if (line.match(/^\|( *).+\|/)) { | |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
501 add = "|" + RegExp.$1 + " |"; |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
502 offset += add.length-2; |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
503 } else { |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
504 return; |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
505 } |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
506 e.preventDefault(); |
852 | 507 if (!document.execCommand("insertText", false, "\n"+add)) { |
508 //Firefox | |
509 area.selectionEnd = area.value.length; | |
510 area.setRangeText("\n"+add+rest); | |
511 area.selectionEnd = null; | |
512 } else { | |
513 area.selectionEnd = area.value.length; | |
514 area.setSelectionRange(area.selectionStart, area.value.length); | |
515 document.execCommand("insertText", false, rest); | |
516 area.selectionEnd = null; | |
517 area.focus(); | |
518 } | |
519 area.selectionStart = pos+offset; | |
520 return; | |
521 if (document.execCommand("insertText", false, "\n"+add)) { | |
522 //area.setSelectionRange(area.selectionStart, text.length); | |
523 // alert("rest=["+rest+"], add=["+add+"]"); | |
524 alert(text.substring(pos, area.value.length)); | |
525 if (rest != rest0) { | |
526 area.setSelectionRange(pos, area.value.length); | |
527 return; | |
528 document.execCommand("delete"); | |
529 } | |
530 document.execCommand("insertText", false, rest); | |
531 } else { | |
532 // Firefox cannot use insertText in textarea... | |
533 area.value = text.substring(0, pos) + "\n" + add + rest; | |
534 } | |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
535 //area.setSelectionRange(pos+length(add)); |
847
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
536 area.selectionStart=area.selectionEnd = (pos + offset); |
a9e147e355fd
Do not file helper when no pattern matches
HIROSE Yuuji <yuuji@gentei.org>
parents:
846
diff
changeset
|
537 |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
538 } |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
539 } |
852 | 540 function helpMarkdown(e) { |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
541 switch (e.key) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
542 case "Backspace": helpMarkdownBS(e); break; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
543 case "Enter": helpMarkdownEnter(e); break; |
852 | 544 } |
545 } | |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
546 /* Init event listeners */ |
837
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
547 function addFileInput() { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
548 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
|
549 if (!inpfile) return; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
550 var filled = true; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
551 var i, ih; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
552 for (i of inpfile) { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
553 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
|
554 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
555 if (filled) { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
556 ih = i.parentNode.innerHTML; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
557 if (ih) { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
558 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
|
559 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
|
560 i.insertAdjacentHTML("afterend", newi) |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
561 i.nextSibling.nextSibling.addEventListener('change', () => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
562 // next==br next.next==input[type=file] |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
563 warnFileSize(document.forms[0]); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
564 }); |
837
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
565 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
566 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
567 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
568 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
|
569 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
|
570 if (morefile) { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
571 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
|
572 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
|
573 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
|
574 morefile.style.visibility = "visible"; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
575 // 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
|
576 }); |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
577 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
578 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
|
579 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
580 // 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
|
581 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
|
582 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
|
583 var i = ev.target; |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
584 if (i) { |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
585 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
|
586 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
587 }); |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
588 } |
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
589 } |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
590 function initTextarea() { |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
591 var te = collectElementsByAttr("textarea", "name", "text"); |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
592 if (!te || !te[0]) return; |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
593 te[0].addEventListener("keydown", helpMarkdown, false); |
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
594 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
595 function initBlogs() { |
837
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
596 // Auto-complete #xxxx |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
597 let i, check = collectElementsByAttr("input", "name", "notifyto"); |
586 | 598 if (check) |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
599 for (i of check) { |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
600 i.addEventListener("click", insertRedirect, false); |
586 | 601 } |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
602 for (i of document.querySelectorAll("a[href]")) |
590
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
603 if (i.getAttribute("href").match(/^#[0-9]+$/)) |
f480fa97fba6
Redirection also inserted by #XXX anchors
HIROSE Yuuji <yuuji@gentei.org>
parents:
586
diff
changeset
|
604 if (RegExp.lastMatch == i.innerHTML) |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
605 i.addEventListener("click", insertRedirect, false) |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
606 for (i of document.querySelectorAll('input#c[value="送信"]')) { |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
607 let b = document.createElement("button"); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
608 b.textContent = "送信!"; |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
609 console.log("b="+b+", tc="+b.textContent); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
610 b.addEventListener("click", ajaxPost, false); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
611 // i.insertAdjacentElement('afterend', b); |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
612 b.id = i.id; |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
613 i.parentNode.replaceChild(b, i); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
614 i.remove(); |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
615 } |
900
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
616 i = document.getElementById("reload"); |
1fa8b4440f8f
Update button changed to ajax
HIROSE Yuuji <yuuji@gentei.org>
parents:
899
diff
changeset
|
617 if (i) i.addEventListener("click", ajaxPost, false); |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
618 for (let f of document.querySelectorAll('input[type="file"]')) { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
619 let form = document.forms[0]; |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
620 f.addEventListener('change', (e) => { |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
621 warnFileSize(form); |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
622 }, false) |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
623 } |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
624 // Hack article_m links |
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
625 registPjaxViewers(document.querySelectorAll("a[href]")); |
586 | 626 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
627 function initGrpAction() { |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
628 var rev = document.getElementById("reverse"); |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
629 if (!rev) return; // Is not grpAction page |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
630 if (rev.tagName.match(/span/i)) { |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
631 rev.textContent = " 反転 "; |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
632 rev.addEventListener("click", reverseChecks, null); |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
633 } |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
634 var emailbtn = document.getElementById("email"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
635 emailbtn.addEventListener("click", function(ev){ |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
636 // Enlarge box and Select user's checkbox |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
637 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
|
638 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
|
639 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
|
640 x[0].style.height = "10em"; |
42bf03cb3712
Enlarge div of form field when bring them visible
HIROSE Yuuji <yuuji@gentei.org>
parents:
667
diff
changeset
|
641 } |
667
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
642 let myuid = document.getElementById("myuid"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
643 if (myuid) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
644 let usel = collectElementsByAttr("input", "name", "usel"); |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
645 if (usel) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
646 for (u of usel) { |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
647 if (u.value == myuid.value) |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
648 u.checked = true; |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
649 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
650 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
651 } |
9ee0e242c25a
Grp-Message customized for Report-handout
HIROSE Yuuji <yuuji@gentei.org>
parents:
659
diff
changeset
|
652 }, null); |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
653 var teamsel = document.getElementById("selteam"); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
654 if (teamsel) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
655 var usel, p, team; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
656 // Select all members of the team |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
657 teamsel.addEventListener("change", function(ev) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
658 var teamname = teamsel.value, |
676
cd6f0badcff4
\b cannot be used for Japanese boundary...
HIROSE Yuuji <yuuji@gentei.org>
parents:
675
diff
changeset
|
659 selected = new RegExp('(^| )'+teamname+"($|,)"); |
675
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
660 usel = collectElementsByAttr("input", "name", "usel"); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
661 if (!usel) return; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
662 for (u of usel) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
663 p = u.parentNode; // should be label |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
664 if (!p) continue; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
665 if (teamname == "TEAM") { // Reset all checks |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
666 u.checked = false; // when "TEAM" is selected |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
667 } else { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
668 p = p.parentNode.parentNode;// should be tr |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
669 team = nthChildOf(p, 3, "td") |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
670 if (team && team.textContent |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
671 && team.textContent.match(selected)) { |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
672 u.checked = true; |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
673 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
674 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
675 } |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
676 }, null); |
9c54908814be
Team selection in GrpAction anabled with js
HIROSE Yuuji <yuuji@gentei.org>
parents:
673
diff
changeset
|
677 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
678 } |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
679 function dispInfoMomentary(msg, elem) { |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
680 // Momentarily display MSG in tooltip-baloon relative to ELEM element. |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
681 let help = document.createElement("p"); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
682 elem.style.position = 'relative'; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
683 elem.style.overflow = 'visible'; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
684 help.setAttribute("class", "info-tooltip"); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
685 help.innerHTML = msg; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
686 elem.appendChild(help); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
687 setTimeout(() => { |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
688 help.classList.add("dissolving"); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
689 setTimeout(() => help.remove(), 3000); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
690 }, 1000); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
691 } |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
692 function initGrphome() { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
693 console.log("initGrphome"); |
894 | 694 // (1)Setup Frozen State Changing Button |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
695 var ja = navigator.language.match(/ja/i); |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
696 |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
697 function toggleFrozen(e, rowid) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
698 let tgt = mypath+"?blog_setfrozen+"+rowid; |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
699 let td = e.target.parentNode; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
700 let tr = td.parentNode; |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
701 fetch(tgt, { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
702 method: "POST", |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
703 headers: {'Content-Type': 'text/html; charset=utf-8'}, |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
704 credentials: "include" |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
705 }).then(function(resp) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
706 return resp.text(); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
707 }).then(function(tbody) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
708 try { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
709 var json = JSON.parse(tbody); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
710 } catch (e) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
711 return; |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
712 } |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
713 let state = json.state, newstate, info; |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
714 if (json.alert) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
715 alert(json.alert) |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
716 } |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
717 if (state.match(/frozen/i)) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
718 newstate = "凍結"; |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
719 info = ja ? newstate+"に設定しました" : 'Set Frozen'; |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
720 } else { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
721 newstate = null; |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
722 info = ja ? '稼動に設定しました' : 'Set Running'; |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
723 } |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
724 tr.setAttribute("class", newstate); |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
725 dispInfoMomentary(info, td); |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
726 }); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
727 } |
894 | 728 let btn = document.querySelectorAll("button.toggle-frozen"); |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
729 for (let b of btn) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
730 let rowid = null; |
893
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
731 let td=b.parentNode, tr = td.parentNode, fr, ru; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
732 ru = ja ? "動" : "Running"; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
733 fr = ja ? "凍" : "Frozen"; |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
734 b.setAttribute('frozen-marker', fr); |
c1a5d137740d
Display momentary information of frozen state change
HIROSE Yuuji <yuuji@gentei.org>
parents:
889
diff
changeset
|
735 b.setAttribute('running-marker', ru); |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
736 for (let a of tr.querySelectorAll("a[href]")) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
737 if (a.getAttribute("href").match(/\?replyblog\+([0-9]+)/)) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
738 rowid = parseInt(RegExp.$1); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
739 break; |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
740 } |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
741 } |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
742 if (rowid && rowid>0) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
743 b.addEventListener("click", function(e) { |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
744 if (!btn) return; |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
745 toggleFrozen(e, rowid); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
746 }, false); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
747 b.setAttribute("title", "稼動/凍結をその場で切り替えます\n\ |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
748 Toggle Running/Frozen ("+rowid+")"); |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
749 } |
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
750 } |
894 | 751 // (2)Setup Column Collapse Button |
752 // INCOMPLETE: Cannot restore original state, but it's enough... | |
753 function toggleColmnWidth(th) { | |
754 let tbl = document.querySelector("table.dumpblogs"); | |
755 let colname = th.textContent, newwidth; | |
756 if (th.style.width) { | |
757 newwidth = null | |
758 // https://developer.mozilla.org/ja/docs/Web/CSS/table-layout | |
759 tbl.style.tableLayout = 'auto'; | |
760 tbl.style.width = null; | |
761 } else { | |
762 newwidth = "2em"; | |
763 tbl.style.tableLayout = 'fixed'; | |
764 tbl.style.width = '100%'; | |
765 } | |
766 th.style.width = newwidth; | |
767 th.style.overflow = "hidden"; | |
768 for (let td of document.querySelectorAll("td."+colname)) { | |
769 console.log(td.tagName); | |
770 td.style.width = newwidth; | |
771 console.log(td.style.width); | |
772 } | |
773 } | |
774 let row1 = document.querySelector("table.dumpblogs tr:first-child"); | |
775 if (row1) { | |
776 let heads = row1.querySelectorAll("th"); | |
777 for (let h of heads) { | |
778 h.addEventListener("click", function(e) { | |
779 toggleColmnWidth(h); | |
780 }, false); | |
781 h.setAttribute("title", "Click to shrink these columns"); | |
782 } | |
783 } | |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
784 } |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
785 function init() { |
898
411ce55c0dae
AJAX posting and PJAX file-viewer initially introduced.
HIROSE Yuuji <yuuji@gentei.org>
parents:
894
diff
changeset
|
786 isOlderJS = !("insertAdjacentElement" in document.body); |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
787 initGrpAction(); |
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
788 initBlogs(); |
837
a6462eea48be
Multiple files upload for tablets added and file renaming fixed
HIROSE Yuuji <yuuji@gentei.org>
parents:
676
diff
changeset
|
789 initFileInput(); |
846
9c4e16c173db
Add support for small help on describing markdown
HIROSE Yuuji <yuuji@gentei.org>
parents:
837
diff
changeset
|
790 initTextarea(); |
889
5843755e3b30
The beginning of AJAX operations
HIROSE Yuuji <yuuji@gentei.org>
parents:
852
diff
changeset
|
791 initGrphome(); |
659
a36a2c3b3056
GrpAction: Reverse selection and supplemental rcpt address
HIROSE Yuuji <yuuji@gentei.org>
parents:
590
diff
changeset
|
792 } |
586 | 793 document.addEventListener('DOMContentLoaded', init, null); |
794 })(); |