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 37
37
"minimatch" : " 9.0.0" ,
38
38
"monaco-editor" : " 0.38.0" ,
39
39
"monaco-editor-webpack-plugin" : " 7.0.1" ,
40
+ "pdfobject" : " 2.2.11" ,
40
41
"pretty-ms" : " 8.0.0" ,
41
42
"sortablejs" : " 1.15.0" ,
42
43
"swagger-ui-dist" : " 4.18.3" ,
Original file line number Diff line number Diff line change 19
19
{{else if .IsPlainText}}
20
20
<pre>{{if .FileContent}}{{.FileContent | Safe}}{{end}}</pre>
21
21
{{else if not .IsTextFile}}
22
- <div class="view-raw ui center">
22
+ <div class="view-raw ui center{{if .IsPDFFile}} gt-p-0{{end}} ">
23
23
{{if .IsImageFile}}
24
24
<img src="{{$.RawFileLink}}">
25
25
{{else if .IsVideoFile}}
31
31
<strong>{{.locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
32
32
</audio>
33
33
{{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 >
35
35
{{else}}
36
36
<a href="{{$.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.locale.Tr "repo.file_view_raw"}}</a>
37
37
{{end}}
Original file line number Diff line number Diff line change 73
73
{{else if .IsPlainText}}
74
74
<pre>{{if .FileContent}}{{.FileContent | Safe}}{{end}}</pre>
75
75
{{else if not .IsTextSource}}
76
- <div class="view-raw ui center">
76
+ <div class="view-raw ui center{{if .IsPDFFile}} gt-p-0{{end}} ">
77
77
{{if .IsImageFile}}
78
78
<img src="{{$.RawFileLink}}">
79
79
{{else if .IsVideoFile}}
85
85
<strong>{{.locale.Tr "repo.audio_not_supported_in_browser"}}</strong>
86
86
</audio>
87
87
{{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 >
89
89
{{else}}
90
90
<a href="{{$.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.locale.Tr "repo.file_view_raw"}}</a>
91
91
{{end}}
Original file line number Diff line number Diff line change 29
29
}
30
30
31
31
.markup pre .is-loading ,
32
- .editor-loading .is-loading {
32
+ .editor-loading .is-loading ,
33
+ .pdf-content .is-loading {
33
34
height : var (--height-loading );
34
35
}
35
36
Original file line number Diff line number Diff line change 413
413
max-width : 600px !important ;
414
414
}
415
415
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
+
416
429
.repository .file .list .non-diff-file-content .plain-text {
417
430
padding : 1em 2em ;
418
431
}
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {initRepoIssueContentHistory} from './features/repo-issue-content.js';
21
21
import { initStopwatch } from './features/stopwatch.js' ;
22
22
import { initFindFileInRepo } from './features/repo-findfile.js' ;
23
23
import { initCommentContent , initMarkupContent } from './markup/content.js' ;
24
+ import { initPdfViewer } from './render/pdf.js' ;
24
25
25
26
import { initUserAuthLinkAccountView , initUserAuthOauth2 } from './features/user-auth.js' ;
26
27
import {
@@ -177,4 +178,5 @@ onDomReady(() => {
177
178
initUserAuthWebAuthnRegister ( ) ;
178
179
initUserSettings ( ) ;
179
180
initRepoDiffView ( ) ;
181
+ initPdfViewer ( ) ;
180
182
} ) ;
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