@@ -527,7 +527,7 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
527527 rotateView ( pdfViewer , 90 ) ;
528528 } ) ;
529529 EventHandler . on ( toolbar , "click" , ".bb-view-print" , async e => {
530- await printPdf ( el , options ) ;
530+ printPdf ( el , options ) ;
531531 await invoke . invokeMethodAsync ( "Printing" ) ;
532532 } )
533533 EventHandler . on ( toolbar , "click" , ".dropdown-item-pages" , async e => {
@@ -540,15 +540,15 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
540540 pdfViewer . spreadMode = 0 ;
541541 }
542542 } ) ;
543- EventHandler . on ( toolbar , "click" , ".bb-view-download" , async e => {
543+ EventHandler . on ( toolbar , "click" , ".bb-view-download" , e => {
544544 let fileName = el . getAttribute ( 'data-bb-download' ) ;
545545 if ( fileName === null ) {
546546 const docTitle = el . querySelector ( '.bb-view-subject' ) ;
547547 if ( docTitle ) {
548548 fileName = docTitle . textContent ;
549549 }
550550 }
551- await downloadPdf ( options , fileName ) ;
551+ downloadPdf ( options , fileName ) ;
552552 } ) ;
553553
554554 EventHandler . on ( toolbar , "click" , ".dropdown-item-presentation" , async e => {
@@ -562,6 +562,8 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
562562 //}
563563 } ) ;
564564 EventHandler . on ( toolbar , "click" , ".dropdown-item-doc" , e => {
565+ showBackdrop ( el ) ;
566+
565567 const dialog = el . querySelector ( ".bb-view-pdf-info" ) ;
566568 if ( dialog ) {
567569 dialog . classList . add ( "show" ) ;
@@ -574,25 +576,23 @@ const addToolbarEventHandlers = (el, pdfViewer, invoke, options) => {
574576 if ( dialog ) {
575577 dialog . classList . remove ( "show" ) ;
576578 }
579+
580+ hideBackdrop ( el ) ;
577581 } ) ;
578582}
579583
580- const downloadPdf = async ( options , fileName ) => {
584+ const downloadPdf = ( options , fileName ) => {
581585 if ( fileName === null ) {
582586 fileName = "download.pdf" ;
583587 }
584588
585- await getPdfUrl ( options , url => {
589+ getPdfUrl ( options , url => {
586590 const anchorElement = document . createElement ( 'a' ) ;
587591 anchorElement . href = url ;
588592 anchorElement . download = fileName ;
589593 document . body . appendChild ( anchorElement ) ;
590594 anchorElement . click ( ) ;
591595 document . body . removeChild ( anchorElement ) ;
592-
593- return new Promise ( ( resolve , reject ) => {
594- resolve ( ) ;
595- } ) ;
596596 } ) ;
597597}
598598
@@ -761,7 +761,7 @@ const makeThumb = async page => {
761761 return canvas ;
762762}
763763
764- const printPdf = async ( el , options ) => {
764+ const printPdf = ( el , options ) => {
765765 let iframe = el . querySelector ( ".bb-view-print-iframe" ) ;
766766 if ( iframe === null ) {
767767 iframe = document . createElement ( "iframe" ) ;
@@ -772,26 +772,37 @@ const printPdf = async (el, options) => {
772772 el . appendChild ( iframe ) ;
773773 }
774774
775- await getPdfUrl ( options , url => {
775+ getPdfUrl ( options , url => {
776776 iframe . src = url ;
777777 iframe . onload = ( ) => {
778778 iframe . contentWindow . focus ( ) ;
779779 iframe . contentWindow . print ( ) ;
780780 } ;
781- return new Promise ( ( resolve , reject ) => {
782- resolve ( ) ;
783- } ) ;
784781 } ) ;
785782}
786783
787- const getPdfUrl = async ( options , callback ) => {
784+ const showBackdrop = el => {
785+ const backdrop = el . querySelector ( '.bb-view-pdf-backdrop' ) ;
786+ if ( backdrop ) {
787+ backdrop . classList . add ( 'show' ) ;
788+ }
789+ }
790+
791+ const hideBackdrop = el => {
792+ const backdrop = el . querySelector ( '.bb-view-pdf-backdrop' ) ;
793+ if ( backdrop ) {
794+ backdrop . classList . remove ( 'show' ) ;
795+ }
796+ }
797+
798+ const getPdfUrl = ( options , callback ) => {
788799 if ( options . url ) {
789800 callback ( options . url ) ;
790801 }
791802 else if ( options . data ) {
792803 const blob = new Blob ( [ options . data ] , { type : 'application/pdf' } ) ;
793804 var url = window . URL . createObjectURL ( blob ) ;
794- await callback ( url ) ;
805+ callback ( url ) ;
795806 window . URL . revokeObjectURL ( url ) ;
796807 }
797808}
0 commit comments