Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Milestone: eliminated the remaining assign-to-DOMElement.innerHTML in the fossil.*.js APIs (ostensible security enhancement), thanks to the DOMParser interface. Fixed an obscure minor bug in /fileedit where a commit message which contained HTML tags could cause the page to misbehave if the 'response manifest' debugging option was turned on. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
79023c9273e2536d1aacae7734ea7996 |
| User & Date: | stephan 2020-09-12 12:21:11.823 |
Context
|
2020-09-12
| ||
| 19:28 | Re-imported pikchr's example scripts using the output from its new example-to-js converter. ... (check-in: 4d946271f7 user: stephan tags: trunk) | |
| 12:21 | Milestone: eliminated the remaining assign-to-DOMElement.innerHTML in the fossil.*.js APIs (ostensible security enhancement), thanks to the DOMParser interface. Fixed an obscure minor bug in /fileedit where a commit message which contained HTML tags could cause the page to misbehave if the 'response manifest' debugging option was turned on. ... (check-in: 79023c9273 user: stephan tags: trunk) | |
| 09:47 | Minor improvements in fossil.dom and touchups in code which can make use of them. Found a way around using innerHTML assignment for rendering pikchr content. (TODO: genericize that and apply it to wikiedit/fileedit previews.) ... (check-in: 74791f8873 user: stephan tags: trunk) | |
Changes
Changes to src/default.css.
| ︙ | ︙ | |||
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 |
white-space: nowrap;
}
.input-with-label > * {
vertical-align: middle;
}
.input-with-label > label {
display: inline; /* some skins set label display to block! */
}
.input-with-label > input {
margin: 0;
}
.input-with-label > button {
margin: 0;
}
| > | 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 |
white-space: nowrap;
}
.input-with-label > * {
vertical-align: middle;
}
.input-with-label > label {
display: inline; /* some skins set label display to block! */
cursor: pointer;
}
.input-with-label > input {
margin: 0;
}
.input-with-label > button {
margin: 0;
}
|
| ︙ | ︙ |
Changes to src/fossil.bootstrap.js.
| ︙ | ︙ | |||
197 198 199 200 201 202 203 204 |
const n = ('number'===typeof forUrl)
? forUrl : F.config[forUrl ? 'hashDigitsUrl' : 'hashDigits'];
return ('string'==typeof hash ? hash.substr(
0, n
) : hash);
};
/**
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
const n = ('number'===typeof forUrl)
? forUrl : F.config[forUrl ? 'hashDigitsUrl' : 'hashDigits'];
return ('string'==typeof hash ? hash.substr(
0, n
) : hash);
};
/**
Convenience wrapper which adds an onload event listener to the
window object. Returns this.
*/
F.onPageLoad = function(callback){
window.addEventListener('load', callback, false);
return this;
};
/**
Convenience wrapper which adds a DOMContentLoadedevent listener
to the window object. Returns this.
*/
F.onDOMContentLoaded = function(callback){
window.addEventListener('DOMContentLoaded', callback, false);
return this;
|
| ︙ | ︙ |
Changes to src/fossil.confirmer.js.
| ︙ | ︙ | |||
116 117 118 119 120 121 122 | - Add an invert option which activates if the timeout is reached and "times out" if the element is clicked again. e.g. a button which says "Saving..." and cancels the op if it's clicked again, else it saves after X time/ticks. - Internally we save/restore the initial text of non-INPUT elements | > | | | 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | - Add an invert option which activates if the timeout is reached and "times out" if the element is clicked again. e.g. a button which says "Saving..." and cancels the op if it's clicked again, else it saves after X time/ticks. - Internally we save/restore the initial text of non-INPUT elements using a relatively expensive bit of DOMParser hoop-jumping. We "should" instead move their child nodes aside (into an internal out-of-DOM element) and restore them as needed. Terse Change history: - 20200811 - Added pinSize option. - 20200507: |
| ︙ | ︙ | |||
154 155 156 157 158 159 160 |
this.target = target;
this.opt = opt;
this.timerID = undefined;
this.state = this.states.initial;
const isInput = f.isInput(target);
const updateText = function(msg){
if(isInput) target.value = msg;
| > > > > > | > > | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
this.target = target;
this.opt = opt;
this.timerID = undefined;
this.state = this.states.initial;
const isInput = f.isInput(target);
const updateText = function(msg){
if(isInput) target.value = msg;
else{
/* Jump through some hoops to avoid assigning to innerHTML... */
const newNode = new DOMParser().parseFromString(msg, 'text/html');
let childs = newNode.documentElement.querySelector('body');
childs = childs ? Array.prototype.slice.call(childs.childNodes, 0) : [];
target.innerText = '';
childs.forEach((e)=>target.appendChild(e));
}
}
const formatCountdown = (txt, number) => txt + " ["+number+"]";
if(opt.pinSize && opt.confirmText){
/* Try to pin the element's width the the greater of its
current width or its waiting-on-confirmation width
to avoid layout reflow when it's activated. */
const digits = (''+(opt.timeout/1000 || opt.ticks)).length;
|
| ︙ | ︙ |
Changes to src/fossil.dom.js.
| ︙ | ︙ | |||
418 419 420 421 422 423 424 |
false.
*/
dom.hasClass = function(e,c){
return (e && e.classList) ? e.classList.contains(c) : false;
};
/**
| | | | | > > < < < | < | 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
false.
*/
dom.hasClass = function(e,c){
return (e && e.classList) ? e.classList.contains(c) : false;
};
/**
Each argument after the first may be a single DOM element or a
container of them with a forEach() method. All such elements are
appended, in the given order, to the dest element using
dom.append(dest,theElement). Thus the 2nd and susequent arguments
may be any type supported as the 2nd argument to that function.
Returns dest.
*/
dom.moveTo = function(dest,e){
const n = arguments.length;
var i = 1;
const self = this;
for( ; i < n; ++i ){
e = arguments[i];
this.append(dest, e);
}
return dest;
};
/**
Each argument after the first may be a single DOM element
or a container of them with a forEach() method. For each
DOM element argument, all children of that DOM element
|
| ︙ | ︙ | |||
695 696 697 698 699 700 701 702 703 |
for(k in style){
if(style.hasOwnProperty(k)) e.style[k] = style[k];
}
}
return e;
};
return F.dom = dom;
})(window.fossil);
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 |
for(k in style){
if(style.hasOwnProperty(k)) e.style[k] = style[k];
}
}
return e;
};
/**
Parses a string as HTML.
Usages:
(htmlString)
(DOMElement target, htmlString)
The first form parses the string as HTML and returns an Array of
all elements parsed from it. If string is falsy then it returns
an empty array.
The second form parses the HTML string and appends all elements
to the given target element using dom.append(), then returns the
first argument.
Caveats:
- It expects a partial HTML document as input, not a full HTML
document with a HEAD and BODY tags. Because of how DOMParser
works, only children of the parsed document's (virtual) body are
acknowledged by this routine.
*/
dom.parseHtml = function(){
let childs, string, tgt;
if(1===arguments.length){
string = arguments[0];
}else if(2==arguments.length){
tgt = arguments[0];
string = arguments[1];
}
if(string){
const newNode = new DOMParser().parseFromString(string, 'text/html');
childs = newNode.documentElement.querySelector('body');
childs = childs ? Array.prototype.slice.call(childs.childNodes, 0) : [];
/* ^^^ we need a clone of the list because reparenting them
modifies a NodeList they're in. */
}else{
childs = [];
}
return tgt ? this.moveTo(tgt, childs) : childs;
};
/**
Sets up pseudo-automatic content preview handling between a
source element (typically a TEXTAREA) and a target rendering
element (typically a DIV). The selector argument must be one of:
- A single DOM element
- A collection of DOM elements with a forEach method.
- A CSS selector
Each element in the collection must have the following data
attributes:
- data-f-preview-from: is either a DOM element id, WITH a leading
'#' prefix, or the name of a method (see below). If it's an ID,
the DOM element must support .value to get the content.
- data-f-preview-to: the DOM element id of the target "previewer"
element, WITH a leading '#', or the name of a method (see below).
- data-f-preview-via: the name of a method (see below).
- OPTIONAL data-f-preview-as-text: a numeric value. Explained below.
Each element gets a click handler added to it which does the
following:
1) Reads the content from its data-f-preview-from element or, if
that property refers to a method, calls the method without
arguments and uses its result as the content.
2) Passes the content to
methodNamespace[f-data-post-via](content,callback). f-data-post-via
is responsible for submitting the preview HTTP request, including
any parameters the request might require. When the response
arrives, it must pass the content of the response to its 2nd
argument, an auto-generated callback installed by this mechanism
which...
3) Assigns the response text to the data-f-preview-to element or
passes it to the function
methodNamespace[f-data-preview-to](content), as appropriate. If
data-f-preview-to is a DOM element and data-f-preview-as-text is
'0' (the default) then the target elements contents are replaced
with the given content as HTML, else the content is assigned to
the target's textContent property. (Note that this routine uses
DOMParser, rather than assignment to innerHTML, to apply
HTML-format content.)
The methodNamespace (2nd argument) defaults to fossil.page, and
any method-name data properties, e.g. data-f-preview-via and
potentially data-f-preview-from/to, must be a single method name,
not a property-access-style string. e.g. "myPreview" is legal but
"foo.myPreview" is not (unless, of course, the method is actually
named "foo.myPreview" (which is legal but would be
unconventional)).
An example...
First an input button:
<button id='test-preview-connector'
data-f-preview-from='#fileedit-content-editor' // elem ID or method name
data-f-preview-via='myPreview' // method name
data-f-preview-to='#fileedit-tab-preview-wrapper' // elem ID or method name
>Preview update</button>
And a sample data-f-preview-via method:
fossil.page.myPreview = function(content,callback){
const fd = new FormData();
fd.append('foo', ...);
fossil.fetch('preview_forumpost',{
payload: fd,
onload: callback,
onerror: (e)=>{ // only if app-specific handling is needed
fossil.fetch.onerror(e); // default impl
... any app-specific error reporting ...
}
});
};
Then connect the parts with:
fossil.connectPagePreviewers('#test-preview-connector');
Note that the data-f-preview-from, data-f-preview-via, and
data-f-preview-to selector are not resolved until the button is
actually clicked, so they need not exist in the DOM at the
instant when the connection is set up, so long as they can be
resolved when the preview-refreshing element is clicked.
Maintenance reminder: this method is not strictly part of
fossil.dom, but is in its file because it needs access to
dom.parseHtml() to avoid an innerHTML assignment and all code
which uses this routine also needs fossil.dom.
*/
F.connectPagePreviewers = function f(selector,methodNamespace){
if('string'===typeof selector){
selector = document.querySelectorAll(selector);
}else if(!selector.forEach){
selector = [selector];
}
if(!methodNamespace){
methodNamespace = F.page;
}
selector.forEach(function(e){
e.addEventListener(
'click', function(r){
const eTo = '#'===e.dataset.fPreviewTo[0]
? document.querySelector(e.dataset.fPreviewTo)
: methodNamespace[e.dataset.fPreviewTo],
eFrom = '#'===e.dataset.fPreviewFrom[0]
? document.querySelector(e.dataset.fPreviewFrom)
: methodNamespace[e.dataset.fPreviewFrom],
asText = +(e.dataset.fPreviewAsText || 0);
eTo.textContent = "Fetching preview...";
methodNamespace[e.dataset.fPreviewVia](
(eFrom instanceof Function ? eFrom() : eFrom.value),
function(r){
if(eTo instanceof Function) eTo(r||'');
else if(!r){
dom.clearElement(eTo);
}else if(asText){
eTo.textContent = r;
}else{
dom.parseHtml(dom.clearElement(eTo), r);
}
}
);
}, false
);
});
return this;
}/*F.connectPagePreviewers()*/;
return F.dom = dom;
})(window.fossil);
|
Changes to src/fossil.page.fileedit.js.
| ︙ | ︙ | |||
1114 1115 1116 1117 1118 1119 1120 |
*/
P.preview = function f(switchToTab){
if(!affirmHasFile()) return this;
const target = this.e.previewTarget,
self = this;
const updateView = function(c){
D.clearElement(target);
| | | 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 |
*/
P.preview = function f(switchToTab){
if(!affirmHasFile()) return this;
const target = this.e.previewTarget,
self = this;
const updateView = function(c){
D.clearElement(target);
if('string'===typeof c) D.parseHtml(target,c);
if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview);
};
return this._postPreview(this.fileContent(), updateView);
};
/**
Callback for use with F.connectPagePreviewers()
|
| ︙ | ︙ | |||
1202 1203 1204 1205 1206 1207 1208 |
fd.append('content',content);
if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
F.message(
"Fetching diff..."
).fetch('fileedit/diff',{
payload: fd,
onload: function(c){
| | | | 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
fd.append('content',content);
if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
F.message(
"Fetching diff..."
).fetch('fileedit/diff',{
payload: fd,
onload: function(c){
D.parseHtml(D.clearElement(target),[
"<div>Diff <code>[",
self.finfo.checkin,
"]</code> → Local Edits</div>",
c||'No changes.'
].join(''));
if(sbs) P.tweakSbsDiffs2();
F.message('Updated diff.');
self.tabs.switchToTab(self.e.tabs.diff);
}
});
return this;
};
|
| ︙ | ︙ | |||
1234 1235 1236 1237 1238 1239 1240 |
cbDryRun = E('[name=dry_run]'),
isDryRun = cbDryRun.checked,
filename = this.finfo.filename;
if(!f.onload){
f.onload = function(c){
const oldFinfo = JSON.parse(JSON.stringify(self.finfo))
if(c.manifest){
| | | | > > > | | 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 |
cbDryRun = E('[name=dry_run]'),
isDryRun = cbDryRun.checked,
filename = this.finfo.filename;
if(!f.onload){
f.onload = function(c){
const oldFinfo = JSON.parse(JSON.stringify(self.finfo))
if(c.manifest){
D.parseHtml(D.clearElement(target), [
"<h3>Manifest",
(c.dryRun?" (dry run)":""),
": ", F.hashDigits(c.checkin),"</h3>",
"<pre><code class='fileedit-manifest'>",
c.manifest.replace(/</g,'<'),
/* ^^^ replace() necessary or this breaks if the manifest
comment contains an unclosed HTML tags,
e.g. <script> */
"</code></pre>"
].join(''));
delete c.manifest/*so we don't stash this with finfo*/;
}
const msg = [
'Committed',
c.dryRun ? '(dry run)' : '',
'[', F.hashDigits(c.checkin) ,'].'
];
|
| ︙ | ︙ |
Changes to src/fossil.page.pikchrshow.js.
| ︙ | ︙ | |||
254 255 256 257 258 259 260 |
P.e.markupAlignWrapper.classList[showIt ? 'remove' : 'add']('hidden');
};
f.getMarkupAlignmentClass = function(){
if(P.e.markupAlignCenter.checked) return ' center';
else if(P.e.markupAlignIndent.checked) return ' indent';
return '';
};
| < < < < < < < < < < < | | | 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
P.e.markupAlignWrapper.classList[showIt ? 'remove' : 'add']('hidden');
};
f.getMarkupAlignmentClass = function(){
if(P.e.markupAlignCenter.checked) return ' center';
else if(P.e.markupAlignIndent.checked) return ' indent';
return '';
};
}
const preTgt = this.e.previewTarget;
if(this.response.isError){
D.append(D.clearElement(preTgt), D.parseHtml(P.response.raw));
D.addClass(preTgt, 'error');
this.e.previewModeLabel.innerText = "Error";
return;
}
D.removeClass(preTgt, 'error');
D.removeClass(this.e.previewCopyButton, 'disabled');
D.removeClass(this.e.markupAlignWrapper, 'hidden');
D.enable(this.e.previewModeToggle, this.e.markupAlignRadios);
let label;
switch(this.previewMode){
case 0:
label = "SVG";
f.showMarkupAlignment(false);
D.append(D.clearElement(preTgt), D.parseHtml(P.response.raw));
this.e.taPreviewText.value =
this.response.raw.replace(f.rxNonce, '')/*for copy button*/;
break;
case 1:
label = "Markdown";
f.showMarkupAlignment(true);
this.e.taPreviewText.value = [
|
| ︙ | ︙ |
Changes to src/fossil.page.wikiedit-wysiwyg-legacy.js.
| ︙ | ︙ | |||
442 443 444 445 446 447 448 |
/* WYSIWYG -> Markup */
// Legacy did this: content=content.replace(setDocMode.linebreak,"</p>\n\n<p>")
D.append(D.clearElement(oDoc), content)
oDoc.style.whiteSpace = "pre-wrap";
D.addClass(setDocMode.toHide, 'hidden');
} else {
/* Markup -> WYSIWYG */
| | | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 |
/* WYSIWYG -> Markup */
// Legacy did this: content=content.replace(setDocMode.linebreak,"</p>\n\n<p>")
D.append(D.clearElement(oDoc), content)
oDoc.style.whiteSpace = "pre-wrap";
D.addClass(setDocMode.toHide, 'hidden');
} else {
/* Markup -> WYSIWYG */
D.parseHtml(D.clearElement(oDoc), content);
oDoc.style.whiteSpace = "normal";
D.removeClass(setDocMode.toHide, 'hidden');
}
oDoc.focus();
}
////////////////////////////////////////////////////////////////////////
|
| ︙ | ︙ |
Changes to src/fossil.page.wikiedit.js.
| ︙ | ︙ | |||
1313 1314 1315 1316 1317 1318 1319 |
Returns this object, noting that the operation is async.
*/
P.preview = function f(switchToTab){
if(!affirmPageLoaded()) return this;
const target = this.e.previewTarget,
self = this;
| | | | 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 |
Returns this object, noting that the operation is async.
*/
P.preview = function f(switchToTab){
if(!affirmPageLoaded()) return this;
const target = this.e.previewTarget,
self = this;
const updateView = function(c,mimetype){
D.clearElement(target);
if('string'===typeof c) D.parseHtml(target,c);
if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview);
};
return this._postPreview(this.wikiContent(), updateView);
};
/**
Callback for use with F.connectPagePreviewers()
|
| ︙ | ︙ | |||
1396 1397 1398 1399 1400 1401 1402 |
fd.append('content',content);
if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
F.message(
"Fetching diff..."
).fetch('wikiajax/diff',{
payload: fd,
onload: function(c){
| | | | 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 |
fd.append('content',content);
if(this.e.selectDiffWS) fd.append('ws',this.e.selectDiffWS.value);
F.message(
"Fetching diff..."
).fetch('wikiajax/diff',{
payload: fd,
onload: function(c){
D.parseHtml(D.clearElement(target), [
"<div>Diff <code>[",
self.winfo.name,
"]</code> → Local Edits</div>",
c||'No changes.'
].join(''));
if(sbs) P.tweakSbsDiffs2();
F.message('Updated diff.');
self.tabs.switchToTab(self.e.tabs.diff);
}
});
return this;
};
|
| ︙ | ︙ |