Fossil SCM

Expanded the fileedit-preview-updated event data to include the mimetype and preview mode so that listeners can make a better-informed decision about how/whether to handle the content.

stephan 2020-05-14 04:46 fileedit-ajaxify
Commit e988ed904a140613633b441ceedfed0a54bec7207f128a6dea53552de804609c
1 file changed +34 -3
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -22,12 +22,39 @@
2222
in place of the built-in textarea, but that is as yet untested.
2323
In order to do so the client would need to replace DOM element
2424
#fileedit-content-editor with their custom widget.
2525
2626
- Event 'fileedit-preview-updated': when the preview is refreshed
27
- from the server, this event passes on the DOM element which
28
- contains the content preview.
27
+ from the server, this event passes on information about the preview
28
+ change in the form of an object:
29
+
30
+ {
31
+ element: the DOM element which contains the content preview.
32
+
33
+ mimetype: the fossil-reported content mimetype.
34
+
35
+ previewMode: a string describing the preview mode: see
36
+ the fossil.page.previewModes map for the values. This can
37
+ be used to determine whether, e.g., the content is suitable
38
+ for applying a 3rd-party code highlighting API to.
39
+ }
40
+
41
+ Here's an example which can be used with the highlightjs code
42
+ highlighter to update the highlighting when the preview is
43
+ refreshed in "wiki" mode (which includes fossil-native wiki and
44
+ markdown):
45
+
46
+ fossil.page.addEventListener(
47
+ 'fileedit-preview-updated',
48
+ (ev)=>{
49
+ if(ev.detail.previewMode==='wiki'){
50
+ ev.detail.element.querySelectorAll(
51
+ 'code[class^=language-]'
52
+ ).forEach((e)=>hljs.highlightBlock(e));
53
+ }
54
+ }
55
+ );
2956
*/
3057
const E = (s)=>document.querySelector(s),
3158
D = F.dom,
3259
P = F.page;
3360
@@ -577,11 +604,15 @@
577604
P.selectPreviewMode(P.previewModes[header]);
578605
if('wiki'===header) P.baseHrefForFile();
579606
else P.baseHrefRestore();
580607
callback(r);
581608
F.message('Updated preview.');
582
- P.dispatchEvent('fileedit-preview-updated',P.e.previewTarget);
609
+ P.dispatchEvent('fileedit-preview-updated',{
610
+ previewMode: P.previewModes.current,
611
+ mimetype: P.finfo.mimetype,
612
+ element: P.e.previewTarget
613
+ });
583614
},
584615
onerror: (e)=>{
585616
fossil.fetch.onerror(e);
586617
callback("Error fetching preview: "+e);
587618
}
588619
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -22,12 +22,39 @@
22 in place of the built-in textarea, but that is as yet untested.
23 In order to do so the client would need to replace DOM element
24 #fileedit-content-editor with their custom widget.
25
26 - Event 'fileedit-preview-updated': when the preview is refreshed
27 from the server, this event passes on the DOM element which
28 contains the content preview.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29 */
30 const E = (s)=>document.querySelector(s),
31 D = F.dom,
32 P = F.page;
33
@@ -577,11 +604,15 @@
577 P.selectPreviewMode(P.previewModes[header]);
578 if('wiki'===header) P.baseHrefForFile();
579 else P.baseHrefRestore();
580 callback(r);
581 F.message('Updated preview.');
582 P.dispatchEvent('fileedit-preview-updated',P.e.previewTarget);
 
 
 
 
583 },
584 onerror: (e)=>{
585 fossil.fetch.onerror(e);
586 callback("Error fetching preview: "+e);
587 }
588
--- src/fossil.page.fileedit.js
+++ src/fossil.page.fileedit.js
@@ -22,12 +22,39 @@
22 in place of the built-in textarea, but that is as yet untested.
23 In order to do so the client would need to replace DOM element
24 #fileedit-content-editor with their custom widget.
25
26 - Event 'fileedit-preview-updated': when the preview is refreshed
27 from the server, this event passes on information about the preview
28 change in the form of an object:
29
30 {
31 element: the DOM element which contains the content preview.
32
33 mimetype: the fossil-reported content mimetype.
34
35 previewMode: a string describing the preview mode: see
36 the fossil.page.previewModes map for the values. This can
37 be used to determine whether, e.g., the content is suitable
38 for applying a 3rd-party code highlighting API to.
39 }
40
41 Here's an example which can be used with the highlightjs code
42 highlighter to update the highlighting when the preview is
43 refreshed in "wiki" mode (which includes fossil-native wiki and
44 markdown):
45
46 fossil.page.addEventListener(
47 'fileedit-preview-updated',
48 (ev)=>{
49 if(ev.detail.previewMode==='wiki'){
50 ev.detail.element.querySelectorAll(
51 'code[class^=language-]'
52 ).forEach((e)=>hljs.highlightBlock(e));
53 }
54 }
55 );
56 */
57 const E = (s)=>document.querySelector(s),
58 D = F.dom,
59 P = F.page;
60
@@ -577,11 +604,15 @@
604 P.selectPreviewMode(P.previewModes[header]);
605 if('wiki'===header) P.baseHrefForFile();
606 else P.baseHrefRestore();
607 callback(r);
608 F.message('Updated preview.');
609 P.dispatchEvent('fileedit-preview-updated',{
610 previewMode: P.previewModes.current,
611 mimetype: P.finfo.mimetype,
612 element: P.e.previewTarget
613 });
614 },
615 onerror: (e)=>{
616 fossil.fetch.onerror(e);
617 callback("Error fetching preview: "+e);
618 }
619

Keyboard Shortcuts

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