@@ -685,8 +685,107 @@ const PDFViewerApplication = {
685685 }
686686 } ,
687687
688- run ( config ) {
689- this . initialize ( config ) . then ( webViewerInitialized ) ;
688+ async run ( config ) {
689+ await this . initialize ( config ) ;
690+
691+ const { appConfig, eventBus, l10n } = this ;
692+ let file ;
693+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
694+ const queryString = document . location . search . substring ( 1 ) ;
695+ const params = parseQueryString ( queryString ) ;
696+ file = params . get ( "file" ) ?? AppOptions . get ( "defaultUrl" ) ;
697+ validateFileURL ( file ) ;
698+ } else if ( PDFJSDev . test ( "MOZCENTRAL" ) ) {
699+ file = window . location . href ;
700+ } else if ( PDFJSDev . test ( "CHROME" ) ) {
701+ file = AppOptions . get ( "defaultUrl" ) ;
702+ }
703+
704+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
705+ const fileInput = appConfig . openFileInput ;
706+ fileInput . value = null ;
707+
708+ fileInput . addEventListener ( "change" , function ( evt ) {
709+ const { files } = evt . target ;
710+ if ( ! files || files . length === 0 ) {
711+ return ;
712+ }
713+ eventBus . dispatch ( "fileinputchange" , {
714+ source : this ,
715+ fileInput : evt . target ,
716+ } ) ;
717+ } ) ;
718+
719+ // Enable dragging-and-dropping a new PDF file onto the viewerContainer.
720+ appConfig . mainContainer . addEventListener ( "dragover" , function ( evt ) {
721+ evt . preventDefault ( ) ;
722+
723+ evt . dataTransfer . dropEffect =
724+ evt . dataTransfer . effectAllowed === "copy" ? "copy" : "move" ;
725+ } ) ;
726+ appConfig . mainContainer . addEventListener ( "drop" , function ( evt ) {
727+ evt . preventDefault ( ) ;
728+
729+ const { files } = evt . dataTransfer ;
730+ if ( ! files || files . length === 0 ) {
731+ return ;
732+ }
733+ eventBus . dispatch ( "fileinputchange" , {
734+ source : this ,
735+ fileInput : evt . dataTransfer ,
736+ } ) ;
737+ } ) ;
738+ }
739+
740+ if ( ! this . supportsDocumentFonts ) {
741+ AppOptions . set ( "disableFontFace" , true ) ;
742+ l10n . get ( "web_fonts_disabled" ) . then ( msg => {
743+ console . warn ( msg ) ;
744+ } ) ;
745+ }
746+
747+ if ( ! this . supportsPrinting ) {
748+ appConfig . toolbar ?. print ?. classList . add ( "hidden" ) ;
749+ appConfig . secondaryToolbar ?. printButton . classList . add ( "hidden" ) ;
750+ }
751+
752+ if ( ! this . supportsFullscreen ) {
753+ appConfig . secondaryToolbar ?. presentationModeButton . classList . add (
754+ "hidden"
755+ ) ;
756+ }
757+
758+ if ( this . supportsIntegratedFind ) {
759+ appConfig . toolbar ?. viewFind ?. classList . add ( "hidden" ) ;
760+ }
761+
762+ appConfig . mainContainer . addEventListener (
763+ "transitionend" ,
764+ function ( evt ) {
765+ if ( evt . target === /* mainContainer */ this ) {
766+ eventBus . dispatch ( "resize" , { source : this } ) ;
767+ }
768+ } ,
769+ true
770+ ) ;
771+
772+ try {
773+ if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
774+ if ( file ) {
775+ this . open ( { url : file } ) ;
776+ } else {
777+ this . _hideViewBookmark ( ) ;
778+ }
779+ } else if ( PDFJSDev . test ( "MOZCENTRAL || CHROME" ) ) {
780+ this . initPassiveLoading ( file ) ;
781+ } else {
782+ throw new Error ( "Not implemented: run" ) ;
783+ }
784+ } catch ( reason ) {
785+ l10n . get ( "loading_error" ) . then ( msg => {
786+ this . _documentError ( msg , reason ) ;
787+ } ) ;
788+ }
690789 } ,
691790
692791 get initialized ( ) {
@@ -2199,105 +2298,6 @@ function reportPageStatsPDFBug({ pageNumber }) {
21992298 globalThis . Stats . add ( pageNumber , pageView ?. pdfPage ?. stats ) ;
22002299}
22012300
2202- function webViewerInitialized ( ) {
2203- const { appConfig, eventBus, l10n } = PDFViewerApplication ;
2204- let file ;
2205- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2206- const queryString = document . location . search . substring ( 1 ) ;
2207- const params = parseQueryString ( queryString ) ;
2208- file = params . get ( "file" ) ?? AppOptions . get ( "defaultUrl" ) ;
2209- validateFileURL ( file ) ;
2210- } else if ( PDFJSDev . test ( "MOZCENTRAL" ) ) {
2211- file = window . location . href ;
2212- } else if ( PDFJSDev . test ( "CHROME" ) ) {
2213- file = AppOptions . get ( "defaultUrl" ) ;
2214- }
2215-
2216- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2217- const fileInput = appConfig . openFileInput ;
2218- fileInput . value = null ;
2219-
2220- fileInput . addEventListener ( "change" , function ( evt ) {
2221- const { files } = evt . target ;
2222- if ( ! files || files . length === 0 ) {
2223- return ;
2224- }
2225- eventBus . dispatch ( "fileinputchange" , {
2226- source : this ,
2227- fileInput : evt . target ,
2228- } ) ;
2229- } ) ;
2230-
2231- // Enable dragging-and-dropping a new PDF file onto the viewerContainer.
2232- appConfig . mainContainer . addEventListener ( "dragover" , function ( evt ) {
2233- evt . preventDefault ( ) ;
2234-
2235- evt . dataTransfer . dropEffect =
2236- evt . dataTransfer . effectAllowed === "copy" ? "copy" : "move" ;
2237- } ) ;
2238- appConfig . mainContainer . addEventListener ( "drop" , function ( evt ) {
2239- evt . preventDefault ( ) ;
2240-
2241- const { files } = evt . dataTransfer ;
2242- if ( ! files || files . length === 0 ) {
2243- return ;
2244- }
2245- eventBus . dispatch ( "fileinputchange" , {
2246- source : this ,
2247- fileInput : evt . dataTransfer ,
2248- } ) ;
2249- } ) ;
2250- }
2251-
2252- if ( ! PDFViewerApplication . supportsDocumentFonts ) {
2253- AppOptions . set ( "disableFontFace" , true ) ;
2254- l10n . get ( "web_fonts_disabled" ) . then ( msg => {
2255- console . warn ( msg ) ;
2256- } ) ;
2257- }
2258-
2259- if ( ! PDFViewerApplication . supportsPrinting ) {
2260- appConfig . toolbar ?. print ?. classList . add ( "hidden" ) ;
2261- appConfig . secondaryToolbar ?. printButton . classList . add ( "hidden" ) ;
2262- }
2263-
2264- if ( ! PDFViewerApplication . supportsFullscreen ) {
2265- appConfig . secondaryToolbar ?. presentationModeButton . classList . add ( "hidden" ) ;
2266- }
2267-
2268- if ( PDFViewerApplication . supportsIntegratedFind ) {
2269- appConfig . toolbar ?. viewFind ?. classList . add ( "hidden" ) ;
2270- }
2271-
2272- appConfig . mainContainer . addEventListener (
2273- "transitionend" ,
2274- function ( evt ) {
2275- if ( evt . target === /* mainContainer */ this ) {
2276- eventBus . dispatch ( "resize" , { source : this } ) ;
2277- }
2278- } ,
2279- true
2280- ) ;
2281-
2282- try {
2283- if ( typeof PDFJSDev === "undefined" || PDFJSDev . test ( "GENERIC" ) ) {
2284- if ( file ) {
2285- PDFViewerApplication . open ( { url : file } ) ;
2286- } else {
2287- PDFViewerApplication . _hideViewBookmark ( ) ;
2288- }
2289- } else if ( PDFJSDev . test ( "MOZCENTRAL || CHROME" ) ) {
2290- PDFViewerApplication . initPassiveLoading ( file ) ;
2291- } else {
2292- throw new Error ( "Not implemented: webViewerInitialized" ) ;
2293- }
2294- } catch ( reason ) {
2295- l10n . get ( "loading_error" ) . then ( msg => {
2296- PDFViewerApplication . _documentError ( msg , reason ) ;
2297- } ) ;
2298- }
2299- }
2300-
23012301function webViewerPageRender ( { pageNumber } ) {
23022302 // If the page is (the most) visible when it starts rendering,
23032303 // ensure that the page number input loading indicator is displayed.
0 commit comments