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