Fossil SCM
Minor hyperlink generation tweak in support of pending additional auto-link/auto-style features.
Commit
ee6c70817d2f1bce5756cd552d1e11611d2c9af7967198b37cab47c872271903
Parent
f04dde73d4a60aa…
1 file changed
+13
-9
+13
-9
| --- tools/chat.tcl | ||
| +++ tools/chat.tcl | ||
| @@ -138,11 +138,11 @@ | ||
| 138 | 138 | // ^^^ achtung, extra backslashes needed for the outer TCL. |
| 139 | 139 | f.ce = (T)=>document.createElement(T); |
| 140 | 140 | f.ct = (T)=>document.createTextNode(T); |
| 141 | 141 | f.replaceUrls = function ff(sub, off, whole){ |
| 142 | 142 | if(off > ff.prevStart){ |
| 143 | - f.accum.push(f.ct((ff.prevStart?' ':'')+whole.substring(ff.prevStart, off-1)+' ')); | |
| 143 | + f.accum.push((ff.prevStart?' ':'')+whole.substring(ff.prevStart, off-1)+' '); | |
| 144 | 144 | } |
| 145 | 145 | const a = f.ce('a'); |
| 146 | 146 | a.setAttribute('href',sub); |
| 147 | 147 | a.setAttribute('target','_blank'); |
| 148 | 148 | a.appendChild(f.ct(sub)); |
| @@ -149,25 +149,29 @@ | ||
| 149 | 149 | f.accum.push(a); |
| 150 | 150 | ff.prevStart = off + sub.length + 1; |
| 151 | 151 | return sub; |
| 152 | 152 | }; |
| 153 | 153 | } |
| 154 | - f.accum = []; | |
| 155 | - f.rxUrl.lastIndex = 0; | |
| 154 | + f.accum = []; // accumulate strings and DOM elements here. | |
| 155 | + f.rxUrl.lastIndex = 0; // reset regex cursor | |
| 156 | 156 | f.replaceUrls.prevStart = 0; |
| 157 | 157 | str.replace(f.rxUrl, f.replaceUrls); |
| 158 | 158 | if(f.replaceUrls.prevStart < str.length){ |
| 159 | - f.accum.push(f.ct((f.replaceUrls.prevStart?' ':'')+str.substring(f.replaceUrls.prevStart))); | |
| 159 | + f.accum.push((f.replaceUrls.prevStart?' ':'')+str.substring(f.replaceUrls.prevStart)); | |
| 160 | 160 | } |
| 161 | 161 | const span = f.ce('span'); |
| 162 | - f.accum.forEach((e)=>span.appendChild(e)); | |
| 162 | + f.accum.forEach(function(e){ | |
| 163 | + // append accumulated strings/DOM elements to target element | |
| 164 | + if('string'===typeof e) e = f.ct(e); | |
| 165 | + span.appendChild(e); | |
| 166 | + }); | |
| 163 | 167 | delete f.accum; |
| 164 | 168 | // TODO: replace @WORD refs with <span class='at-me'>@WORD</span>, but |
| 165 | - // only when WORD==current user name. The above dissection into chunks | |
| 166 | - // complicates that somewhat, requiring a separate pass over the remaining | |
| 167 | - // TEXT nodes and a separate array to accumulate the results to. | |
| 168 | - return span; | |
| 169 | + // only when WORD==current user name. That requires a separate pass | |
| 170 | + // over the remaining STRING entries and a separate array to accumulate | |
| 171 | + // the results to. | |
| 172 | + return span; | |
| 169 | 173 | }; |
| 170 | 174 | function newcontent(jx){ |
| 171 | 175 | var tab = document.getElementById("dialog"); |
| 172 | 176 | var i; |
| 173 | 177 | for(i=0; i<jx.msgs.length; ++i){ |
| 174 | 178 |
| --- tools/chat.tcl | |
| +++ tools/chat.tcl | |
| @@ -138,11 +138,11 @@ | |
| 138 | // ^^^ achtung, extra backslashes needed for the outer TCL. |
| 139 | f.ce = (T)=>document.createElement(T); |
| 140 | f.ct = (T)=>document.createTextNode(T); |
| 141 | f.replaceUrls = function ff(sub, off, whole){ |
| 142 | if(off > ff.prevStart){ |
| 143 | f.accum.push(f.ct((ff.prevStart?' ':'')+whole.substring(ff.prevStart, off-1)+' ')); |
| 144 | } |
| 145 | const a = f.ce('a'); |
| 146 | a.setAttribute('href',sub); |
| 147 | a.setAttribute('target','_blank'); |
| 148 | a.appendChild(f.ct(sub)); |
| @@ -149,25 +149,29 @@ | |
| 149 | f.accum.push(a); |
| 150 | ff.prevStart = off + sub.length + 1; |
| 151 | return sub; |
| 152 | }; |
| 153 | } |
| 154 | f.accum = []; |
| 155 | f.rxUrl.lastIndex = 0; |
| 156 | f.replaceUrls.prevStart = 0; |
| 157 | str.replace(f.rxUrl, f.replaceUrls); |
| 158 | if(f.replaceUrls.prevStart < str.length){ |
| 159 | f.accum.push(f.ct((f.replaceUrls.prevStart?' ':'')+str.substring(f.replaceUrls.prevStart))); |
| 160 | } |
| 161 | const span = f.ce('span'); |
| 162 | f.accum.forEach((e)=>span.appendChild(e)); |
| 163 | delete f.accum; |
| 164 | // TODO: replace @WORD refs with <span class='at-me'>@WORD</span>, but |
| 165 | // only when WORD==current user name. The above dissection into chunks |
| 166 | // complicates that somewhat, requiring a separate pass over the remaining |
| 167 | // TEXT nodes and a separate array to accumulate the results to. |
| 168 | return span; |
| 169 | }; |
| 170 | function newcontent(jx){ |
| 171 | var tab = document.getElementById("dialog"); |
| 172 | var i; |
| 173 | for(i=0; i<jx.msgs.length; ++i){ |
| 174 |
| --- tools/chat.tcl | |
| +++ tools/chat.tcl | |
| @@ -138,11 +138,11 @@ | |
| 138 | // ^^^ achtung, extra backslashes needed for the outer TCL. |
| 139 | f.ce = (T)=>document.createElement(T); |
| 140 | f.ct = (T)=>document.createTextNode(T); |
| 141 | f.replaceUrls = function ff(sub, off, whole){ |
| 142 | if(off > ff.prevStart){ |
| 143 | f.accum.push((ff.prevStart?' ':'')+whole.substring(ff.prevStart, off-1)+' '); |
| 144 | } |
| 145 | const a = f.ce('a'); |
| 146 | a.setAttribute('href',sub); |
| 147 | a.setAttribute('target','_blank'); |
| 148 | a.appendChild(f.ct(sub)); |
| @@ -149,25 +149,29 @@ | |
| 149 | f.accum.push(a); |
| 150 | ff.prevStart = off + sub.length + 1; |
| 151 | return sub; |
| 152 | }; |
| 153 | } |
| 154 | f.accum = []; // accumulate strings and DOM elements here. |
| 155 | f.rxUrl.lastIndex = 0; // reset regex cursor |
| 156 | f.replaceUrls.prevStart = 0; |
| 157 | str.replace(f.rxUrl, f.replaceUrls); |
| 158 | if(f.replaceUrls.prevStart < str.length){ |
| 159 | f.accum.push((f.replaceUrls.prevStart?' ':'')+str.substring(f.replaceUrls.prevStart)); |
| 160 | } |
| 161 | const span = f.ce('span'); |
| 162 | f.accum.forEach(function(e){ |
| 163 | // append accumulated strings/DOM elements to target element |
| 164 | if('string'===typeof e) e = f.ct(e); |
| 165 | span.appendChild(e); |
| 166 | }); |
| 167 | delete f.accum; |
| 168 | // TODO: replace @WORD refs with <span class='at-me'>@WORD</span>, but |
| 169 | // only when WORD==current user name. That requires a separate pass |
| 170 | // over the remaining STRING entries and a separate array to accumulate |
| 171 | // the results to. |
| 172 | return span; |
| 173 | }; |
| 174 | function newcontent(jx){ |
| 175 | var tab = document.getElementById("dialog"); |
| 176 | var i; |
| 177 | for(i=0; i<jx.msgs.length; ++i){ |
| 178 |