@@ -85,7 +85,7 @@ const loadPdf = async (el, invoke, options) => {
8585 eventBus
8686 } ) ;
8787
88- initEventBus ( el , pdfViewer , eventBus , invoke , options ) ;
88+ addEventBus ( el , pdfViewer , eventBus , invoke , options ) ;
8989
9090 const pdfDocument = await loadingTask . promise ;
9191 pdfViewer . setDocument ( pdfDocument ) ;
@@ -164,7 +164,7 @@ const setObserver = el => {
164164 return observer ;
165165}
166166
167- const initEventBus = ( el , pdfViewer , eventBus , invoke , options ) => {
167+ const addEventBus = ( el , pdfViewer , eventBus , invoke , options ) => {
168168 eventBus . on ( "pagesinit" , async ( ) => {
169169 if ( options . fitMode ) {
170170 pdfViewer . currentScaleValue = fitMode ;
@@ -182,39 +182,19 @@ const initEventBus = (el, pdfViewer, eventBus, invoke, options) => {
182182 } ) ;
183183
184184 eventBus . on ( "pagesloaded" , async e => {
185- if ( options . enableThumbnails ) {
186- resetThumbnailsView ( el , pdfViewer ) ;
187- }
188-
189185 if ( options . triggerPagesLoaded === true ) {
190186 await invoke . invokeMethodAsync ( "PagesLoaded" , e . pagesCount ) ;
191187 }
192188
193- const controls = el . querySelector ( ".bb-view-controls" ) ;
194- EventHandler . on ( controls , "click" , ".bb-view-print" , async e => {
195- printPdf ( options . url ) ;
196- await invoke . invokeMethodAsync ( "Printing" ) ;
197- } ) ;
198- EventHandler . on ( controls , "click" , ".dropdown-item-pages" , async e => {
199- e . delegateTarget . classList . toggle ( "active" ) ;
189+ if ( options . currentPage !== 1 ) {
190+ pdfViewer . currentPageNumber = options . currentPage ;
191+ }
200192
201- if ( pdfViewer . spreadMode !== 1 ) {
202- pdfViewer . spreadMode = 1 ;
203- }
204- else {
205- pdfViewer . spreadMode = 0 ;
206- }
207- } ) ;
208- EventHandler . on ( controls , "click" , ".dropdown-item-presentation" , async e => {
209- e . delegateTarget . classList . toggle ( "active" ) ;
210-
211- //if (pdfViewer.isInPresentationMode) {
212- // document.exitFullscreen();
213- //}
214- //else {
215- // el.requestFullscreen();
216- //}
217- } ) ;
193+ if ( options . enableThumbnails ) {
194+ resetThumbnailsView ( el , pdfViewer ) ;
195+ }
196+
197+ addToolbarEventHandlers ( el , pdfViewer , invoke , options ) ;
218198 } )
219199
220200 eventBus . on ( "pagechanging" , async evt => {
@@ -237,15 +217,16 @@ const initEventBus = (el, pdfViewer, eventBus, invoke, options) => {
237217 }
238218
239219 if ( options . triggerPageChanged === true ) {
240- await invoke . invokeMethodAsync ( "pageChanged " , page ) ;
220+ await invoke . invokeMethodAsync ( "PageChanged " , page ) ;
241221 }
242222 } , true ) ;
243223
244- const minus = el . querySelector ( ".bb-page-minus" ) ;
245- const plus = el . querySelector ( ".bb-page-plus" ) ;
246- const scaleEl = el . querySelector ( ".bb-view-scale-input" ) ;
247224
248225 eventBus . on ( "scalechanging" , evt => {
226+ const minus = el . querySelector ( ".bb-page-minus" ) ;
227+ const plus = el . querySelector ( ".bb-page-plus" ) ;
228+ const scaleEl = el . querySelector ( ".bb-view-scale-input" ) ;
229+
249230 const scale = evt . scale * 100 ;
250231 scaleEl . value = `${ Math . round ( scale , 0 ) } %` ;
251232
@@ -261,17 +242,6 @@ const initEventBus = (el, pdfViewer, eventBus, invoke, options) => {
261242 }
262243 } )
263244
264- EventHandler . on ( minus , "click" , e => updateScale ( pdfViewer , e . target , - 1 ) ) ;
265- EventHandler . on ( plus , "click" , e => updateScale ( pdfViewer , e . target , 1 ) ) ;
266-
267- const titleEl = el . querySelector ( ".bb-view-title" ) ;
268- if ( titleEl ) {
269- EventHandler . on ( titleEl , "click" , '.bb-view-bar' , e => {
270- const thumbnailsEl = el . querySelector ( ".bb-view-thumbnails" ) ;
271- thumbnailsEl . classList . toggle ( "show" ) ;
272- } ) ;
273- }
274-
275245 eventBus . on ( "rotationchanging" , evt => {
276246 const thumbnailsContainer = el . querySelector ( ".bb-view-thumbnails" ) ;
277247 if ( thumbnailsContainer ) {
@@ -280,6 +250,41 @@ const initEventBus = (el, pdfViewer, eventBus, invoke, options) => {
280250 } )
281251}
282252
253+ const addToolbarEventHandlers = ( el , pdfViewer , invoke , options ) => {
254+ const toolbar = el . querySelector ( ".bb-view-toolbar" ) ;
255+ EventHandler . on ( toolbar , "click" , ".bb-view-print" , async e => {
256+ printPdf ( options . url ) ;
257+ await invoke . invokeMethodAsync ( "Printing" ) ;
258+ } )
259+ EventHandler . on ( toolbar , "click" , ".dropdown-item-pages" , async e => {
260+ e . delegateTarget . classList . toggle ( "active" ) ;
261+
262+ if ( pdfViewer . spreadMode !== 1 ) {
263+ pdfViewer . spreadMode = 1 ;
264+ }
265+ else {
266+ pdfViewer . spreadMode = 0 ;
267+ }
268+ } ) ;
269+ EventHandler . on ( toolbar , "click" , ".dropdown-item-presentation" , async e => {
270+ e . delegateTarget . classList . toggle ( "active" ) ;
271+
272+ //if (pdfViewer.isInPresentationMode) {
273+ // document.exitFullscreen();
274+ //}
275+ //else {
276+ // el.requestFullscreen();
277+ //}
278+ } ) ;
279+
280+ EventHandler . on ( toolbar , "click" , '.bb-page-minus' , e => updateScale ( pdfViewer , e . delegateTarget , - 1 ) ) ;
281+ EventHandler . on ( toolbar , "click" , '.bb-page-plus' , e => updateScale ( pdfViewer , e . delegateTarget , 1 ) ) ;
282+ EventHandler . on ( toolbar , "click" , '.bb-view-bar' , e => {
283+ const thumbnailsEl = el . querySelector ( ".bb-view-thumbnails" ) ;
284+ thumbnailsEl . classList . toggle ( "show" ) ;
285+ } ) ;
286+ }
287+
283288const resetThumbnailsView = ( el , pdfViewer ) => {
284289 const thumbnailsContainer = el . querySelector ( ".bb-view-thumbnails" ) ;
285290 pdfViewer . getPagesOverview ( ) . map ( async ( p , i ) => {
@@ -329,6 +334,10 @@ const updateScale = (pdfViewer, button, rate) => {
329334 const current = Math . round ( parseFloat ( scale * 100 ) , 0 ) ;
330335 const step = [ 25 , 33 , 50 , 67 , 75 , 80 , 90 , 100 , 110 , 125 , 150 , 175 , 200 , 250 , 300 , 400 , 500 ] ;
331336 const findValues = step . filter ( s => rate > 0 ? current < s : current > s ) ;
337+ if ( findValues . length === 0 ) {
338+ return ;
339+ }
340+
332341 let v = 100 ;
333342 if ( rate > 0 ) {
334343 v = findValues . shift ( ) ;
0 commit comments