rev |
line source |
yuuji@889
|
1 // 愛
|
yuuji@586
|
2 (function (){
|
yuuji@898
|
3 var isOlderJS; // Set in init();
|
yuuji@898
|
4 var hasTouchPad =
|
yuuji@898
|
5 (navigator.maxTouchPoints && navigator.maxTouchPoints >0);
|
yuuji@898
|
6 var myurl = document.URL,
|
yuuji@898
|
7 mypath = myurl.substring(myurl.lastIndexOf("/"));
|
yuuji@898
|
8 var art_m_list = [];
|
yuuji@946
|
9 var mathjax = false;
|
yuuji@915
|
10 let input_pdfsw = 'input[name="comppdf"]';
|
yuuji@898
|
11 if (mypath.match(/(.*)\/(.*)/)) {
|
yuuji@898
|
12 mypath = RegExp.$2;
|
yuuji@898
|
13 mypath = mypath.substring(0, mypath.lastIndexOf("?"));
|
yuuji@898
|
14 //alert("mypath="+mypath);
|
yuuji@898
|
15 }
|
yuuji@667
|
16 function collectElementsByAttr(elm, attr, val) {
|
yuuji@586
|
17 var e = document.getElementsByTagName(elm);
|
yuuji@586
|
18 if (!e) return null;
|
yuuji@586
|
19 var list = [];
|
yuuji@586
|
20 for (var i of e) {
|
yuuji@667
|
21 if (i.getAttribute(attr) == val)
|
yuuji@586
|
22 list.push(i)
|
yuuji@586
|
23 }
|
yuuji@586
|
24 return list;
|
yuuji@586
|
25 }
|
yuuji@675
|
26 function nthChildOf(parent, n, elem) { // Return Nth child of type ELEM
|
yuuji@675
|
27 // N begins with 1
|
yuuji@675
|
28 var i=0;
|
yuuji@675
|
29 var le = elem.toLowerCase();
|
yuuji@675
|
30 for (var c of parent.childNodes) {
|
yuuji@675
|
31 if (!c.tagName) continue;
|
yuuji@675
|
32 if (c.tagName.toLowerCase() == le) {
|
yuuji@675
|
33 if (++i >= n) return c;
|
yuuji@675
|
34 }
|
yuuji@675
|
35 }
|
yuuji@675
|
36 return null;
|
yuuji@675
|
37 }
|
yuuji@586
|
38 function insertRedirect(e) {
|
yuuji@586
|
39 var articleId, textarea = document.getElementById("text");
|
yuuji@586
|
40 var p = e.target, checked = p.checked;
|
yuuji@586
|
41 while (p = p.parentNode)
|
yuuji@586
|
42 if (p.nodeName.match(/^td$/i)) break;
|
yuuji@586
|
43 if (!p) return;
|
yuuji@586
|
44 while (p = p.nextSibling)
|
yuuji@586
|
45 if (p.nodeName.match(/^td$/i)) break;
|
yuuji@586
|
46 if (!p) return;
|
yuuji@586
|
47 articleId = p.getAttribute("id");
|
yuuji@586
|
48 if (textarea && articleId) {
|
yuuji@586
|
49 var tv = textarea.value, lines;
|
yuuji@586
|
50 if (tv)
|
yuuji@586
|
51 lines = tv.split("\n");
|
yuuji@586
|
52 else
|
yuuji@586
|
53 lines = [""];
|
yuuji@586
|
54 var re = new RegExp("[, ]*#"+articleId+"(?![0-9])");
|
yuuji@590
|
55 checked = (p.nodeName.match(/^input$/)
|
yuuji@590
|
56 ? p.checked // checkbox obeys its status
|
yuuji@590
|
57 : !lines[0].match(re)) // a-elment toggles redirection
|
yuuji@586
|
58 if (checked) {
|
yuuji@586
|
59 if (!lines[0].match(re)) {
|
yuuji@586
|
60 var re2 = new RegExp(/>#[#0-9, ]+[0-9]/);
|
yuuji@586
|
61 if (lines[0].match(re2))
|
yuuji@586
|
62 lines[0] = lines[0].replace(
|
yuuji@586
|
63 re2, '$&, '+'#'+articleId);
|
yuuji@586
|
64 else {
|
yuuji@586
|
65 if (lines[0] > "") lines[0] = " "+lines[0];
|
yuuji@586
|
66 lines[0] = ">#"+articleId+lines[0];
|
yuuji@586
|
67 }
|
yuuji@586
|
68 }
|
yuuji@586
|
69 } else { // Remove #xxxxx
|
yuuji@586
|
70 if (lines[0].match(/^>#[0-9 ,]+#/)) // 2 or more #id's
|
yuuji@586
|
71 lines[0] = lines[0].replace(
|
yuuji@586
|
72 new RegExp("^>#"+articleId+"[ ,]*"), ">").replace(
|
yuuji@586
|
73 new RegExp("[ ,]*#"+articleId), "");
|
yuuji@586
|
74 else {
|
yuuji@586
|
75 lines[0] = lines[0].replace(
|
yuuji@586
|
76 new RegExp(">#"+articleId+"[ ,]*"), "");
|
yuuji@586
|
77 }
|
yuuji@586
|
78 }
|
yuuji@586
|
79 lines[0] = lines[0].replace(/^> *$/, '');
|
yuuji@586
|
80 textarea.value = lines.join("\n");
|
yuuji@586
|
81 }
|
yuuji@586
|
82 }
|
yuuji@898
|
83 function registPjaxViewers(aHrefList) {
|
yuuji@898
|
84 let apos=art_m_list.length;
|
yuuji@898
|
85 for (let a of aHrefList) {
|
yuuji@898
|
86 let href = a.getAttribute("href");
|
yuuji@898
|
87 let localvar = apos;
|
yuuji@898
|
88 let td = a.parentNode,
|
yuuji@898
|
89 tr = td.parentNode,
|
yuuji@898
|
90 id = td.id,
|
yuuji@898
|
91 text = td.textContent,
|
yuuji@898
|
92 author = tr.getElementsByTagName("a");
|
yuuji@898
|
93 if (author) author = author[0].getAttribute("title");
|
yuuji@939
|
94 if (href.match(/\?showattc\+article_m\+([0-9]+)$/)) {
|
yuuji@939
|
95 if (td.innerHTML.match(/読み取り不可/)) {
|
yuuji@898
|
96 a.removeAttribute("href");
|
yuuji@898
|
97 continue;
|
yuuji@898
|
98 }
|
yuuji@898
|
99 let url = RegExp.lastMatch;
|
yuuji@898
|
100 // console.log("pjaxView(e, "+href+", "+apos+")");
|
yuuji@898
|
101 a.addEventListener("click", function(e) {
|
yuuji@898
|
102 // Shoud use closure local variable: localvar
|
yuuji@898
|
103 pjaxView(e, href, localvar);
|
yuuji@898
|
104 }, false);
|
yuuji@898
|
105 apos++;
|
yuuji@898
|
106 art_m_list.push({
|
yuuji@898
|
107 url: href, id: id, author: author, text: text
|
yuuji@898
|
108 });
|
yuuji@898
|
109 }
|
yuuji@898
|
110 }
|
yuuji@898
|
111 }
|
yuuji@906
|
112 function registInsertDirect(aHrefList) {
|
yuuji@906
|
113 for (i of aHrefList)
|
yuuji@906
|
114 if (i.getAttribute("href").match(/^#[0-9]+$/))
|
yuuji@906
|
115 if (RegExp.lastMatch == i.innerHTML)
|
yuuji@906
|
116 i.addEventListener("click", insertRedirect, false)
|
yuuji@906
|
117 }
|
yuuji@946
|
118 function mathjaxUpdate(arg) {
|
yuuji@946
|
119 try {
|
yuuji@946
|
120 if (MathJax && MathJax.typesetPromise) {
|
yuuji@946
|
121 MathJax.texReset(); // Reset Math counters
|
yuuji@946
|
122 MathJax.typesetPromise(arg); // MathJax v3
|
yuuji@946
|
123 }
|
yuuji@946
|
124 } catch (err) {console.log(err);}
|
yuuji@946
|
125 }
|
yuuji@898
|
126 var ajaxSubmit;
|
yuuji@898
|
127 function replAddNews(newtable) {
|
yuuji@898
|
128 let newids = [], idlist=[];
|
yuuji@898
|
129 let getArticleID = function (td) {
|
yuuji@898
|
130 return parseInt(td.parentNode.getElementsByTagName("td")[1].id);
|
yuuji@898
|
131 }
|
yuuji@898
|
132 for (let i of newtable.querySelectorAll("td.repl"))
|
yuuji@898
|
133 newids.push(i);
|
yuuji@898
|
134 newids = newids.sort((a,b)=> {
|
yuuji@898
|
135 return (getArticleID(a) - getArticleID(b));
|
yuuji@898
|
136 });
|
yuuji@898
|
137 for (i of newids)
|
yuuji@898
|
138 idlist.push(getArticleID(i));
|
yuuji@898
|
139 console.log("IDList="+idlist.join());
|
yuuji@900
|
140 let cnt=0, ntr;
|
yuuji@898
|
141 let current = collectElementsByAttr("td", "class", "repl"),
|
yuuji@898
|
142 ncur=0, n, icur=0, o, oid, nid, otr;
|
yuuji@898
|
143 current = document.querySelectorAll('td[class="repl"]');
|
yuuji@898
|
144 let last=current[current.length-1],
|
yuuji@898
|
145 tbody = last.parentNode.parentNode;
|
yuuji@906
|
146 let addEventsToNewTr = function(tr) {
|
yuuji@906
|
147 let td = tr.getElementsByTagName("td"),
|
yuuji@906
|
148 td0 = td[0], td1 = td[1];
|
yuuji@906
|
149 td0.classList.add("new");
|
yuuji@906
|
150 registInsertDirect(td0.querySelectorAll("a[href]"));
|
yuuji@906
|
151 registPjaxViewers(td1.querySelectorAll("a[href]"));
|
yuuji@906
|
152 }
|
yuuji@919
|
153 // Erase all "new article" flags before merging
|
yuuji@919
|
154 for (let i of document.querySelectorAll("td.new"))
|
yuuji@919
|
155 i.classList.remove("new");
|
yuuji@898
|
156 // Now reconstruct articles with merge-sort like method
|
yuuji@898
|
157 outer: for (; ncur<newids.length; ncur++) {
|
yuuji@898
|
158 n = newids[ncur];
|
yuuji@898
|
159 if (!n.id) continue;
|
yuuji@898
|
160 nid = parseInt(n.id);
|
yuuji@898
|
161 if (nid<=0) continue;
|
yuuji@900
|
162 ntr = n.parentNode;
|
yuuji@898
|
163 for (; icur<current.length; icur++) {
|
yuuji@898
|
164 o = current[icur];
|
yuuji@898
|
165 otr = o.parentNode;
|
yuuji@898
|
166 oid = getArticleID(o);
|
yuuji@898
|
167 if (!oid || oid=="") continue;
|
yuuji@898
|
168 if (oid >= nid) {
|
yuuji@906
|
169 addEventsToNewTr(ntr);
|
yuuji@898
|
170 tbody.insertBefore(ntr, otr);
|
yuuji@898
|
171 if (oid==nid) otr.remove();
|
yuuji@898
|
172 cnt++;
|
yuuji@898
|
173 continue outer;
|
yuuji@898
|
174 }
|
yuuji@898
|
175 }
|
yuuji@898
|
176 // Append absolutely new articles.
|
yuuji@898
|
177 ntr = n.parentNode;
|
yuuji@906
|
178 addEventsToNewTr(ntr)
|
yuuji@898
|
179 tbody.appendChild(ntr);
|
yuuji@898
|
180 ntr.classList.add("dissolving");
|
yuuji@900
|
181 let localntr = ntr;
|
yuuji@898
|
182 setTimeout(() => {
|
yuuji@900
|
183 localntr.classList.remove("dissolving");
|
yuuji@900
|
184 localntr.classList.add("emerging");
|
yuuji@898
|
185 }, 100);
|
yuuji@898
|
186 cnt++;
|
yuuji@898
|
187 }
|
yuuji@946
|
188 mathjaxUpdate(newids);
|
yuuji@898
|
189 console.log("Update "+cnt+"rows");
|
yuuji@901
|
190 if (cnt>0 && ntr.scrollIntoView) {
|
yuuji@901
|
191 let option = {behavior: "smooth"};
|
yuuji@901
|
192 if (!isOlderJS) option.block = "center";
|
yuuji@900
|
193 try { // Scroll to last updated row
|
yuuji@901
|
194 ntr.scrollIntoView(option);
|
yuuji@901
|
195 } catch (e1) {}
|
yuuji@901
|
196 }
|
yuuji@898
|
197 return cnt;
|
yuuji@898
|
198 }
|
yuuji@898
|
199
|
yuuji@898
|
200 function warnFileSize(form) {
|
yuuji@898
|
201 let szmax = form.querySelector('input[name="filesize_max"]').value;
|
yuuji@898
|
202 if (!szmax || szmax=="") return;
|
yuuji@898
|
203 szmax = parseInt(szmax);
|
yuuji@898
|
204 if (szmax <= 0) return;
|
yuuji@898
|
205 // szmax = 10000
|
yuuji@915
|
206 let ng = "", rcval=false, fileexists=false,
|
yuuji@915
|
207 pdfsw = form.querySelector(input_pdfsw),
|
yuuji@915
|
208 pdfmsg = "Try compressing PDF?\nPDFを圧縮してみますか?\n" +
|
yuuji@915
|
209 "(それでも収まらない場合もあります)";
|
yuuji@898
|
210 for (let f of form.querySelectorAll('input[type="file"]')) {
|
yuuji@915
|
211 let thiserr = false;
|
yuuji@898
|
212 for (let i of f.files) {
|
yuuji@898
|
213 fileexists = true;
|
yuuji@898
|
214 let fn = i.name, sz = i.size;
|
yuuji@898
|
215 console.log("max="+szmax+", fn="+fn+", sz="+sz);
|
yuuji@898
|
216 if (sz > szmax) {
|
yuuji@915
|
217 if (fn.match(/\.pdf/i)
|
yuuji@915
|
218 && sz < szmax*3 // XXX : x3 reasonable?
|
yuuji@915
|
219 && (pdfsw || confirm(pdfmsg))) {
|
yuuji@915
|
220 if (!pdfsw) {
|
yuuji@915
|
221 pdfsw = document.createElement("input");
|
yuuji@915
|
222 pdfsw.name = "comppdf";
|
yuuji@916
|
223 pdfsw.type = "hidden";
|
yuuji@915
|
224 f.parentNode.insertBefore(pdfsw, f);
|
yuuji@915
|
225 pdfsw.value = "yes";
|
yuuji@915
|
226 }
|
yuuji@915
|
227 } else {
|
yuuji@915
|
228 thiserr = true;
|
yuuji@915
|
229 ng += ((ng>"" ? ", " : "")+fn)
|
yuuji@915
|
230 }
|
yuuji@898
|
231 }
|
yuuji@898
|
232 }
|
yuuji@898
|
233 thiserr ? f.classList.add("warnbg") : f.classList.remove("warnbg");
|
yuuji@898
|
234 }
|
yuuji@898
|
235 if (ng>"") {
|
yuuji@898
|
236 rcval = "File-size Limit Error: "+ng+"\n"+
|
yuuji@898
|
237 "Should be less than "+szmax+"bytes.\n"+
|
yuuji@898
|
238 szmax+"バイト未満にしてください"
|
yuuji@898
|
239 alert(rcval);
|
yuuji@898
|
240 }
|
yuuji@898
|
241 if (form.text.value == "") {
|
yuuji@898
|
242 let w;
|
yuuji@898
|
243 if (fileexists)
|
yuuji@898
|
244 w = "Fill the text area\n" +
|
yuuji@898
|
245 "添付したファイルに関する説明を入れてください。";
|
yuuji@898
|
246 else
|
yuuji@898
|
247 w = "Enter your comment!\n何か書き込んでね!";
|
yuuji@898
|
248 alert(w);
|
yuuji@898
|
249 rcval = (rcval || w);
|
yuuji@898
|
250 form.text.classList.add("warnbg");
|
yuuji@898
|
251 setTimeout(() => {form.text.classList.remove("warnbg");}, 2000)
|
yuuji@898
|
252 }
|
yuuji@898
|
253 return rcval;
|
yuuji@898
|
254 }
|
yuuji@898
|
255 function ajaxPost(e) {
|
yuuji@898
|
256 e.preventDefault();
|
yuuji@898
|
257 let rowid;
|
yuuji@898
|
258 if (!myurl.match(/replyblog\+([0-9]+)/)) return;
|
yuuji@898
|
259 rowid = RegExp.$1
|
yuuji@898
|
260 let myform = document.querySelector("form.replyblog");
|
yuuji@898
|
261 let data = new FormData(myform),
|
yuuji@898
|
262 fetchtime = data.get("fetchtime");
|
yuuji@898
|
263 if (!fetchtime || fetchtime=="") return;
|
yuuji@898
|
264 ///*XX*/fetchtime = "2020-06-14T00:00:00";data.set("fetchtime", fetchtime)
|
yuuji@900
|
265
|
yuuji@900
|
266 ajaxSubmit = e.target;
|
yuuji@900
|
267 ajaxSubmit.back = ajaxSubmit.textContent;
|
yuuji@900
|
268 if (ajaxSubmit.id == "reload") {
|
yuuji@900
|
269 ajaxSubmit.textContent = "更新中"
|
yuuji@900
|
270 data.set("text", "")
|
yuuji@900
|
271 } else {
|
yuuji@900
|
272 if (warnFileSize(myform)) return;
|
yuuji@900
|
273 ajaxSubmit.textContent = "送信中";
|
yuuji@900
|
274 }
|
yuuji@900
|
275 ajaxSubmit.blur();
|
yuuji@900
|
276 ajaxSubmit.disabled = true;
|
yuuji@898
|
277 let act = mypath+"?blog_fetch+"+rowid+"+f:"+fetchtime;
|
yuuji@898
|
278
|
yuuji@898
|
279 function respUpdate(tbody) {
|
yuuji@907
|
280 ajaxSubmit.textContent = ajaxSubmit.back;
|
yuuji@907
|
281 ajaxSubmit.disabled = false;
|
yuuji@898
|
282 let div = document.createElement("div"), form, newform;
|
yuuji@898
|
283 try {
|
yuuji@898
|
284 div.innerHTML = tbody;
|
yuuji@898
|
285 form = div.querySelector("form");
|
yuuji@898
|
286 } catch (er) {
|
yuuji@898
|
287 alert("Cannot parse fetch data");
|
yuuji@898
|
288 return;
|
yuuji@898
|
289 }
|
yuuji@898
|
290 let update = replAddNews(form);
|
yuuji@898
|
291 let dispelem = myform.querySelector("textarea").parentNode;
|
yuuji@907
|
292 if (div.querySelector('input[name="user"]')) { // is login form
|
yuuji@907
|
293 dispInfoMomentary("Login Again Please", dispelem)
|
yuuji@907
|
294 return;
|
yuuji@907
|
295 }
|
yuuji@898
|
296 newform = new FormData(form);
|
yuuji@900
|
297 if (data.get("text") > "") { // Called by submit button
|
yuuji@900
|
298 myform.reset();
|
yuuji@915
|
299 let pdfsw = myform.querySelector(input_pdfsw);
|
yuuji@915
|
300 if (pdfsw) pdfsw.remove();
|
yuuji@900
|
301 // myform.text.value = '';
|
yuuji@900
|
302 }
|
yuuji@898
|
303 myform.fetchtime.value = newform.get("fetchtime");
|
yuuji@898
|
304 myform.id.value = newform.get("id");
|
yuuji@898
|
305 if (update && update > 0) {
|
yuuji@898
|
306 let s = update + " new article" +
|
yuuji@898
|
307 (update>1 ? "s" : "") + " posted";
|
yuuji@898
|
308 dispInfoMomentary(s, dispelem);
|
yuuji@898
|
309 }
|
yuuji@898
|
310 }
|
yuuji@898
|
311 fetch(act, {
|
yuuji@898
|
312 method: "POST", body: data,
|
yuuji@898
|
313 credentials: "include" // For older firefox
|
yuuji@898
|
314 }).then((resp) => {
|
yuuji@898
|
315 return resp.text();
|
yuuji@898
|
316 }).then((tbody) => {
|
yuuji@898
|
317 respUpdate(tbody);
|
yuuji@898
|
318 })
|
yuuji@898
|
319 }
|
yuuji@898
|
320 function pjaxView(ev, url, mynum) {
|
yuuji@928
|
321 if (ev.ctrlKey||ev.shiftKey) return;
|
yuuji@898
|
322 ev.preventDefault();
|
yuuji@898
|
323 let box = document.createElement("div")
|
yuuji@898
|
324 box.setAttribute("class", "pjaxview");
|
yuuji@898
|
325 let p1 = document.createElement("p"),
|
yuuji@898
|
326 bt = document.createElement("button"),
|
yuuji@898
|
327 sl = document.createElement("button"),
|
yuuji@898
|
328 sr = document.createElement("button"),
|
yuuji@898
|
329 loading = document.createElement("span"),
|
yuuji@898
|
330 info = document.createElement("p");
|
yuuji@898
|
331 info1 = document.createElement("span");
|
yuuji@898
|
332 info2 = document.createElement("span");
|
yuuji@898
|
333 iframe = document.createElement("iframe");
|
yuuji@898
|
334 var curpos = mynum;
|
yuuji@898
|
335 var historyBase = history.length;
|
yuuji@898
|
336
|
yuuji@898
|
337 function _setPjaxCurposInfo() {
|
yuuji@898
|
338 let len = art_m_list.length;
|
yuuji@898
|
339 let cur = art_m_list[curpos]
|
yuuji@898
|
340 info1.textContent = (1+curpos)+" of "+len+" article #"+cur.id+
|
yuuji@898
|
341 (cur.author ? " by "+cur.author : "") + ":";
|
yuuji@898
|
342 info2.textContent = cur.text.trim();
|
yuuji@898
|
343 info2.setAttribute("class", "border textdigest");
|
yuuji@898
|
344 }
|
yuuji@898
|
345 function _resetPjax() {
|
yuuji@898
|
346 // All we can do surely is to back 1 page,
|
yuuji@898
|
347 // because we cannot move to desirable entry of history list.
|
yuuji@898
|
348 history.back();
|
yuuji@898
|
349 }
|
yuuji@898
|
350 function setSwipeAct(iframe) {
|
yuuji@898
|
351 // We cannot use DOMContentLoaded nor iframe.contentWindow here.
|
yuuji@898
|
352 // PDF.js does not construct contentWindow...?
|
yuuji@898
|
353 iframe.addEventListener("load", () => {
|
yuuji@898
|
354 loading.classList.remove("loading");
|
yuuji@898
|
355 if (!hasTouchPad) return;
|
yuuji@898
|
356 let ifm = iframe.contentDocument;
|
yuuji@898
|
357 let startX, moveX, thresh = 100;
|
yuuji@898
|
358 ifm.addEventListener("touchstart", (e) => {
|
yuuji@898
|
359 e.preventDefault();
|
yuuji@898
|
360 startX = e.touches[0].pageX;
|
yuuji@898
|
361 }, false);
|
yuuji@898
|
362 ifm.addEventListener("touchmove", (e) => {
|
yuuji@898
|
363 e.preventDefault();
|
yuuji@898
|
364 moveX = e.touches[0].pageX;
|
yuuji@898
|
365 }, false);
|
yuuji@898
|
366 ifm.addEventListener("touchend", (e) => {
|
yuuji@898
|
367 if (startX < moveX && startX + thresh < moveX) {
|
yuuji@898
|
368 switchTo(e, -1);
|
yuuji@898
|
369 } else if (startX > moveX && startX - thresh > moveX) {
|
yuuji@898
|
370 switchTo(e, +1);
|
yuuji@898
|
371 }
|
yuuji@898
|
372 }, false);
|
yuuji@898
|
373 }, false);
|
yuuji@898
|
374
|
yuuji@898
|
375 }
|
yuuji@898
|
376 function switchTo(e, direction) {
|
yuuji@898
|
377 e.preventDefault();
|
yuuji@898
|
378 let len = art_m_list.length, cur, newpos, url;
|
yuuji@898
|
379 newpos = (curpos+len+direction)%len;
|
yuuji@898
|
380 if (curpos == newpos) return; // No need to switch to same one
|
yuuji@898
|
381 curpos = newpos;
|
yuuji@898
|
382 cur = art_m_list[curpos];
|
yuuji@898
|
383 url = cur.url;
|
yuuji@898
|
384 // We should remove iframe once to preserve history Object
|
yuuji@898
|
385 // https://inthetechpit.com/2019/04/20/update-iframe-without-affecting-browser-history/
|
yuuji@898
|
386 let parent = iframe.parentNode;
|
yuuji@898
|
387 // alert("D = "+direction);
|
yuuji@898
|
388 iframe.remove();
|
yuuji@898
|
389 parent.appendChild(iframe);
|
yuuji@898
|
390 try {
|
yuuji@898
|
391 loading.classList.add("loading");
|
yuuji@898
|
392 iframe.src = url;
|
yuuji@898
|
393 // iframe.contentDocument.location.replace(url);
|
yuuji@898
|
394 // location.replace cannot be used because PDF viewer.js
|
yuuji@898
|
395 // does not have iframe.contentDocument
|
yuuji@898
|
396 } catch (err) {
|
yuuji@898
|
397 alert("Cannot load "+src+" : "+err.name);
|
yuuji@898
|
398 }
|
yuuji@898
|
399 _setPjaxCurposInfo();
|
yuuji@898
|
400 setSwipeAct(iframe);
|
yuuji@898
|
401 }
|
yuuji@898
|
402 function switchToByKey(e) {
|
yuuji@898
|
403 // alert("KEY="+e.key);
|
yuuji@898
|
404 switch (e.key) {
|
yuuji@898
|
405 case "ArrowLeft":
|
yuuji@898
|
406 switchTo(e, -1); break;
|
yuuji@898
|
407 case "ArrowRight":
|
yuuji@898
|
408 switchTo(e, +1); break;
|
yuuji@898
|
409 case "Escape":
|
yuuji@898
|
410 history.back();
|
yuuji@898
|
411 }
|
yuuji@898
|
412 }
|
yuuji@898
|
413 // <div><p>
|
yuuji@898
|
414 // <button> << </button><button>Dismiss</button><button> >> </button>
|
yuuji@898
|
415 // </p><p><span> info1 </span> <span> info2 </span></p>
|
yuuji@898
|
416 // <iframe src="..."></iframe>
|
yuuji@898
|
417 // </div>
|
yuuji@898
|
418 // ==> [ << ][Dissmiss][ >> ]
|
yuuji@898
|
419 // ==> ## of ## article #xxx by AUTHOR
|
yuuji@898
|
420 sl.textContent = " << ";
|
yuuji@898
|
421 sr.textContent = " >> ";
|
yuuji@898
|
422 sl.addEventListener("click", (e) => {switchTo(e, -1);});
|
yuuji@898
|
423 sr.addEventListener("click", (e) => {switchTo(e, +1);});
|
yuuji@898
|
424 sl.setAttribute("title", "to="+(mynum-1));
|
yuuji@898
|
425 sr.setAttribute("title", "to="+(mynum+1));
|
yuuji@898
|
426 document.body.appendChild(box);
|
yuuji@898
|
427 bt.textContent = "Click to dismiss / もどる"+mynum;
|
yuuji@898
|
428
|
yuuji@898
|
429 box.appendChild(p1);
|
yuuji@898
|
430 p1.appendChild(sl); p1.appendChild(bt); p1.appendChild(sr);
|
yuuji@930
|
431 { // TEST: Normal mode
|
yuuji@930
|
432 let only = document.createElement("button"),
|
yuuji@930
|
433 h = location.href;
|
yuuji@930
|
434 only.textContent = ".oO□";
|
yuuji@930
|
435 only.setAttribute("title", "Open in Normal Window");
|
yuuji@930
|
436 only.addEventListener("click", function() {
|
yuuji@930
|
437 location.replace(iframe.src);
|
yuuji@930
|
438 });
|
yuuji@930
|
439 p1.appendChild(only);
|
yuuji@930
|
440 }
|
yuuji@898
|
441 p1.appendChild(loading);
|
yuuji@898
|
442 info.appendChild(info1); info.appendChild(info2);
|
yuuji@898
|
443 loading.textContent=" Loading...";
|
yuuji@898
|
444 loading.classList.add("hidden");
|
yuuji@898
|
445 loading.classList.add("loading");
|
yuuji@898
|
446 box.appendChild(info);
|
yuuji@898
|
447 iframe.src = url;
|
yuuji@898
|
448
|
yuuji@925
|
449 box.addEventListener("keydown", switchToByKey);
|
yuuji@898
|
450 //box.addEventListener("click", (e) => {_resetPjax();});
|
yuuji@898
|
451 bt.addEventListener("click", (e) => {_resetPjax();});
|
yuuji@898
|
452 // dp.addEventListener("click", (e) => {_resetPjax();});
|
yuuji@898
|
453 info.addEventListener("click", (e) => {_resetPjax();});
|
yuuji@898
|
454 box.appendChild(iframe);
|
yuuji@898
|
455
|
yuuji@898
|
456 setSwipeAct(iframe);
|
yuuji@898
|
457
|
yuuji@898
|
458 _setPjaxCurposInfo();
|
yuuji@898
|
459 bt.focus();
|
yuuji@898
|
460 setTimeout(() => {box.classList.add("pjaxview2");}, 10);
|
yuuji@898
|
461 // Finally update history stack
|
yuuji@946
|
462 pjaxHistoryPush(box);
|
yuuji@946
|
463 }
|
yuuji@946
|
464 function pjaxHistoryPush(box) {
|
yuuji@898
|
465 if (history.pushState) {
|
yuuji@898
|
466 let h = location.href.replace(/#.*/, '')+"#pjaxview";
|
yuuji@898
|
467 history.pushState({url: h}, null, h);
|
yuuji@898
|
468 window.addEventListener("popstate", (e) => {
|
yuuji@898
|
469 if (box) {
|
yuuji@898
|
470 box.remove(); box = null;
|
yuuji@898
|
471 }
|
yuuji@898
|
472 }, false);
|
yuuji@898
|
473 }
|
yuuji@898
|
474 }
|
yuuji@659
|
475 function reverseChecks() {
|
yuuji@667
|
476 var names = collectElementsByAttr("input", "name", "usel");
|
yuuji@659
|
477 for (let u of names) {
|
yuuji@659
|
478 u.checked = !u.checked;
|
yuuji@659
|
479 }
|
yuuji@659
|
480 }
|
yuuji@852
|
481 function renumberOL(str, start) {
|
yuuji@852
|
482 var stra = str.split("\n");
|
yuuji@852
|
483 for (var i=1; i<stra.length; i++) {
|
yuuji@852
|
484 if (stra[i].match(/^[1-9][0-9]*\. /)) {
|
yuuji@852
|
485 let orig=stra[i];
|
yuuji@852
|
486 stra[i] = (++start)+". "+RegExp.rightContext;
|
yuuji@852
|
487 } else if (stra[i].match(/^ /)) {
|
yuuji@852
|
488 continue;
|
yuuji@852
|
489 } else
|
yuuji@852
|
490 break;
|
yuuji@852
|
491 }
|
yuuji@852
|
492 return stra.join("\n");
|
yuuji@852
|
493 }
|
yuuji@934
|
494 function submitThisForm(e) {
|
yuuji@934
|
495 var input = e.target, ajaxpost = document.getElementById("c");
|
yuuji@852
|
496 for (var elm=input.parentNode; elm; elm = elm.parentNode) {
|
yuuji@934
|
497 if (ajaxpost) {
|
yuuji@934
|
498 ajaxpost.click();
|
yuuji@934
|
499 return true;
|
yuuji@934
|
500 } else if (elm.nodeName.match(/form/i)) {
|
yuuji@852
|
501 elm.submit();
|
yuuji@852
|
502 return true;
|
yuuji@852
|
503 }
|
yuuji@852
|
504 }
|
yuuji@852
|
505 return false;
|
yuuji@852
|
506 }
|
yuuji@852
|
507 function helpMarkdownBS(e) {
|
yuuji@852
|
508 var area = e.target, pos = area.selectionStart, text = area.value;
|
yuuji@852
|
509 if (area.selectionStart != area.selectionEnd) return;
|
yuuji@852
|
510 if (pos<2) return;
|
yuuji@852
|
511 if (text.substr(pos-1, 2)=="\n\n") return;
|
yuuji@852
|
512 var bol = text.lastIndexOf("\n", pos-1),
|
yuuji@852
|
513 eol = text.indexOf("\n", pos);
|
yuuji@852
|
514 if (bol<=0 || bol==eol) return;
|
yuuji@852
|
515 var thisline = text.substring(bol+1, eol==-1 ? text.length : eol);
|
yuuji@852
|
516 thisline = text.substring(bol+1, pos);
|
yuuji@852
|
517 if (thisline == "* ") {
|
yuuji@852
|
518 area.setSelectionRange(pos-2, pos);
|
yuuji@852
|
519 } else if (thisline.match(/^[1-9][0-9]*\. $/)) {
|
yuuji@852
|
520 area.setSelectionRange(pos-RegExp.lastMatch.length, pos);
|
yuuji@852
|
521 }
|
yuuji@852
|
522 }
|
yuuji@852
|
523 function helpMarkdownEnter(e) {
|
yuuji@852
|
524 if (e.keyCode == 13 && !e.shiftKey) {
|
yuuji@934
|
525 if (e.ctrlKey && submitThisForm(e)) {
|
yuuji@852
|
526 e.preventDefault();
|
yuuji@852
|
527 return;
|
yuuji@852
|
528 }
|
yuuji@846
|
529 var area = e.target;
|
yuuji@846
|
530 var pos = area.selectionStart, text = area.value;
|
yuuji@847
|
531 if (pos==0) return;
|
yuuji@846
|
532 var last = text.lastIndexOf("\n", pos-1);
|
yuuji@852
|
533 var rest = text.substring(pos), rest0=rest;
|
yuuji@852
|
534 var line = last ? text.substring(last+1, pos) : text;
|
yuuji@852
|
535 var next = rest.substring(rest.indexOf("\n"))||rest;
|
yuuji@852
|
536 next=next.substring(1);
|
yuuji@847
|
537 var tail = text.substring(pos-2, pos), br = (tail==" ");
|
yuuji@847
|
538 var add = "", offset = 1;
|
yuuji@846
|
539 if (line.startsWith("* ")) {
|
yuuji@847
|
540 add = "* ";
|
yuuji@847
|
541 offset += add.length;
|
yuuji@847
|
542 if (br) {
|
yuuji@847
|
543 add = " " + "\n" + add;
|
yuuji@847
|
544 }
|
yuuji@846
|
545 } else if (line.match(/^([1-9][0-9]*)\. /)) {
|
yuuji@852
|
546 var ln = parseInt(RegExp.$1), nn=ln+1,
|
yuuji@852
|
547 len = RegExp.lastMatch.length;
|
yuuji@852
|
548 add = nn+". ";
|
yuuji@852
|
549 let toeol = text.substr(pos, text.indexOf("\n"));
|
yuuji@852
|
550 if (br) {
|
yuuji@852
|
551 if (next.startsWith(add)) {
|
yuuji@852
|
552 add=" ".repeat(len);
|
yuuji@852
|
553 nn = ln;
|
yuuji@852
|
554 } else {
|
yuuji@852
|
555 add = " ".repeat(len)+ "\n" + add;
|
yuuji@852
|
556 offset -= len+1;
|
yuuji@852
|
557 }
|
yuuji@852
|
558 }
|
yuuji@852
|
559 if (next.match(/^[1-9][0-9]*\. /))
|
yuuji@852
|
560 rest = renumberOL(rest, nn);
|
yuuji@847
|
561 offset += add.length;
|
yuuji@852
|
562 } else if (line.match(/^\|( *).+\|/)) {
|
yuuji@846
|
563 add = "|" + RegExp.$1 + " |";
|
yuuji@847
|
564 offset += add.length-2;
|
yuuji@847
|
565 } else {
|
yuuji@847
|
566 return;
|
yuuji@846
|
567 }
|
yuuji@847
|
568 e.preventDefault();
|
yuuji@852
|
569 if (!document.execCommand("insertText", false, "\n"+add)) {
|
yuuji@852
|
570 //Firefox
|
yuuji@852
|
571 area.selectionEnd = area.value.length;
|
yuuji@852
|
572 area.setRangeText("\n"+add+rest);
|
yuuji@852
|
573 area.selectionEnd = null;
|
yuuji@852
|
574 } else {
|
yuuji@852
|
575 area.selectionEnd = area.value.length;
|
yuuji@852
|
576 area.setSelectionRange(area.selectionStart, area.value.length);
|
yuuji@852
|
577 document.execCommand("insertText", false, rest);
|
yuuji@852
|
578 area.selectionEnd = null;
|
yuuji@852
|
579 area.focus();
|
yuuji@852
|
580 }
|
yuuji@852
|
581 area.selectionStart = pos+offset;
|
yuuji@852
|
582 return;
|
yuuji@852
|
583 if (document.execCommand("insertText", false, "\n"+add)) {
|
yuuji@852
|
584 //area.setSelectionRange(area.selectionStart, text.length);
|
yuuji@852
|
585 // alert("rest=["+rest+"], add=["+add+"]");
|
yuuji@852
|
586 alert(text.substring(pos, area.value.length));
|
yuuji@852
|
587 if (rest != rest0) {
|
yuuji@852
|
588 area.setSelectionRange(pos, area.value.length);
|
yuuji@852
|
589 return;
|
yuuji@852
|
590 document.execCommand("delete");
|
yuuji@852
|
591 }
|
yuuji@852
|
592 document.execCommand("insertText", false, rest);
|
yuuji@852
|
593 } else {
|
yuuji@852
|
594 // Firefox cannot use insertText in textarea...
|
yuuji@852
|
595 area.value = text.substring(0, pos) + "\n" + add + rest;
|
yuuji@852
|
596 }
|
yuuji@846
|
597 //area.setSelectionRange(pos+length(add));
|
yuuji@847
|
598 area.selectionStart=area.selectionEnd = (pos + offset);
|
yuuji@847
|
599
|
yuuji@846
|
600 }
|
yuuji@846
|
601 }
|
yuuji@946
|
602 var helpParenPreview = 0;
|
yuuji@946
|
603 function helpMarkdownParen(e) {
|
yuuji@946
|
604 if (!mathjax) return;
|
yuuji@946
|
605 var area = e.target, pos = area.selectionStart, text = area.value;
|
yuuji@946
|
606 if (pos<2) return;
|
yuuji@946
|
607 if (text[pos-1] == "\\") {
|
yuuji@946
|
608 let ins="( \\)";
|
yuuji@946
|
609 if (text[pos-2] == "\\") ins="( \\\\)";
|
yuuji@946
|
610 area.setRangeText(ins, pos, pos);
|
yuuji@946
|
611 area.selectionStart = pos+2;
|
yuuji@946
|
612 if (helpParenPreview++ < 1) {
|
yuuji@946
|
613 dispInfoMomentary("Preview formula by Meta-p\n"+
|
yuuji@946
|
614 "Meta-p で数式プレビュー", e.target.parentNode);
|
yuuji@946
|
615 }
|
yuuji@946
|
616 e.preventDefault();
|
yuuji@946
|
617 }
|
yuuji@946
|
618 }
|
yuuji@947
|
619 function textInsert(area, string, pos1, pos2) {
|
yuuji@947
|
620 console.log("str="+string);
|
yuuji@947
|
621 area.setRangeText(string, pos1||area.selectionStart,
|
yuuji@947
|
622 pos2||pos1||area.selectionStart);
|
yuuji@947
|
623 area.selectionStart += string.length;
|
yuuji@947
|
624 }
|
yuuji@947
|
625 function beginningOfLine(area, pos) {
|
yuuji@947
|
626 pos = pos||area.selectionStart;
|
yuuji@947
|
627 let b = area.value.lastIndexOf("\n", pos);
|
yuuji@947
|
628 if (pos>1 && area.value.charCodeAt(pos)==10)
|
yuuji@947
|
629 b = area.value.lastIndexOf("\n", pos-1);;
|
yuuji@947
|
630 return b>=0 ? b : 0;
|
yuuji@947
|
631 }
|
yuuji@947
|
632 function isInBeginEnd(area, pos){
|
yuuji@947
|
633 pos = pos||area.selectionStart;
|
yuuji@947
|
634 let bol = beginningOfLine(area, pos);
|
yuuji@947
|
635 let thisline = area.value.substr(bol);
|
yuuji@947
|
636 console.log("curchar="+area.value.charCodeAt(pos));
|
yuuji@947
|
637 console.log("prechar="+area.value.charCodeAt(pos-1));
|
yuuji@947
|
638 console.log("bol="+bol+", thisline="+thisline);
|
yuuji@947
|
639 let match = thisline.search(/\\(begin|end){([A-Za-z]*)/), lm, be;
|
yuuji@947
|
640 if (match >= 0) {
|
yuuji@947
|
641 lm = RegExp.lastMatch;
|
yuuji@947
|
642 be = RegExp.$1;
|
yuuji@947
|
643 return RegExp.$2
|
yuuji@947
|
644 }
|
yuuji@947
|
645 return null;
|
yuuji@946
|
646 }
|
yuuji@946
|
647 function helpMarkdownBrace(e) {
|
yuuji@946
|
648 if (!mathjax) return;
|
yuuji@946
|
649 var area = e.target, pos = area.selectionStart, text = area.value,
|
yuuji@946
|
650 begin = "\\begin", end = "\\end";
|
yuuji@946
|
651 if (pos < end.length) return;
|
yuuji@946
|
652 if (text.substr(pos-end.length).startsWith(end)) {
|
yuuji@946
|
653 let beg = text.lastIndexOf(begin, pos);
|
yuuji@946
|
654 if (beg >= 0) {
|
yuuji@946
|
655 let env = text.substr(beg).search(/\\begin{(.*?)}/);
|
yuuji@946
|
656 if (env >= 0) {
|
yuuji@947
|
657 textInsert(area, "{"+RegExp.$1+"}", pos);
|
yuuji@946
|
658 e.preventDefault();
|
yuuji@946
|
659 }
|
yuuji@946
|
660 }
|
yuuji@946
|
661 }
|
yuuji@946
|
662 }
|
yuuji@947
|
663 function helpMarkdownBraceClose(e) {
|
yuuji@947
|
664 if (!mathjax) return;
|
yuuji@947
|
665 let area = e.target, pos = area.selectionStart, text = area.value,
|
yuuji@947
|
666 begin = "\\begin", end = "\\end";
|
yuuji@947
|
667 if (text.substr(pos).startsWith("}")) {
|
yuuji@947
|
668 area.setRangeText("", pos, pos+1);
|
yuuji@947
|
669 // e.preventDefault();
|
yuuji@947
|
670 }
|
yuuji@947
|
671 let inbegend = isInBeginEnd(area, pos);
|
yuuji@948
|
672 if (!inbegend) return;
|
yuuji@947
|
673 let nextendpos = text.substr(pos).indexOf("\\end{");
|
yuuji@947
|
674 let nextcurend = text.substr(pos).indexOf("\\end{"+inbegend+"}");
|
yuuji@947
|
675 if (nextcurend<0 || nextendpos!=nextcurend) {
|
yuuji@947
|
676 area.setRangeText("}\n\n\\end{"+inbegend+"}", pos, pos);
|
yuuji@947
|
677 area.selectionStart = pos+2;
|
yuuji@947
|
678 e.preventDefault();
|
yuuji@947
|
679 }
|
yuuji@947
|
680 console.log(inbegend);
|
yuuji@947
|
681
|
yuuji@947
|
682 }
|
yuuji@946
|
683 function helpMarkdownPreview(area) {
|
yuuji@946
|
684 if (!mathjax) {
|
yuuji@946
|
685 alert("no"+e.target)
|
yuuji@946
|
686 dispInfoMomentary("This board has no MathJax mode.\n"+
|
yuuji@946
|
687 "この掲示板は数式モードOFFです。",
|
yuuji@946
|
688 e.target.parentNode);
|
yuuji@946
|
689 return;
|
yuuji@946
|
690 }
|
yuuji@946
|
691 let text = area.value;
|
yuuji@946
|
692 let preview = document.createElement("div");
|
yuuji@946
|
693 let bp = document.createElement("p");
|
yuuji@946
|
694 let btn = document.createElement("button");
|
yuuji@946
|
695 btn.innerText = "Click or ESC to Dissmiss / クリックかESCで戻る";
|
yuuji@946
|
696 bp.classList.add("c");
|
yuuji@946
|
697 preview.classList.add("pjaxview");
|
yuuji@946
|
698 preview.classList.add("pjaxview2");
|
yuuji@946
|
699 let pre = document.createElement("p");
|
yuuji@946
|
700 bp.appendChild(btn);
|
yuuji@946
|
701 preview.appendChild(bp);
|
yuuji@946
|
702 preview.appendChild(pre);
|
yuuji@946
|
703 pre.innerText = text;
|
yuuji@946
|
704 document.body.appendChild(preview);
|
yuuji@946
|
705 function dismiss(t) {
|
yuuji@946
|
706 history.back();
|
yuuji@946
|
707 preview.remove();
|
yuuji@946
|
708 area.focus();
|
yuuji@946
|
709 }
|
yuuji@946
|
710 preview.addEventListener("click", dismiss, false);
|
yuuji@946
|
711 preview.addEventListener("keydown", dismiss, false);
|
yuuji@946
|
712 MathJax.typesetPromise([pre]);
|
yuuji@946
|
713 pjaxHistoryPush(preview);
|
yuuji@946
|
714 btn.focus();
|
yuuji@946
|
715 }
|
yuuji@852
|
716 function helpMarkdown(e) {
|
yuuji@898
|
717 switch (e.key) {
|
yuuji@898
|
718 case "Backspace": helpMarkdownBS(e); break;
|
yuuji@898
|
719 case "Enter": helpMarkdownEnter(e); break;
|
yuuji@946
|
720 case "(": helpMarkdownParen(e); break;
|
yuuji@946
|
721 case "p": if (e.metaKey) helpMarkdownPreview(e.target); break;
|
yuuji@946
|
722 case "{": helpMarkdownBrace(e); break;
|
yuuji@947
|
723 case "}": helpMarkdownBraceClose(e); break;
|
yuuji@852
|
724 }
|
yuuji@852
|
725 }
|
yuuji@846
|
726 /* Init event listeners */
|
yuuji@837
|
727 function addFileInput() {
|
yuuji@837
|
728 var inpfile = collectElementsByAttr("input", "name", "image");
|
yuuji@837
|
729 if (!inpfile) return;
|
yuuji@837
|
730 var filled = true;
|
yuuji@837
|
731 var i, ih;
|
yuuji@837
|
732 for (i of inpfile) {
|
yuuji@837
|
733 if (! i.value) filled=false;
|
yuuji@837
|
734 }
|
yuuji@837
|
735 if (filled) {
|
yuuji@837
|
736 ih = i.parentNode.innerHTML;
|
yuuji@837
|
737 if (ih) {
|
yuuji@837
|
738 var inpf = ih.substring(ih.indexOf("<input")),
|
yuuji@837
|
739 newi = "<br>"+inpf.substring(0, inpf.indexOf(">")+1);
|
yuuji@837
|
740 i.insertAdjacentHTML("afterend", newi)
|
yuuji@898
|
741 i.nextSibling.nextSibling.addEventListener('change', () => {
|
yuuji@898
|
742 // next==br next.next==input[type=file]
|
yuuji@898
|
743 warnFileSize(document.forms[0]);
|
yuuji@898
|
744 });
|
yuuji@837
|
745 }
|
yuuji@837
|
746 }
|
yuuji@837
|
747 }
|
yuuji@837
|
748 function initFileInput() { // Multiplies "input type=file"
|
yuuji@837
|
749 var el, morefile = document.getElementById("morefile");
|
yuuji@837
|
750 if (morefile) {
|
yuuji@837
|
751 for (el of collectElementsByAttr("input", "name", "image")) {
|
yuuji@837
|
752 el.addEventListener("change", function(ev) {
|
yuuji@837
|
753 if (ev.target.value > "" && ev.target.files.length == 1)
|
yuuji@837
|
754 morefile.style.visibility = "visible";
|
yuuji@837
|
755 // No need to hide again, sure?
|
yuuji@837
|
756 });
|
yuuji@837
|
757 }
|
yuuji@837
|
758 morefile.addEventListener("click", addFileInput, null);
|
yuuji@837
|
759 }
|
yuuji@837
|
760 // When renaming, select basename part
|
yuuji@837
|
761 for (el of collectElementsByAttr("input", "class", "mv")) {
|
yuuji@837
|
762 el.addEventListener("focus", function(ev) {
|
yuuji@837
|
763 var i = ev.target;
|
yuuji@837
|
764 if (i) {
|
yuuji@837
|
765 i.setSelectionRange(0, i.value.lastIndexOf("."));
|
yuuji@837
|
766 }
|
yuuji@837
|
767 });
|
yuuji@837
|
768 }
|
yuuji@837
|
769 }
|
yuuji@846
|
770 function initTextarea() {
|
yuuji@846
|
771 var te = collectElementsByAttr("textarea", "name", "text");
|
yuuji@846
|
772 if (!te || !te[0]) return;
|
yuuji@846
|
773 te[0].addEventListener("keydown", helpMarkdown, false);
|
yuuji@846
|
774 }
|
yuuji@659
|
775 function initBlogs() {
|
yuuji@837
|
776 // Auto-complete #xxxx
|
yuuji@900
|
777 let i, check = collectElementsByAttr("input", "name", "notifyto");
|
yuuji@586
|
778 if (check)
|
yuuji@900
|
779 for (i of check) {
|
yuuji@898
|
780 i.addEventListener("click", insertRedirect, false);
|
yuuji@586
|
781 }
|
yuuji@906
|
782 registInsertDirect(document.querySelectorAll("a[href]"));
|
yuuji@911
|
783 if (myurl.match(/replyblog\+[0-9]/)
|
yuuji@911
|
784 && document.querySelector("td.repl")) {
|
yuuji@911
|
785 // There's no need to provide ajax posting when
|
yuuji@911
|
786 // no replies written to the blog. Therefore we
|
yuuji@911
|
787 // assign ajax post when td.repl exists.
|
yuuji@909
|
788 for (i of document.querySelectorAll('input#c[value="送信"]')) {
|
yuuji@909
|
789 let b = document.createElement("button");
|
yuuji@909
|
790 b.textContent = "送信!";
|
yuuji@909
|
791 console.log("b="+b+", tc="+b.textContent);
|
yuuji@909
|
792 b.addEventListener("click", ajaxPost, false);
|
yuuji@909
|
793 // i.insertAdjacentElement('afterend', b);
|
yuuji@910
|
794 b.setAttribute("class", i.getAttribute("class"))
|
yuuji@910
|
795 b.setAttribute("title", i.getAttribute("title"))
|
yuuji@910
|
796 i.parentNode.replaceChild(b, i);
|
yuuji@909
|
797 b.id = i.id;
|
yuuji@914
|
798 // i.remove();
|
yuuji@914
|
799 i.classList.add("aux");
|
yuuji@914
|
800 i.value = "送信(予備)"
|
yuuji@914
|
801 b.parentNode.appendChild(i);
|
yuuji@909
|
802 }
|
yuuji@911
|
803 i = document.getElementById("reload");
|
yuuji@911
|
804 if (i) i.addEventListener("click", ajaxPost, false);
|
yuuji@911
|
805 }
|
yuuji@902
|
806 for (i of document.querySelectorAll('input[type="file"]')) {
|
yuuji@902
|
807 i.addEventListener('change', (e) => {
|
yuuji@902
|
808 warnFileSize(document.forms[0]);
|
yuuji@898
|
809 }, false)
|
yuuji@898
|
810 }
|
yuuji@898
|
811 // Hack article_m links
|
yuuji@898
|
812 registPjaxViewers(document.querySelectorAll("a[href]"));
|
yuuji@586
|
813 }
|
yuuji@659
|
814 function initGrpAction() {
|
yuuji@659
|
815 var rev = document.getElementById("reverse");
|
yuuji@667
|
816 if (!rev) return; // Is not grpAction page
|
yuuji@667
|
817 if (rev.tagName.match(/span/i)) {
|
yuuji@659
|
818 rev.textContent = " 反転 ";
|
yuuji@659
|
819 rev.addEventListener("click", reverseChecks, null);
|
yuuji@659
|
820 }
|
yuuji@667
|
821 var emailbtn = document.getElementById("email");
|
yuuji@667
|
822 emailbtn.addEventListener("click", function(ev){
|
yuuji@675
|
823 // Enlarge box and Select user's checkbox
|
yuuji@667
|
824 if (!ev.target.checked) return;
|
yuuji@673
|
825 var x = collectElementsByAttr("div", "class", "foldtabs");
|
yuuji@673
|
826 if (x && x[0] && x[0].style) {
|
yuuji@673
|
827 x[0].style.height = "10em";
|
yuuji@673
|
828 }
|
yuuji@667
|
829 let myuid = document.getElementById("myuid");
|
yuuji@667
|
830 if (myuid) {
|
yuuji@667
|
831 let usel = collectElementsByAttr("input", "name", "usel");
|
yuuji@667
|
832 if (usel) {
|
yuuji@667
|
833 for (u of usel) {
|
yuuji@667
|
834 if (u.value == myuid.value)
|
yuuji@667
|
835 u.checked = true;
|
yuuji@667
|
836 }
|
yuuji@667
|
837 }
|
yuuji@667
|
838 }
|
yuuji@667
|
839 }, null);
|
yuuji@675
|
840 var teamsel = document.getElementById("selteam");
|
yuuji@675
|
841 if (teamsel) {
|
yuuji@675
|
842 var usel, p, team;
|
yuuji@675
|
843 // Select all members of the team
|
yuuji@675
|
844 teamsel.addEventListener("change", function(ev) {
|
yuuji@675
|
845 var teamname = teamsel.value,
|
yuuji@676
|
846 selected = new RegExp('(^| )'+teamname+"($|,)");
|
yuuji@675
|
847 usel = collectElementsByAttr("input", "name", "usel");
|
yuuji@675
|
848 if (!usel) return;
|
yuuji@675
|
849 for (u of usel) {
|
yuuji@675
|
850 p = u.parentNode; // should be label
|
yuuji@675
|
851 if (!p) continue;
|
yuuji@675
|
852 if (teamname == "TEAM") { // Reset all checks
|
yuuji@675
|
853 u.checked = false; // when "TEAM" is selected
|
yuuji@675
|
854 } else {
|
yuuji@675
|
855 p = p.parentNode.parentNode;// should be tr
|
yuuji@938
|
856 team = nthChildOf(p, 4, "td")
|
yuuji@675
|
857 if (team && team.textContent
|
yuuji@675
|
858 && team.textContent.match(selected)) {
|
yuuji@675
|
859 u.checked = true;
|
yuuji@675
|
860 }
|
yuuji@675
|
861 }
|
yuuji@675
|
862 }
|
yuuji@675
|
863 }, null);
|
yuuji@675
|
864 }
|
yuuji@659
|
865 }
|
yuuji@893
|
866 function dispInfoMomentary(msg, elem) {
|
yuuji@893
|
867 // Momentarily display MSG in tooltip-baloon relative to ELEM element.
|
yuuji@893
|
868 let help = document.createElement("p");
|
yuuji@893
|
869 elem.style.position = 'relative';
|
yuuji@893
|
870 elem.style.overflow = 'visible';
|
yuuji@893
|
871 help.setAttribute("class", "info-tooltip");
|
yuuji@893
|
872 help.innerHTML = msg;
|
yuuji@893
|
873 elem.appendChild(help);
|
yuuji@893
|
874 setTimeout(() => {
|
yuuji@893
|
875 help.classList.add("dissolving");
|
yuuji@893
|
876 setTimeout(() => help.remove(), 3000);
|
yuuji@893
|
877 }, 1000);
|
yuuji@893
|
878 }
|
yuuji@889
|
879 function initGrphome() {
|
yuuji@889
|
880 console.log("initGrphome");
|
yuuji@894
|
881 // (1)Setup Frozen State Changing Button
|
yuuji@893
|
882 var ja = navigator.language.match(/ja/i);
|
yuuji@889
|
883
|
yuuji@889
|
884 function toggleFrozen(e, rowid) {
|
yuuji@889
|
885 let tgt = mypath+"?blog_setfrozen+"+rowid;
|
yuuji@893
|
886 let td = e.target.parentNode;
|
yuuji@893
|
887 let tr = td.parentNode;
|
yuuji@889
|
888 fetch(tgt, {
|
yuuji@889
|
889 method: "POST",
|
yuuji@889
|
890 headers: {'Content-Type': 'text/html; charset=utf-8'},
|
yuuji@898
|
891 credentials: "include"
|
yuuji@889
|
892 }).then(function(resp) {
|
yuuji@889
|
893 return resp.text();
|
yuuji@889
|
894 }).then(function(tbody) {
|
yuuji@889
|
895 try {
|
yuuji@889
|
896 var json = JSON.parse(tbody);
|
yuuji@889
|
897 } catch (e) {
|
yuuji@889
|
898 return;
|
yuuji@889
|
899 }
|
yuuji@893
|
900 let state = json.state, newstate, info;
|
yuuji@889
|
901 if (json.alert) {
|
yuuji@889
|
902 alert(json.alert)
|
yuuji@889
|
903 }
|
yuuji@889
|
904 if (state.match(/frozen/i)) {
|
yuuji@889
|
905 newstate = "凍結";
|
yuuji@893
|
906 info = ja ? newstate+"に設定しました" : 'Set Frozen';
|
yuuji@889
|
907 } else {
|
yuuji@889
|
908 newstate = null;
|
yuuji@893
|
909 info = ja ? '稼動に設定しました' : 'Set Running';
|
yuuji@889
|
910 }
|
yuuji@889
|
911 tr.setAttribute("class", newstate);
|
yuuji@893
|
912 dispInfoMomentary(info, td);
|
yuuji@889
|
913 });
|
yuuji@889
|
914 }
|
yuuji@894
|
915 let btn = document.querySelectorAll("button.toggle-frozen");
|
yuuji@889
|
916 for (let b of btn) {
|
yuuji@889
|
917 let rowid = null;
|
yuuji@893
|
918 let td=b.parentNode, tr = td.parentNode, fr, ru;
|
yuuji@893
|
919 ru = ja ? "動" : "Running";
|
yuuji@893
|
920 fr = ja ? "凍" : "Frozen";
|
yuuji@893
|
921 b.setAttribute('frozen-marker', fr);
|
yuuji@893
|
922 b.setAttribute('running-marker', ru);
|
yuuji@889
|
923 for (let a of tr.querySelectorAll("a[href]")) {
|
yuuji@889
|
924 if (a.getAttribute("href").match(/\?replyblog\+([0-9]+)/)) {
|
yuuji@889
|
925 rowid = parseInt(RegExp.$1);
|
yuuji@889
|
926 break;
|
yuuji@889
|
927 }
|
yuuji@889
|
928 }
|
yuuji@889
|
929 if (rowid && rowid>0) {
|
yuuji@889
|
930 b.addEventListener("click", function(e) {
|
yuuji@889
|
931 if (!btn) return;
|
yuuji@889
|
932 toggleFrozen(e, rowid);
|
yuuji@889
|
933 }, false);
|
yuuji@889
|
934 b.setAttribute("title", "稼動/凍結をその場で切り替えます\n\
|
yuuji@889
|
935 Toggle Running/Frozen ("+rowid+")");
|
yuuji@889
|
936 }
|
yuuji@889
|
937 }
|
yuuji@894
|
938 // (2)Setup Column Collapse Button
|
yuuji@894
|
939 // INCOMPLETE: Cannot restore original state, but it's enough...
|
yuuji@894
|
940 function toggleColmnWidth(th) {
|
yuuji@894
|
941 let tbl = document.querySelector("table.dumpblogs");
|
yuuji@894
|
942 let colname = th.textContent, newwidth;
|
yuuji@894
|
943 if (th.style.width) {
|
yuuji@894
|
944 newwidth = null
|
yuuji@894
|
945 // https://developer.mozilla.org/ja/docs/Web/CSS/table-layout
|
yuuji@894
|
946 tbl.style.tableLayout = 'auto';
|
yuuji@894
|
947 tbl.style.width = null;
|
yuuji@894
|
948 } else {
|
yuuji@894
|
949 newwidth = "2em";
|
yuuji@894
|
950 tbl.style.tableLayout = 'fixed';
|
yuuji@894
|
951 tbl.style.width = '100%';
|
yuuji@894
|
952 }
|
yuuji@894
|
953 th.style.width = newwidth;
|
yuuji@894
|
954 th.style.overflow = "hidden";
|
yuuji@894
|
955 for (let td of document.querySelectorAll("td."+colname)) {
|
yuuji@894
|
956 console.log(td.tagName);
|
yuuji@894
|
957 td.style.width = newwidth;
|
yuuji@894
|
958 console.log(td.style.width);
|
yuuji@894
|
959 }
|
yuuji@894
|
960 }
|
yuuji@894
|
961 let row1 = document.querySelector("table.dumpblogs tr:first-child");
|
yuuji@894
|
962 if (row1) {
|
yuuji@894
|
963 let heads = row1.querySelectorAll("th");
|
yuuji@894
|
964 for (let h of heads) {
|
yuuji@894
|
965 h.addEventListener("click", function(e) {
|
yuuji@894
|
966 toggleColmnWidth(h);
|
yuuji@894
|
967 }, false);
|
yuuji@894
|
968 h.setAttribute("title", "Click to shrink these columns");
|
yuuji@894
|
969 }
|
yuuji@894
|
970 }
|
yuuji@889
|
971 }
|
yuuji@946
|
972 function initMath() {
|
yuuji@946
|
973 mathjax = MathJax||document.getElementById("mathjax");
|
yuuji@946
|
974 if (!mathjax) return;
|
yuuji@946
|
975 let ta = document.querySelector("textarea");
|
yuuji@946
|
976 if (!ta) return;
|
yuuji@946
|
977 let btn = document.createElement("button");
|
yuuji@954
|
978 btn.setAttribute("title", "\\( と \\) で数式利用\n"+
|
yuuji@954
|
979 "\\[ と \\] で段組み数式モード\n"+
|
yuuji@954
|
980 "便利なマクロ:\n"+
|
yuuji@954
|
981 " \\boxed{aaa}, \\fcolorbox{framecolor}{bgcolor}{text}\n"+
|
yuuji@954
|
982 " \\underline{aaa}, \\fcolorbox{framecolor}{bgcolor}{text}\n"+
|
yuuji@954
|
983 "独自定義マクロ:\n"+
|
yuuji@954
|
984 " \\warn{xxx} 注意喚起用色付き枠\n"+
|
yuuji@954
|
985 " \\Warn{xxx} 大きな文字で注意喚起")
|
yuuji@946
|
986 btn.innerHTML = "MathJax<br>Preview";
|
yuuji@946
|
987 btn.addEventListener('click', (e) => {
|
yuuji@946
|
988 e.preventDefault();
|
yuuji@946
|
989 ta.focus();
|
yuuji@946
|
990 helpMarkdownPreview(ta);
|
yuuji@946
|
991 });
|
yuuji@949
|
992 ta.parentNode.appendChild(btn);
|
yuuji@946
|
993 }
|
yuuji@659
|
994 function init() {
|
yuuji@898
|
995 isOlderJS = !("insertAdjacentElement" in document.body);
|
yuuji@659
|
996 initGrpAction();
|
yuuji@659
|
997 initBlogs();
|
yuuji@837
|
998 initFileInput();
|
yuuji@846
|
999 initTextarea();
|
yuuji@889
|
1000 initGrphome();
|
yuuji@946
|
1001 initMath();
|
yuuji@659
|
1002 }
|
yuuji@586
|
1003 document.addEventListener('DOMContentLoaded', init, null);
|
yuuji@586
|
1004 })();
|