File tree Expand file tree Collapse file tree 8 files changed +47
-5
lines changed Expand file tree Collapse file tree 8 files changed +47
-5
lines changed Original file line number Diff line number Diff line change 3737 "minimatch" : " 9.0.0" ,
3838 "monaco-editor" : " 0.38.0" ,
3939 "monaco-editor-webpack-plugin" : " 7.0.1" ,
40+ "pdfobject" : " 2.2.11" ,
4041 "pretty-ms" : " 8.0.0" ,
4142 "sortablejs" : " 1.15.0" ,
4243 "swagger-ui-dist" : " 4.18.3" ,
Original file line number Diff line number Diff line change 1919 {{else if .IsPlainText}}
2020 <pre>{{if .FileContent}}{{.FileContent | Safe}}{{end}}</pre>
2121 {{else if not .IsTextFile}}
22- <div class="view-raw ui center">
22+ <div class="view-raw ui center{{if .IsPDFFile}} gt-p-0{{end}} ">
2323 {{if .IsImageFile}}
2424 <img src="{{$.RawFileLink}}">
2525 {{else if .IsVideoFile}}
3131 <strong>{{.locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
3232 </audio>
3333 {{else if .IsPDFFile}}
34- <iframe width="100%" height="600px" src="{{AssetUrlPrefix}}/vendor/plugins/pdfjs/web/viewer.html?file={{$.RawFileLink }}"></iframe >
34+ <div class="pdf-content is-loading" data- src="{{$.RawFileLink}}" data-fallback-button-text="{{.locale.Tr "diff.view_file" }}"></div >
3535 {{else}}
3636 <a href="{{$.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.locale.Tr "repo.file_view_raw"}}</a>
3737 {{end}}
Original file line number Diff line number Diff line change 7373 {{else if .IsPlainText}}
7474 <pre>{{if .FileContent}}{{.FileContent | Safe}}{{end}}</pre>
7575 {{else if not .IsTextSource}}
76- <div class="view-raw ui center">
76+ <div class="view-raw ui center{{if .IsPDFFile}} gt-p-0{{end}} ">
7777 {{if .IsImageFile}}
7878 <img src="{{$.RawFileLink}}">
7979 {{else if .IsVideoFile}}
8585 <strong>{{.locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
8686 </audio>
8787 {{else if .IsPDFFile}}
88- <iframe width="100%" height="600px" src="{{AssetUrlPrefix}}/vendor/plugins/pdfjs/web/viewer.html?file={{$.RawFileLink }}"></iframe >
88+ <div class="pdf-content is-loading" data- src="{{$.RawFileLink}}" data-fallback-button-text="{{.locale.Tr "repo.diff.view_file" }}"></div >
8989 {{else}}
9090 <a href="{{$.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.locale.Tr "repo.file_view_raw"}}</a>
9191 {{end}}
Original file line number Diff line number Diff line change 2929}
3030
3131.markup pre .is-loading ,
32- .editor-loading .is-loading {
32+ .editor-loading .is-loading ,
33+ .pdf-content .is-loading {
3334 height : var (--height-loading );
3435}
3536
Original file line number Diff line number Diff line change 413413 max-width : 600px !important ;
414414}
415415
416+ .pdf-content {
417+ width : 100% ;
418+ height : 600px ;
419+ border : none !important ;
420+ display : flex;
421+ align-items : center;
422+ justify-content : center;
423+ }
424+
425+ .pdf-content : has (.pdf-fallback-button ) {
426+ height : 100px ;
427+ }
428+
416429.repository .file .list .non-diff-file-content .plain-text {
417430 padding : 1em 2em ;
418431}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {initRepoIssueContentHistory} from './features/repo-issue-content.js';
2121import { initStopwatch } from './features/stopwatch.js' ;
2222import { initFindFileInRepo } from './features/repo-findfile.js' ;
2323import { initCommentContent , initMarkupContent } from './markup/content.js' ;
24+ import { initPdfViewer } from './render/pdf.js' ;
2425
2526import { initUserAuthLinkAccountView , initUserAuthOauth2 } from './features/user-auth.js' ;
2627import {
@@ -177,4 +178,5 @@ onDomReady(() => {
177178 initUserAuthWebAuthnRegister ( ) ;
178179 initUserSettings ( ) ;
179180 initRepoDiffView ( ) ;
181+ initPdfViewer ( ) ;
180182} ) ;
Original file line number Diff line number Diff line change 1+ import { htmlEscape } from 'escape-goat' ;
2+
3+ export async function initPdfViewer ( ) {
4+ const els = document . querySelectorAll ( '.pdf-content' ) ;
5+ if ( ! els . length ) return ;
6+
7+ const pdfobject = await import ( /* webpackChunkName: "pdfobject" */ 'pdfobject' ) ;
8+
9+ for ( const el of els ) {
10+ const src = el . getAttribute ( 'data-src' ) ;
11+ const fallbackText = el . getAttribute ( 'data-fallback-button-text' ) ;
12+ pdfobject . embed ( src , el , {
13+ fallbackLink : htmlEscape `
14+ < a role ="button " class ="ui basic button pdf-fallback-button " href ="[url] "> ${ fallbackText } </ a >
15+ ` ,
16+ } ) ;
17+ el . classList . remove ( 'is-loading' ) ;
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments