Fossil SCM

Fixed a preview quirk which caused the pikchr click handlers to not get processed on wikiedit/fileedit previews after the first one.

stephan 2020-09-18 09:21 trunk
Commit 052d37480927b6010c8a33549254fe0f2113ff7dc9e44498c6237e0c058150d9
+1 -1
--- src/fileedit.c
+++ src/fileedit.c
@@ -1747,11 +1747,11 @@
17471747
/* ^^^ fossil.page[methodName]() OR text source elem ID,
17481748
** but we need a method in order to support clients swapping out
17491749
** the text editor with their own. */
17501750
"data-f-preview-via='_postPreview' "
17511751
/* ^^^ fossil.page[methodName](content, callback) */
1752
- "data-f-preview-to='#fileedit-tab-preview-wrapper' "
1752
+ "data-f-preview-to='_previewTo' "
17531753
/* ^^^ dest elem ID */
17541754
">Refresh</button>");
17551755
/* Toggle auto-update of preview when the Preview tab is selected. */
17561756
CX("<div class='input-with-label'>"
17571757
"<input type='checkbox' value='1' "
17581758
--- 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
--- src/fossil.dom.js
+++ src/fossil.dom.js
@@ -805,11 +805,12 @@
805805
any method-name data properties, e.g. data-f-preview-via and
806806
potentially data-f-preview-from/to, must be a single method name,
807807
not a property-access-style string. e.g. "myPreview" is legal but
808808
"foo.myPreview" is not (unless, of course, the method is actually
809809
named "foo.myPreview" (which is legal but would be
810
- unconventional)).
810
+ unconventional)). All such methods are called with
811
+ methodNamespace as their "this".
811812
812813
An example...
813814
814815
First an input button:
815816
@@ -868,13 +869,13 @@
868869
? document.querySelector(e.dataset.fPreviewFrom)
869870
: methodNamespace[e.dataset.fPreviewFrom],
870871
asText = +(e.dataset.fPreviewAsText || 0);
871872
eTo.textContent = "Fetching preview...";
872873
methodNamespace[e.dataset.fPreviewVia](
873
- (eFrom instanceof Function ? eFrom() : eFrom.value),
874
+ (eFrom instanceof Function ? eFrom.call(methodNamespace) : eFrom.value),
874875
function(r){
875
- if(eTo instanceof Function) eTo(r||'');
876
+ if(eTo instanceof Function) eTo.call(methodNamespace, r||'');
876877
else if(!r){
877878
dom.clearElement(eTo);
878879
}else if(asText){
879880
eTo.textContent = r;
880881
}else{
881882
--- 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
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -1141,21 +1141,29 @@
11411141
11421142
Returns this object, noting that the operation is async.
11431143
*/
11441144
P.preview = function f(switchToTab){
11451145
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);
11511148
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
+ });
11551150
};
11561151
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
+
11571165
/**
11581166
Callback for use with F.connectPagePreviewers()
11591167
*/
11601168
P._postPreview = function(content,callback){
11611169
if(!affirmHasFile()) return this;
11621170
--- 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
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -1342,21 +1342,29 @@
13421342
13431343
Returns this object, noting that the operation is async.
13441344
*/
13451345
P.preview = function f(switchToTab){
13461346
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);
13521349
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
+ });
13561351
};
13571352
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
+
13581366
/**
13591367
Callback for use with F.connectPagePreviewers()
13601368
*/
13611369
P._postPreview = function(content,callback){
13621370
if(!affirmPageLoaded()) return this;
13631371
--- 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 @@
12211221
/* ^^^ fossil.page[methodName]() OR text source elem ID,
12221222
** but we need a method in order to support clients swapping out
12231223
** the text editor with their own. */
12241224
"data-f-preview-via='_postPreview' "
12251225
/* ^^^ 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]*/
12281228
">Refresh</button>");
12291229
/* Toggle auto-update of preview when the Preview tab is selected. */
12301230
CX("<div class='input-with-label'>"
12311231
"<input type='checkbox' value='1' "
12321232
"id='cb-preview-autorefresh' checked>"
12331233
--- 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

Keyboard Shortcuts

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