@ -37,9 +37,9 @@ var SidebarView = {
/ * *
/ * *
* @ typedef { Object } PDFSidebarOptions
* @ typedef { Object } PDFSidebarOptions
* @ property { PDFViewer } - The document viewer .
* @ property { PDFViewer } pdfViewer - The document viewer .
* @ property { PDFThumbnailViewer } - The thumbnail viewer .
* @ property { PDFThumbnailViewer } pdfThumbnailViewer - The thumbnail viewer .
* @ property { PDFOutlineViewer } - The outline viewer .
* @ property { PDFOutlineViewer } pdfOutlineViewer - The outline viewer .
* @ property { HTMLDivElement } mainContainer - The main container
* @ property { HTMLDivElement } mainContainer - The main container
* ( in which the viewer element is placed ) .
* ( in which the viewer element is placed ) .
* @ property { HTMLDivElement } outerContainer - The outer container
* @ property { HTMLDivElement } outerContainer - The outer container
@ -139,17 +139,25 @@ var PDFSidebar = (function PDFSidebarClosure() {
this . isInitialViewSet = true ;
this . isInitialViewSet = true ;
if ( this . isOpen && view === SidebarView . NONE ) {
if ( this . isOpen && view === SidebarView . NONE ) {
this . _dispatchEvent ( ) ;
// If the user has already manually opened the sidebar,
// If the user has already manually opened the sidebar,
// immediately closing it would be bad UX.
// immediately closing it would be bad UX.
return ;
return ;
}
}
this . switchView ( view , true ) ;
var isViewPreserved = ( view === this . visibleView ) ;
this . switchView ( view , /* forceOpen */ true ) ;
if ( isViewPreserved ) {
// Prevent dispatching two back-to-back `sidebarviewchanged` events,
// since `this.switchView` dispatched the event if the view changed.
this . _dispatchEvent ( ) ;
}
} ,
} ,
/ * *
/ * *
* @ param { number } view - The sidebar view that should be switched to ,
* @ param { number } view - The sidebar view that should be switched to ,
* must be one of the values in { SidebarView } .
* must be one of the values in { SidebarView } .
* @ param { boolean } forceOpen - Ensure that the sidebar is opened .
* @ param { boolean } forceOpen - ( optional ) Ensure that the sidebar is open .
* The default value is false .
* The default value is false .
* /
* /
switchView : function PDFSidebar _switchView ( view , forceOpen ) {
switchView : function PDFSidebar _switchView ( view , forceOpen ) {
@ -157,9 +165,7 @@ var PDFSidebar = (function PDFSidebarClosure() {
this . close ( ) ;
this . close ( ) ;
return ;
return ;
}
}
if ( forceOpen ) {
var isViewChanged = ( view !== this . active ) ;
this . open ( ) ;
}
var shouldForceRendering = false ;
var shouldForceRendering = false ;
switch ( view ) {
switch ( view ) {
@ -172,7 +178,7 @@ var PDFSidebar = (function PDFSidebarClosure() {
this . outlineView . classList . add ( 'hidden' ) ;
this . outlineView . classList . add ( 'hidden' ) ;
this . attachmentsView . classList . add ( 'hidden' ) ;
this . attachmentsView . classList . add ( 'hidden' ) ;
if ( this . isOpen && view !== this . active ) {
if ( this . isOpen && isViewChanged ) {
this . _updateThumbnailViewer ( ) ;
this . _updateThumbnailViewer ( ) ;
shouldForceRendering = true ;
shouldForceRendering = true ;
}
}
@ -210,9 +216,17 @@ var PDFSidebar = (function PDFSidebarClosure() {
// in order to prevent setting it to an invalid state.
// in order to prevent setting it to an invalid state.
this . active = view | 0 ;
this . active = view | 0 ;
if ( forceOpen && ! this . isOpen ) {
this . open ( ) ;
// NOTE: `this.open` will trigger rendering, and dispatch the event.
return ;
}
if ( shouldForceRendering ) {
if ( shouldForceRendering ) {
this . _forceRendering ( ) ;
this . _forceRendering ( ) ;
}
}
if ( isViewChanged ) {
this . _dispatchEvent ( ) ;
}
} ,
} ,
open : function PDFSidebar _open ( ) {
open : function PDFSidebar _open ( ) {
@ -229,6 +243,7 @@ var PDFSidebar = (function PDFSidebarClosure() {
this . _updateThumbnailViewer ( ) ;
this . _updateThumbnailViewer ( ) ;
}
}
this . _forceRendering ( ) ;
this . _forceRendering ( ) ;
this . _dispatchEvent ( ) ;
} ,
} ,
close : function PDFSidebar _close ( ) {
close : function PDFSidebar _close ( ) {
@ -242,6 +257,7 @@ var PDFSidebar = (function PDFSidebarClosure() {
this . outerContainer . classList . remove ( 'sidebarOpen' ) ;
this . outerContainer . classList . remove ( 'sidebarOpen' ) ;
this . _forceRendering ( ) ;
this . _forceRendering ( ) ;
this . _dispatchEvent ( ) ;
} ,
} ,
toggle : function PDFSidebar _toggle ( ) {
toggle : function PDFSidebar _toggle ( ) {
@ -252,6 +268,17 @@ var PDFSidebar = (function PDFSidebarClosure() {
}
}
} ,
} ,
/ * *
* @ private
* /
_dispatchEvent : function PDFSidebar _dispatchEvent ( ) {
var event = document . createEvent ( 'CustomEvent' ) ;
event . initCustomEvent ( 'sidebarviewchanged' , true , true , {
view : this . visibleView ,
} ) ;
this . outerContainer . dispatchEvent ( event ) ;
} ,
/ * *
/ * *
* @ private
* @ private
* /
* /