Fossil SCM
Added fileedit-preview-updated event, for use in hooking up 3rd-party syntax highlighting to the preview. (Tested locally with highlightjs.)
Commit
8e293f959ab5c0fcee97734eb83c64dd38acb4cec308b52b6f93d957cc4ec283
Parent
4619c9a772bb23e…
1 file changed
+11
-10
+11
-10
| --- src/fossil.page.fileedit.js | ||
| +++ src/fossil.page.fileedit.js | ||
| @@ -4,12 +4,12 @@ | ||
| 4 | 4 | Code for the /filepage app. Requires that the fossil JS |
| 5 | 5 | bootstrapping is complete and fossil.fetch() has been installed. |
| 6 | 6 | |
| 7 | 7 | Custom events, handled via fossil.page.addEventListener(): |
| 8 | 8 | |
| 9 | - - 'fileedit-file-loaded': passes on information when it loads a | |
| 10 | - file, in the form of an object: | |
| 9 | + - Event 'fileedit-file-loaded': passes on information when it | |
| 10 | + loads a file, in the form of an object: | |
| 11 | 11 | |
| 12 | 12 | { |
| 13 | 13 | filename: string, |
| 14 | 14 | checkin: UUID string, |
| 15 | 15 | isExe: bool, |
| @@ -21,10 +21,13 @@ | ||
| 21 | 21 | skin-level JS in order to use a custom 3rd-party editing widget |
| 22 | 22 | in place of the built-in textarea, but that is as yet untested. |
| 23 | 23 | In order to do so the client would need to replace DOM element |
| 24 | 24 | #fileedit-content-editor with their custom widget. |
| 25 | 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. | |
| 26 | 29 | */ |
| 27 | 30 | const E = (s)=>document.querySelector(s), |
| 28 | 31 | D = F.dom, |
| 29 | 32 | P = F.page; |
| 30 | 33 | |
| @@ -212,10 +215,11 @@ | ||
| 212 | 215 | selectPreviewMode: E('#select-preview-mode select'), |
| 213 | 216 | selectHtmlEmsWrap: E('#select-preview-html-ems'), |
| 214 | 217 | selectEolWrap: E('#select-preview-html-ems'), |
| 215 | 218 | cbLineNumbersWrap: E('#cb-line-numbers'), |
| 216 | 219 | cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'), |
| 220 | + previewTarget: E('#fileedit-tab-preview-wrapper'), | |
| 217 | 221 | cbIsExe: E('input[type=checkbox][name=exec_bit]'), |
| 218 | 222 | fsFileVersionDetails: E('#file-version-details'), |
| 219 | 223 | tabs:{ |
| 220 | 224 | content: E('#fileedit-tab-content'), |
| 221 | 225 | preview: E('#fileedit-tab-preview'), |
| @@ -536,19 +540,15 @@ | ||
| 536 | 540 | |
| 537 | 541 | Returns this object, noting that the operation is async. |
| 538 | 542 | */ |
| 539 | 543 | P.preview = function f(switchToTab){ |
| 540 | 544 | if(!affirmHasFile()) return this; |
| 541 | - if(!f.target){ | |
| 542 | - f.target = this.e.tabs.preview.querySelector( | |
| 543 | - '#fileedit-tab-preview-wrapper' | |
| 544 | - ); | |
| 545 | - } | |
| 546 | - const self = this; | |
| 545 | + const target = this.e.previewTarget, | |
| 546 | + self = this; | |
| 547 | 547 | const updateView = function(c){ |
| 548 | - D.clearElement(f.target); | |
| 549 | - if('string'===typeof c) f.target.innerHTML = c; | |
| 548 | + D.clearElement(target); | |
| 549 | + if('string'===typeof c) target.innerHTML = c; | |
| 550 | 550 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 551 | 551 | }; |
| 552 | 552 | return this._postPreview(this.value(), updateView); |
| 553 | 553 | }; |
| 554 | 554 | |
| @@ -577,10 +577,11 @@ | ||
| 577 | 577 | P.selectPreviewMode(P.previewModes[header]); |
| 578 | 578 | if('wiki'===header) P.baseHrefForFile(); |
| 579 | 579 | else P.baseHrefRestore(); |
| 580 | 580 | callback(r); |
| 581 | 581 | F.message('Updated preview.'); |
| 582 | + P.dispatchEvent('fileedit-preview-updated',P.e.previewTarget); | |
| 582 | 583 | }, |
| 583 | 584 | onerror: (e)=>{ |
| 584 | 585 | fossil.fetch.onerror(e); |
| 585 | 586 | callback("Error fetching preview: "+e); |
| 586 | 587 | } |
| 587 | 588 |
| --- src/fossil.page.fileedit.js | |
| +++ src/fossil.page.fileedit.js | |
| @@ -4,12 +4,12 @@ | |
| 4 | Code for the /filepage app. Requires that the fossil JS |
| 5 | bootstrapping is complete and fossil.fetch() has been installed. |
| 6 | |
| 7 | Custom events, handled via fossil.page.addEventListener(): |
| 8 | |
| 9 | - 'fileedit-file-loaded': passes on information when it loads a |
| 10 | file, in the form of an object: |
| 11 | |
| 12 | { |
| 13 | filename: string, |
| 14 | checkin: UUID string, |
| 15 | isExe: bool, |
| @@ -21,10 +21,13 @@ | |
| 21 | skin-level JS in order to use a custom 3rd-party editing widget |
| 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 | */ |
| 27 | const E = (s)=>document.querySelector(s), |
| 28 | D = F.dom, |
| 29 | P = F.page; |
| 30 | |
| @@ -212,10 +215,11 @@ | |
| 212 | selectPreviewMode: E('#select-preview-mode select'), |
| 213 | selectHtmlEmsWrap: E('#select-preview-html-ems'), |
| 214 | selectEolWrap: E('#select-preview-html-ems'), |
| 215 | cbLineNumbersWrap: E('#cb-line-numbers'), |
| 216 | cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'), |
| 217 | cbIsExe: E('input[type=checkbox][name=exec_bit]'), |
| 218 | fsFileVersionDetails: E('#file-version-details'), |
| 219 | tabs:{ |
| 220 | content: E('#fileedit-tab-content'), |
| 221 | preview: E('#fileedit-tab-preview'), |
| @@ -536,19 +540,15 @@ | |
| 536 | |
| 537 | Returns this object, noting that the operation is async. |
| 538 | */ |
| 539 | P.preview = function f(switchToTab){ |
| 540 | if(!affirmHasFile()) return this; |
| 541 | if(!f.target){ |
| 542 | f.target = this.e.tabs.preview.querySelector( |
| 543 | '#fileedit-tab-preview-wrapper' |
| 544 | ); |
| 545 | } |
| 546 | const self = this; |
| 547 | const updateView = function(c){ |
| 548 | D.clearElement(f.target); |
| 549 | if('string'===typeof c) f.target.innerHTML = c; |
| 550 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 551 | }; |
| 552 | return this._postPreview(this.value(), updateView); |
| 553 | }; |
| 554 | |
| @@ -577,10 +577,11 @@ | |
| 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 | }, |
| 583 | onerror: (e)=>{ |
| 584 | fossil.fetch.onerror(e); |
| 585 | callback("Error fetching preview: "+e); |
| 586 | } |
| 587 |
| --- src/fossil.page.fileedit.js | |
| +++ src/fossil.page.fileedit.js | |
| @@ -4,12 +4,12 @@ | |
| 4 | Code for the /filepage app. Requires that the fossil JS |
| 5 | bootstrapping is complete and fossil.fetch() has been installed. |
| 6 | |
| 7 | Custom events, handled via fossil.page.addEventListener(): |
| 8 | |
| 9 | - Event 'fileedit-file-loaded': passes on information when it |
| 10 | loads a file, in the form of an object: |
| 11 | |
| 12 | { |
| 13 | filename: string, |
| 14 | checkin: UUID string, |
| 15 | isExe: bool, |
| @@ -21,10 +21,13 @@ | |
| 21 | skin-level JS in order to use a custom 3rd-party editing widget |
| 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 | |
| @@ -212,10 +215,11 @@ | |
| 215 | selectPreviewMode: E('#select-preview-mode select'), |
| 216 | selectHtmlEmsWrap: E('#select-preview-html-ems'), |
| 217 | selectEolWrap: E('#select-preview-html-ems'), |
| 218 | cbLineNumbersWrap: E('#cb-line-numbers'), |
| 219 | cbAutoPreview: E('#cb-preview-autoupdate > input[type=checkbox]'), |
| 220 | previewTarget: E('#fileedit-tab-preview-wrapper'), |
| 221 | cbIsExe: E('input[type=checkbox][name=exec_bit]'), |
| 222 | fsFileVersionDetails: E('#file-version-details'), |
| 223 | tabs:{ |
| 224 | content: E('#fileedit-tab-content'), |
| 225 | preview: E('#fileedit-tab-preview'), |
| @@ -536,19 +540,15 @@ | |
| 540 | |
| 541 | Returns this object, noting that the operation is async. |
| 542 | */ |
| 543 | P.preview = function f(switchToTab){ |
| 544 | if(!affirmHasFile()) return this; |
| 545 | const target = this.e.previewTarget, |
| 546 | self = this; |
| 547 | const updateView = function(c){ |
| 548 | D.clearElement(target); |
| 549 | if('string'===typeof c) target.innerHTML = c; |
| 550 | if(switchToTab) self.tabs.switchToTab(self.e.tabs.preview); |
| 551 | }; |
| 552 | return this._postPreview(this.value(), updateView); |
| 553 | }; |
| 554 | |
| @@ -577,10 +577,11 @@ | |
| 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 |