Fossil SCM
Fixed a preview quirk which caused the pikchr click handlers to not get processed on wikiedit/fileedit previews after the first one.
Commit
052d37480927b6010c8a33549254fe0f2113ff7dc9e44498c6237e0c058150d9
Parent
539eb61f85bcc6f…
5 files changed
+1
-1
+4
-3
+16
-8
+16
-8
+2
-2
+1
-1
| --- src/fileedit.c | ||
| +++ src/fileedit.c | ||
| @@ -1747,11 +1747,11 @@ | ||
| 1747 | 1747 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1748 | 1748 | ** but we need a method in order to support clients swapping out |
| 1749 | 1749 | ** the text editor with their own. */ |
| 1750 | 1750 | "data-f-preview-via='_postPreview' " |
| 1751 | 1751 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1752 | - "data-f-preview-to='#fileedit-tab-preview-wrapper' " | |
| 1752 | + "data-f-preview-to='_previewTo' " | |
| 1753 | 1753 | /* ^^^ dest elem ID */ |
| 1754 | 1754 | ">Refresh</button>"); |
| 1755 | 1755 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1756 | 1756 | CX("<div class='input-with-label'>" |
| 1757 | 1757 | "<input type='checkbox' value='1' " |
| 1758 | 1758 |
| --- src/fileedit.c | |
| +++ src/fileedit.c | |
| @@ -1747,11 +1747,11 @@ | |
| 1747 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1748 | ** but we need a method in order to support clients swapping out |
| 1749 | ** the text editor with their own. */ |
| 1750 | "data-f-preview-via='_postPreview' " |
| 1751 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1752 | "data-f-preview-to='#fileedit-tab-preview-wrapper' " |
| 1753 | /* ^^^ dest elem ID */ |
| 1754 | ">Refresh</button>"); |
| 1755 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1756 | CX("<div class='input-with-label'>" |
| 1757 | "<input type='checkbox' value='1' " |
| 1758 |
| --- src/fileedit.c | |
| +++ src/fileedit.c | |
| @@ -1747,11 +1747,11 @@ | |
| 1747 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1748 | ** but we need a method in order to support clients swapping out |
| 1749 | ** the text editor with their own. */ |
| 1750 | "data-f-preview-via='_postPreview' " |
| 1751 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1752 | "data-f-preview-to='_previewTo' " |
| 1753 | /* ^^^ dest elem ID */ |
| 1754 | ">Refresh</button>"); |
| 1755 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1756 | CX("<div class='input-with-label'>" |
| 1757 | "<input type='checkbox' value='1' " |
| 1758 |
+4
-3
| --- src/fossil.dom.js | ||
| +++ src/fossil.dom.js | ||
| @@ -805,11 +805,12 @@ | ||
| 805 | 805 | any method-name data properties, e.g. data-f-preview-via and |
| 806 | 806 | potentially data-f-preview-from/to, must be a single method name, |
| 807 | 807 | not a property-access-style string. e.g. "myPreview" is legal but |
| 808 | 808 | "foo.myPreview" is not (unless, of course, the method is actually |
| 809 | 809 | named "foo.myPreview" (which is legal but would be |
| 810 | - unconventional)). | |
| 810 | + unconventional)). All such methods are called with | |
| 811 | + methodNamespace as their "this". | |
| 811 | 812 | |
| 812 | 813 | An example... |
| 813 | 814 | |
| 814 | 815 | First an input button: |
| 815 | 816 | |
| @@ -868,13 +869,13 @@ | ||
| 868 | 869 | ? document.querySelector(e.dataset.fPreviewFrom) |
| 869 | 870 | : methodNamespace[e.dataset.fPreviewFrom], |
| 870 | 871 | asText = +(e.dataset.fPreviewAsText || 0); |
| 871 | 872 | eTo.textContent = "Fetching preview..."; |
| 872 | 873 | methodNamespace[e.dataset.fPreviewVia]( |
| 873 | - (eFrom instanceof Function ? eFrom() : eFrom.value), | |
| 874 | + (eFrom instanceof Function ? eFrom.call(methodNamespace) : eFrom.value), | |
| 874 | 875 | function(r){ |
| 875 | - if(eTo instanceof Function) eTo(r||''); | |
| 876 | + if(eTo instanceof Function) eTo.call(methodNamespace, r||''); | |
| 876 | 877 | else if(!r){ |
| 877 | 878 | dom.clearElement(eTo); |
| 878 | 879 | }else if(asText){ |
| 879 | 880 | eTo.textContent = r; |
| 880 | 881 | }else{ |
| 881 | 882 |
| --- src/fossil.dom.js | |
| +++ src/fossil.dom.js | |
| @@ -805,11 +805,12 @@ | |
| 805 | any method-name data properties, e.g. data-f-preview-via and |
| 806 | potentially data-f-preview-from/to, must be a single method name, |
| 807 | not a property-access-style string. e.g. "myPreview" is legal but |
| 808 | "foo.myPreview" is not (unless, of course, the method is actually |
| 809 | named "foo.myPreview" (which is legal but would be |
| 810 | unconventional)). |
| 811 | |
| 812 | An example... |
| 813 | |
| 814 | First an input button: |
| 815 | |
| @@ -868,13 +869,13 @@ | |
| 868 | ? document.querySelector(e.dataset.fPreviewFrom) |
| 869 | : methodNamespace[e.dataset.fPreviewFrom], |
| 870 | asText = +(e.dataset.fPreviewAsText || 0); |
| 871 | eTo.textContent = "Fetching preview..."; |
| 872 | methodNamespace[e.dataset.fPreviewVia]( |
| 873 | (eFrom instanceof Function ? eFrom() : eFrom.value), |
| 874 | function(r){ |
| 875 | if(eTo instanceof Function) eTo(r||''); |
| 876 | else if(!r){ |
| 877 | dom.clearElement(eTo); |
| 878 | }else if(asText){ |
| 879 | eTo.textContent = r; |
| 880 | }else{ |
| 881 |
| --- src/fossil.dom.js | |
| +++ src/fossil.dom.js | |
| @@ -805,11 +805,12 @@ | |
| 805 | any method-name data properties, e.g. data-f-preview-via and |
| 806 | potentially data-f-preview-from/to, must be a single method name, |
| 807 | not a property-access-style string. e.g. "myPreview" is legal but |
| 808 | "foo.myPreview" is not (unless, of course, the method is actually |
| 809 | named "foo.myPreview" (which is legal but would be |
| 810 | unconventional)). All such methods are called with |
| 811 | methodNamespace as their "this". |
| 812 | |
| 813 | An example... |
| 814 | |
| 815 | First an input button: |
| 816 | |
| @@ -868,13 +869,13 @@ | |
| 869 | ? document.querySelector(e.dataset.fPreviewFrom) |
| 870 | : methodNamespace[e.dataset.fPreviewFrom], |
| 871 | asText = +(e.dataset.fPreviewAsText || 0); |
| 872 | eTo.textContent = "Fetching preview..."; |
| 873 | methodNamespace[e.dataset.fPreviewVia]( |
| 874 | (eFrom instanceof Function ? eFrom.call(methodNamespace) : eFrom.value), |
| 875 | function(r){ |
| 876 | if(eTo instanceof Function) eTo.call(methodNamespace, r||''); |
| 877 | else if(!r){ |
| 878 | dom.clearElement(eTo); |
| 879 | }else if(asText){ |
| 880 | eTo.textContent = r; |
| 881 | }else{ |
| 882 |
+16
-8
| --- src/fossil.page.fileedit.js | ||
| +++ src/fossil.page.fileedit.js | ||
| @@ -1141,21 +1141,29 @@ | ||
| 1141 | 1141 | |
| 1142 | 1142 | Returns this object, noting that the operation is async. |
| 1143 | 1143 | */ |
| 1144 | 1144 | P.preview = function f(switchToTab){ |
| 1145 | 1145 | if(!affirmHasFile()) return this; |
| 1146 | - const target = this.e.previewTarget, | |
| 1147 | - self = this; | |
| 1148 | - const updateView = function(c){ | |
| 1149 | - D.clearElement(target); | |
| 1150 | - if('string'===typeof c) D.parseHtml(target,c); | |
| 1146 | + return this._postPreview(this.fileContent(), function(c){ | |
| 1147 | + P._previewTo(c); | |
| 1151 | 1148 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1152 | - if(F.pikchr) F.pikchr.addSrcView(); | |
| 1153 | - }; | |
| 1154 | - return this._postPreview(this.fileContent(), updateView); | |
| 1149 | + }); | |
| 1155 | 1150 | }; |
| 1156 | 1151 | |
| 1152 | + /** | |
| 1153 | + Callback for use with F.connectPagePreviewers(). Gets passed | |
| 1154 | + the preview content. | |
| 1155 | + */ | |
| 1156 | + P._previewTo = function(c){ | |
| 1157 | + const target = this.e.previewTarget; | |
| 1158 | + D.clearElement(target); | |
| 1159 | + if('string'===typeof c) D.parseHtml(target,c); | |
| 1160 | + if(F.pikchr){ | |
| 1161 | + F.pikchr.addSrcView(target.querySelectorAll('svg.pikchr')); | |
| 1162 | + } | |
| 1163 | + }; | |
| 1164 | + | |
| 1157 | 1165 | /** |
| 1158 | 1166 | Callback for use with F.connectPagePreviewers() |
| 1159 | 1167 | */ |
| 1160 | 1168 | P._postPreview = function(content,callback){ |
| 1161 | 1169 | if(!affirmHasFile()) return this; |
| 1162 | 1170 |
| --- src/fossil.page.fileedit.js | |
| +++ src/fossil.page.fileedit.js | |
| @@ -1141,21 +1141,29 @@ | |
| 1141 | |
| 1142 | Returns this object, noting that the operation is async. |
| 1143 | */ |
| 1144 | P.preview = function f(switchToTab){ |
| 1145 | if(!affirmHasFile()) return this; |
| 1146 | const target = this.e.previewTarget, |
| 1147 | self = this; |
| 1148 | const updateView = function(c){ |
| 1149 | D.clearElement(target); |
| 1150 | if('string'===typeof c) D.parseHtml(target,c); |
| 1151 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1152 | if(F.pikchr) F.pikchr.addSrcView(); |
| 1153 | }; |
| 1154 | return this._postPreview(this.fileContent(), updateView); |
| 1155 | }; |
| 1156 | |
| 1157 | /** |
| 1158 | Callback for use with F.connectPagePreviewers() |
| 1159 | */ |
| 1160 | P._postPreview = function(content,callback){ |
| 1161 | if(!affirmHasFile()) return this; |
| 1162 |
| --- src/fossil.page.fileedit.js | |
| +++ src/fossil.page.fileedit.js | |
| @@ -1141,21 +1141,29 @@ | |
| 1141 | |
| 1142 | Returns this object, noting that the operation is async. |
| 1143 | */ |
| 1144 | P.preview = function f(switchToTab){ |
| 1145 | if(!affirmHasFile()) return this; |
| 1146 | return this._postPreview(this.fileContent(), function(c){ |
| 1147 | P._previewTo(c); |
| 1148 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1149 | }); |
| 1150 | }; |
| 1151 | |
| 1152 | /** |
| 1153 | Callback for use with F.connectPagePreviewers(). Gets passed |
| 1154 | the preview content. |
| 1155 | */ |
| 1156 | P._previewTo = function(c){ |
| 1157 | const target = this.e.previewTarget; |
| 1158 | D.clearElement(target); |
| 1159 | if('string'===typeof c) D.parseHtml(target,c); |
| 1160 | if(F.pikchr){ |
| 1161 | F.pikchr.addSrcView(target.querySelectorAll('svg.pikchr')); |
| 1162 | } |
| 1163 | }; |
| 1164 | |
| 1165 | /** |
| 1166 | Callback for use with F.connectPagePreviewers() |
| 1167 | */ |
| 1168 | P._postPreview = function(content,callback){ |
| 1169 | if(!affirmHasFile()) return this; |
| 1170 |
+16
-8
| --- src/fossil.page.wikiedit.js | ||
| +++ src/fossil.page.wikiedit.js | ||
| @@ -1342,21 +1342,29 @@ | ||
| 1342 | 1342 | |
| 1343 | 1343 | Returns this object, noting that the operation is async. |
| 1344 | 1344 | */ |
| 1345 | 1345 | P.preview = function f(switchToTab){ |
| 1346 | 1346 | if(!affirmPageLoaded()) return this; |
| 1347 | - const target = this.e.previewTarget, | |
| 1348 | - self = this; | |
| 1349 | - const updateView = function(c,mimetype){ | |
| 1350 | - D.clearElement(target); | |
| 1351 | - if('string'===typeof c) D.parseHtml(target,c); | |
| 1347 | + return this._postPreview(this.wikiContent(), function(c){ | |
| 1348 | + P._previewTo(c); | |
| 1352 | 1349 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1353 | - if(F.pikchr) F.pikchr.addSrcView(); | |
| 1354 | - }; | |
| 1355 | - return this._postPreview(this.wikiContent(), updateView); | |
| 1350 | + }); | |
| 1356 | 1351 | }; |
| 1357 | 1352 | |
| 1353 | + /** | |
| 1354 | + Callback for use with F.connectPagePreviewers(). Gets passed | |
| 1355 | + the preview content. | |
| 1356 | + */ | |
| 1357 | + P._previewTo = function(c){ | |
| 1358 | + const target = this.e.previewTarget; | |
| 1359 | + D.clearElement(target); | |
| 1360 | + if('string'===typeof c) D.parseHtml(target,c); | |
| 1361 | + if(F.pikchr){ | |
| 1362 | + F.pikchr.addSrcView(target.querySelectorAll('svg.pikchr')); | |
| 1363 | + } | |
| 1364 | + }; | |
| 1365 | + | |
| 1358 | 1366 | /** |
| 1359 | 1367 | Callback for use with F.connectPagePreviewers() |
| 1360 | 1368 | */ |
| 1361 | 1369 | P._postPreview = function(content,callback){ |
| 1362 | 1370 | if(!affirmPageLoaded()) return this; |
| 1363 | 1371 |
| --- src/fossil.page.wikiedit.js | |
| +++ src/fossil.page.wikiedit.js | |
| @@ -1342,21 +1342,29 @@ | |
| 1342 | |
| 1343 | Returns this object, noting that the operation is async. |
| 1344 | */ |
| 1345 | P.preview = function f(switchToTab){ |
| 1346 | if(!affirmPageLoaded()) return this; |
| 1347 | const target = this.e.previewTarget, |
| 1348 | self = this; |
| 1349 | const updateView = function(c,mimetype){ |
| 1350 | D.clearElement(target); |
| 1351 | if('string'===typeof c) D.parseHtml(target,c); |
| 1352 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1353 | if(F.pikchr) F.pikchr.addSrcView(); |
| 1354 | }; |
| 1355 | return this._postPreview(this.wikiContent(), updateView); |
| 1356 | }; |
| 1357 | |
| 1358 | /** |
| 1359 | Callback for use with F.connectPagePreviewers() |
| 1360 | */ |
| 1361 | P._postPreview = function(content,callback){ |
| 1362 | if(!affirmPageLoaded()) return this; |
| 1363 |
| --- src/fossil.page.wikiedit.js | |
| +++ src/fossil.page.wikiedit.js | |
| @@ -1342,21 +1342,29 @@ | |
| 1342 | |
| 1343 | Returns this object, noting that the operation is async. |
| 1344 | */ |
| 1345 | P.preview = function f(switchToTab){ |
| 1346 | if(!affirmPageLoaded()) return this; |
| 1347 | return this._postPreview(this.wikiContent(), function(c){ |
| 1348 | P._previewTo(c); |
| 1349 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 1350 | }); |
| 1351 | }; |
| 1352 | |
| 1353 | /** |
| 1354 | Callback for use with F.connectPagePreviewers(). Gets passed |
| 1355 | the preview content. |
| 1356 | */ |
| 1357 | P._previewTo = function(c){ |
| 1358 | const target = this.e.previewTarget; |
| 1359 | D.clearElement(target); |
| 1360 | if('string'===typeof c) D.parseHtml(target,c); |
| 1361 | if(F.pikchr){ |
| 1362 | F.pikchr.addSrcView(target.querySelectorAll('svg.pikchr')); |
| 1363 | } |
| 1364 | }; |
| 1365 | |
| 1366 | /** |
| 1367 | Callback for use with F.connectPagePreviewers() |
| 1368 | */ |
| 1369 | P._postPreview = function(content,callback){ |
| 1370 | if(!affirmPageLoaded()) return this; |
| 1371 |
+2
-2
| --- src/wiki.c | ||
| +++ src/wiki.c | ||
| @@ -1221,12 +1221,12 @@ | ||
| 1221 | 1221 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1222 | 1222 | ** but we need a method in order to support clients swapping out |
| 1223 | 1223 | ** the text editor with their own. */ |
| 1224 | 1224 | "data-f-preview-via='_postPreview' " |
| 1225 | 1225 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1226 | - "data-f-preview-to='#wikiedit-tab-preview-wrapper' " | |
| 1227 | - /* ^^^ dest elem ID */ | |
| 1226 | + "data-f-preview-to='_previewTo' " | |
| 1227 | + /* ^^^ dest elem ID or fossil.page[methodName]*/ | |
| 1228 | 1228 | ">Refresh</button>"); |
| 1229 | 1229 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1230 | 1230 | CX("<div class='input-with-label'>" |
| 1231 | 1231 | "<input type='checkbox' value='1' " |
| 1232 | 1232 | "id='cb-preview-autorefresh' checked>" |
| 1233 | 1233 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1221,12 +1221,12 @@ | |
| 1221 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1222 | ** but we need a method in order to support clients swapping out |
| 1223 | ** the text editor with their own. */ |
| 1224 | "data-f-preview-via='_postPreview' " |
| 1225 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1226 | "data-f-preview-to='#wikiedit-tab-preview-wrapper' " |
| 1227 | /* ^^^ dest elem ID */ |
| 1228 | ">Refresh</button>"); |
| 1229 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1230 | CX("<div class='input-with-label'>" |
| 1231 | "<input type='checkbox' value='1' " |
| 1232 | "id='cb-preview-autorefresh' checked>" |
| 1233 |
| --- src/wiki.c | |
| +++ src/wiki.c | |
| @@ -1221,12 +1221,12 @@ | |
| 1221 | /* ^^^ fossil.page[methodName]() OR text source elem ID, |
| 1222 | ** but we need a method in order to support clients swapping out |
| 1223 | ** the text editor with their own. */ |
| 1224 | "data-f-preview-via='_postPreview' " |
| 1225 | /* ^^^ fossil.page[methodName](content, callback) */ |
| 1226 | "data-f-preview-to='_previewTo' " |
| 1227 | /* ^^^ dest elem ID or fossil.page[methodName]*/ |
| 1228 | ">Refresh</button>"); |
| 1229 | /* Toggle auto-update of preview when the Preview tab is selected. */ |
| 1230 | CX("<div class='input-with-label'>" |
| 1231 | "<input type='checkbox' value='1' " |
| 1232 | "id='cb-preview-autorefresh' checked>" |
| 1233 |