comparison s4-main.js @ 972:8781f341d93a draft

Add referring text to hover title of ">#xxxx" marks.
author HIROSE Yuuji <yuuji@gentei.org>
date Sat, 28 May 2022 22:34:21 +0900
parents b327b5691b59
children 072362c47306
comparison
equal deleted inserted replaced
971:0ac251f04f21 972:8781f341d93a
1 // 愛 1 // 愛
2 (function (){ 2 (function (){
3 var isOlderJS; // Set in init(); 3 var isOlderJS; // Set in init();
4 var hoverTextLines = 10;
4 var hasTouchPad = 5 var hasTouchPad =
5 (navigator.maxTouchPoints && navigator.maxTouchPoints >0); 6 (navigator.maxTouchPoints && navigator.maxTouchPoints >0);
6 var myurl = document.URL, 7 var myurl = document.URL,
7 mypath = myurl.substring(myurl.lastIndexOf("/")); 8 mypath = myurl.substring(myurl.lastIndexOf("/"));
8 var art_m_list = []; 9 var art_m_list = [];
1030 ta.focus(); 1031 ta.focus();
1031 helpMarkdownPreview(ta); 1032 helpMarkdownPreview(ta);
1032 }); 1033 });
1033 ta.parentNode.appendChild(btn); 1034 ta.parentNode.appendChild(btn);
1034 } 1035 }
1036 function initReplyHover() {
1037 function getTextId(id) {
1038 console.log("Getting!::"+id);
1039 let txt = document.getElementById(id).innerText;
1040 return txt.split("\n").splice(0,hoverTextLines).join("\n");
1041 }
1042 for (let td of document.querySelectorAll("td.repl")) {
1043 let text = td.innerHTML;
1044 console.log(text);
1045 if (text.startsWith("\&gt;#")) {
1046 let newline = text.indexOf("\n");
1047 let first = text.substring(0, newline),
1048 rest = text.substring(newline);
1049 td.innerHTML = first.replace(
1050 /#([0-9]+)/g,
1051 (match, start, whole) => {
1052 let id = RegExp.$1
1053 return '<span title="' + getTextId(id) + '">'
1054 + match + '</span>';
1055 }
1056 ) + rest;
1057 }
1058 }
1059 }
1035 function init() { 1060 function init() {
1036 isOlderJS = !("insertAdjacentElement" in document.body); 1061 isOlderJS = !("insertAdjacentElement" in document.body);
1037 initGrpAction(); 1062 initGrpAction();
1038 initBlogs(); 1063 initBlogs();
1039 initFileInput(); 1064 initFileInput();
1040 initTextarea(); 1065 initTextarea();
1041 initGrphome(); 1066 initGrphome();
1042 initMath(); 1067 initMath();
1068 initReplyHover();
1043 } 1069 }
1044 document.addEventListener('DOMContentLoaded', init, null); 1070 document.addEventListener('DOMContentLoaded', init, null);
1045 })(); 1071 })();

yatex.org