File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -31,11 +31,18 @@ function onPageLoad() {
31
31
32
32
parsePageUrl ( ) ;
33
33
34
- view . setOnPdfFileChosenListener ( async function ( pdfFile : File ) {
34
+ view . setOnPdfFileChosenListener (
35
+ ( ) => true ,
36
+ async function ( pdfFile : File ) {
37
+ await loadPdfFromFile ( pdfFile ) ;
38
+ }
39
+ ) ;
40
+
41
+ async function loadPdfFromFile ( pdfFile : File ) {
35
42
await readFileAsArrayBuffer ( pdfFile ) . then ( function ( fileData : ArrayBuffer ) {
36
43
loadPdf ( pdfFile . name , fileData ) ;
37
44
} ) ;
38
- } ) ;
45
+ }
39
46
40
47
function readFileAsArrayBuffer ( file : File ) : Promise < ArrayBuffer > {
41
48
return new Promise ( ( resolve , reject ) => {
@@ -155,6 +162,21 @@ function onPageLoad() {
155
162
156
163
view . enableNavButtons ( ) ;
157
164
165
+ view . setOnPdfFileChosenListener (
166
+ function ( ) {
167
+ const overlays : Overlays = extractOverlays ( ) ;
168
+ return (
169
+ overlays . pagesOverlays . size == 0 ||
170
+ confirm (
171
+ "If you load another PDF, all changes in the current PDF will be lost. Are you sure?"
172
+ )
173
+ ) ;
174
+ } ,
175
+ async function ( pdfFile : File ) {
176
+ await loadPdfFromFile ( pdfFile ) ;
177
+ }
178
+ ) ;
179
+
158
180
view . setOnNextClickedListener ( function ( ) {
159
181
if ( currentPage + 1 <= pdfDocument . getPageCount ( ) ) {
160
182
gotoPage ( currentPage + 1 ) ;
Original file line number Diff line number Diff line change @@ -300,13 +300,17 @@ export class View {
300
300
}
301
301
302
302
public setOnPdfFileChosenListener (
303
+ canChoosePdfPrecheck : ( ) => boolean ,
303
304
onPdfFileChosen : ( pdfFile : File ) => Promise < void >
304
305
) {
305
306
const pdfInput = document . getElementById (
306
307
"pdf-file-input"
307
308
) as HTMLInputElement ;
308
- pdfInput . onclick = function ( ) {
309
+ pdfInput . onclick = function ( e : Event ) {
309
310
pdfInput . value = "" ;
311
+ if ( ! canChoosePdfPrecheck ( ) ) {
312
+ e . preventDefault ( ) ;
313
+ }
310
314
} ;
311
315
pdfInput . onchange = async function ( ev : Event ) {
312
316
const input = ev . target as HTMLInputElement ;
You can’t perform that action at this time.
0 commit comments