annotate s4-main.js @ 980:f0b63223cb80 draft

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

yatex.org