comparison s4-main.js @ 1000:ddf85e80f64e draft

Hover text for reply marks were breaking pjax view, fixed.
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 04 Dec 2022 09:56:36 +0859
parents f7cd4528926b
children bbd5a0c50d5b
comparison
equal deleted inserted replaced
999:1fd61bbd69f8 1000:ddf85e80f64e
13 mypath = RegExp.$2; 13 mypath = RegExp.$2;
14 mypath = mypath.substring(0, mypath.lastIndexOf("?")); 14 mypath = mypath.substring(0, mypath.lastIndexOf("?"));
15 //alert("mypath="+mypath); 15 //alert("mypath="+mypath);
16 } 16 }
17 function escapeChars(old) { 17 function escapeChars(old) {
18 return old.replaceAll('"', '&quot;') 18 return old.replaceAll('&', '&amp;')
19 .replaceAll('"', '&quot;')
19 .replaceAll("<", '&lt;') 20 .replaceAll("<", '&lt;')
20 .replaceAll(">", '&gt;'); 21 .replaceAll(">", '&gt;');
21 } 22 }
22 function collectElementsByAttr(elm, attr, val) { 23 function collectElementsByAttr(elm, attr, val) {
23 var e = document.getElementsByTagName(elm); 24 var e = document.getElementsByTagName(elm);
1145 } else 1146 } else
1146 return ""; 1147 return "";
1147 } 1148 }
1148 unit = unit||document; 1149 unit = unit||document;
1149 for (let td of unit.querySelectorAll("td.repl")) { 1150 for (let td of unit.querySelectorAll("td.repl")) {
1150 let text = td.innerHTML; 1151 let firstC = td.firstChild;
1151 if (text.startsWith("\&gt;#")) { 1152 // Direct replacing innerHTML breaks embedded DOM event handlers.
1152 let newline = text.indexOf("\n"); 1153 // So, we split td.repl into elements and replace the first
1153 let first, rest; 1154 // textNode(nodeType==3) with hover-text embeded content.
1155 if (firstC.nodeType==3 && firstC.nodeValue.startsWith(">#")) {
1156 let newline = firstC.nodeValue.indexOf("\n");
1157 let firstline;
1154 if (newline > 0) { 1158 if (newline > 0) {
1155 first = text.substring(0, newline); 1159 firstline = firstC.nodeValue.substring(0, 1+newline);
1156 rest = text.substring(newline); 1160 firstC.nodeValue = firstC.nodeValue.substring(1+newline);
1157 } else { 1161 } else {
1158 first = text; 1162 // Cannot be reached here, but leave this for robustness
1159 rest = ""; 1163 firstline = firstC.nodeValue;
1160 } 1164 firstC.nodeValue = "";
1161 td.innerHTML = first.replace( 1165 }
1162 /#([0-9]+)/g, 1166 td.insertAdjacentHTML(
1163 (match, start, whole) => { 1167 'afterbegin',
1164 let id = RegExp.$1 1168 escapeChars(firstline).replace(
1165 return '<a title="' + getTextById(id) 1169 /#([0-9]+)/g,
1166 + '" href="' + match 1170 (match, start, whole) => {
1167 + '">' + match + '</a>'; 1171 let id = RegExp.$1
1168 } 1172 return '<a title="' + getTextById(id)
1169 ) + rest; 1173 + '" href="' + match
1174 + '">' + match + '</a>';
1175 }));
1170 } 1176 }
1171 } 1177 }
1172 } 1178 }
1173 function initReplyHover(unit) { 1179 function initReplyHover(unit) {
1174 // https://stackoverflow.com/questions/60154233/event-when-typesetting-is-done-mathjax-3 1180 // https://stackoverflow.com/questions/60154233/event-when-typesetting-is-done-mathjax-3

yatex.org