File tree Expand file tree Collapse file tree 3 files changed +6
-8
lines changed Expand file tree Collapse file tree 3 files changed +6
-8
lines changed Original file line number Diff line number Diff line change 3131 <strong>{{ctx.Locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
3232 </audio>
3333 {{else if .IsPDFFile}}
34- <div class="pdf-content is-loading" data-src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "diff.view_file"}}"></div>
34+ <div class="pdf-content is-loading" data-global-init="initPdfViewer" data- src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "diff.view_file"}}"></div>
3535 {{else}}
3636 <a href="{{$.RawFileLink}}" rel="nofollow" class="tw-p-4">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
3737 {{end}}
Original file line number Diff line number Diff line change 108108 <strong>{{ctx.Locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
109109 </audio>
110110 {{else if .IsPDFFile}}
111- <div class="pdf-content is-loading" data-src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "repo.diff.view_file"}}"></div>
111+ <div class="pdf-content is-loading" data-global-init="initPdfViewer" data- src="{{$.RawFileLink}}" data-fallback-button-text="{{ctx.Locale.Tr "repo.diff.view_file"}}"></div>
112112 {{else}}
113113 <a href="{{$.RawFileLink}}" rel="nofollow" class="tw-p-4">{{ctx.Locale.Tr "repo.file_view_raw"}}</a>
114114 {{end}}
Original file line number Diff line number Diff line change 11import { htmlEscape } from 'escape-goat' ;
2+ import { registerGlobalInitFunc } from '../modules/observer.ts' ;
23
34export async function initPdfViewer ( ) {
4- const els = document . querySelectorAll ( '.pdf-content' ) ;
5- if ( ! els . length ) return ;
5+ registerGlobalInitFunc ( 'initPdfViewer' , async ( el : HTMLInputElement ) => {
6+ const pdfobject = await import ( /* webpackChunkName: "pdfobject" */ 'pdfobject' ) ;
67
7- const pdfobject = await import ( /* webpackChunkName: "pdfobject" */ 'pdfobject' ) ;
8-
9- for ( const el of els ) {
108 const src = el . getAttribute ( 'data-src' ) ;
119 const fallbackText = el . getAttribute ( 'data-fallback-button-text' ) ;
1210 pdfobject . embed ( src , el , {
@@ -15,5 +13,5 @@ export async function initPdfViewer() {
1513 ` ,
1614 } ) ;
1715 el . classList . remove ( 'is-loading' ) ;
18- }
16+ } ) ;
1917}
You can’t perform that action at this time.
0 commit comments