Fossil SCM

Minor hyperlink generation tweak in support of pending additional auto-link/auto-style features.

stephan 2020-12-22 08:25 chatroom-dev
Commit ee6c70817d2f1bce5756cd552d1e11611d2c9af7967198b37cab47c872271903
1 file changed +13 -9
+13 -9
--- tools/chat.tcl
+++ tools/chat.tcl
@@ -138,11 +138,11 @@
138138
// ^^^ achtung, extra backslashes needed for the outer TCL.
139139
f.ce = (T)=>document.createElement(T);
140140
f.ct = (T)=>document.createTextNode(T);
141141
f.replaceUrls = function ff(sub, off, whole){
142142
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)+' ');
144144
}
145145
const a = f.ce('a');
146146
a.setAttribute('href',sub);
147147
a.setAttribute('target','_blank');
148148
a.appendChild(f.ct(sub));
@@ -149,25 +149,29 @@
149149
f.accum.push(a);
150150
ff.prevStart = off + sub.length + 1;
151151
return sub;
152152
};
153153
}
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
156156
f.replaceUrls.prevStart = 0;
157157
str.replace(f.rxUrl, f.replaceUrls);
158158
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));
160160
}
161161
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
+ });
163167
delete f.accum;
164168
// 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;
169173
};
170174
function newcontent(jx){
171175
var tab = document.getElementById("dialog");
172176
var i;
173177
for(i=0; i<jx.msgs.length; ++i){
174178
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button