s4
changeset 1000:ddf85e80f64e
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 | 1fd61bbd69f8 |
children | bbd5a0c50d5b |
files | s4-main.js |
diffstat | 1 files changed, 24 insertions(+), 18 deletions(-) [+] |
line diff
1.1 --- a/s4-main.js Sat Nov 26 09:55:45 2022 +0859 1.2 +++ b/s4-main.js Sun Dec 04 09:56:36 2022 +0859 1.3 @@ -15,7 +15,8 @@ 1.4 //alert("mypath="+mypath); 1.5 } 1.6 function escapeChars(old) { 1.7 - return old.replaceAll('"', '"') 1.8 + return old.replaceAll('&', '&') 1.9 + .replaceAll('"', '"') 1.10 .replaceAll("<", '<') 1.11 .replaceAll(">", '>'); 1.12 } 1.13 @@ -1147,26 +1148,31 @@ 1.14 } 1.15 unit = unit||document; 1.16 for (let td of unit.querySelectorAll("td.repl")) { 1.17 - let text = td.innerHTML; 1.18 - if (text.startsWith("\>#")) { 1.19 - let newline = text.indexOf("\n"); 1.20 - let first, rest; 1.21 + let firstC = td.firstChild; 1.22 + // Direct replacing innerHTML breaks embedded DOM event handlers. 1.23 + // So, we split td.repl into elements and replace the first 1.24 + // textNode(nodeType==3) with hover-text embeded content. 1.25 + if (firstC.nodeType==3 && firstC.nodeValue.startsWith(">#")) { 1.26 + let newline = firstC.nodeValue.indexOf("\n"); 1.27 + let firstline; 1.28 if (newline > 0) { 1.29 - first = text.substring(0, newline); 1.30 - rest = text.substring(newline); 1.31 + firstline = firstC.nodeValue.substring(0, 1+newline); 1.32 + firstC.nodeValue = firstC.nodeValue.substring(1+newline); 1.33 } else { 1.34 - first = text; 1.35 - rest = ""; 1.36 + // Cannot be reached here, but leave this for robustness 1.37 + firstline = firstC.nodeValue; 1.38 + firstC.nodeValue = ""; 1.39 } 1.40 - td.innerHTML = first.replace( 1.41 - /#([0-9]+)/g, 1.42 - (match, start, whole) => { 1.43 - let id = RegExp.$1 1.44 - return '<a title="' + getTextById(id) 1.45 - + '" href="' + match 1.46 - + '">' + match + '</a>'; 1.47 - } 1.48 - ) + rest; 1.49 + td.insertAdjacentHTML( 1.50 + 'afterbegin', 1.51 + escapeChars(firstline).replace( 1.52 + /#([0-9]+)/g, 1.53 + (match, start, whole) => { 1.54 + let id = RegExp.$1 1.55 + return '<a title="' + getTextById(id) 1.56 + + '" href="' + match 1.57 + + '">' + match + '</a>'; 1.58 + })); 1.59 } 1.60 } 1.61 }