@ -18,9 +18,9 @@
@@ -18,9 +18,9 @@
'use strict' ;
var DELAY _BEFORE _RESETTING _SWITCH _IN _PROGRESS = 1500 ; // in ms
var DELAY _BEFORE _HIDING _CONTROLS = 3000 ; // in ms
var SELECTOR = 'presentationControls' ;
var DELAY _BEFORE _RESETTING _SWITCH _IN _PROGRESS = 1000 ; // in ms
/ * *
* @ typedef { Object } PDFPresentationModeOptions
@ -32,30 +32,25 @@ var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1000; // in ms
@@ -32,30 +32,25 @@ var DELAY_BEFORE_RESETTING_SWITCH_IN_PROGRESS = 1000; // in ms
* to the context menu in Presentation Mode .
* /
var PDFPresentationMode = {
initialized : false ,
active : false ,
args : null ,
contextMenuOpen : false ,
mouseScrollTimeStamp : 0 ,
mouseScrollDelta : 0 ,
/ * *
* @ class
* /
var PDFPresentationMode = ( function PDFPresentationModeClosure ( ) {
/ * *
* @ constructs PDFPresentationMode
* @ param { PDFPresentationModeOptions } options
* /
initialize : function pdfPresentationModeInitialize ( options ) {
this . initialized = true ;
function PDFPresentationMode ( options ) {
this . container = options . container ;
this . viewer = options . viewer || options . container . firstElementChild ;
this . pdfThumbnailViewer = options . pdfThumbnailViewer || null ;
var contextMenuItems = options . contextMenuItems || null ;
window . addEventListener ( 'fullscreenchange' , this . _fullscreenChange ) ;
window . addEventListener ( 'mozfullscreenchange' , this . _fullscreenChange ) ;
//#if !(FIREFOX || MOZCENTRAL)
window . addEventListener ( 'webkitfullscreenchange' , this . _fullscreenChange ) ;
window . addEventListener ( 'MSFullscreenChange' , this . _fullscreenChange ) ;
//#endif
this . active = false ;
this . args = null ;
this . contextMenuOpen = false ;
this . mouseScrollTimeStamp = 0 ;
this . mouseScrollDelta = 0 ;
if ( contextMenuItems ) {
for ( var i = 0 , ii = contextMenuItems . length ; i < ii ; i ++ ) {
@ -66,17 +61,19 @@ var PDFPresentationMode = {
@@ -66,17 +61,19 @@ var PDFPresentationMode = {
} . bind ( this , item . handler ) ) ;
}
}
} ,
}
PDFPresentationMode . prototype = {
/ * *
* Request the browser to enter fullscreen mode .
* @ returns { boolean } Indicating if the request was successful .
* /
request : function pdfPresentationModeR equest( ) {
if ( ! this . initialized || this . switchInProgress || this . active ||
request : function PDFPresentationMode _r equest( ) {
if ( this . switchInProgress || this . active ||
! this . viewer . hasChildNodes ( ) ) {
return false ;
}
this . _addFullscreenChangeListeners ( ) ;
this . _setSwitchInProgress ( ) ;
this . _notifyStateChange ( ) ;
@ -105,8 +102,8 @@ var PDFPresentationMode = {
@@ -105,8 +102,8 @@ var PDFPresentationMode = {
* with large enough motion , to prevent accidental page switches .
* @ param { number } delta - The delta value from the mouse event .
* /
mouseScroll : function pdfPresentationModeM ouseScroll( delta ) {
if ( ! this . initialized && ! this . active ) {
mouseScroll : function PDFPresentationMode _m ouseScroll( delta ) {
if ( ! this . active ) {
return ;
}
var MOUSE _SCROLL _COOLDOWN _TIME = 50 ;
@ -119,12 +116,12 @@ var PDFPresentationMode = {
@@ -119,12 +116,12 @@ var PDFPresentationMode = {
var currentTime = ( new Date ( ) ) . getTime ( ) ;
var storedTime = this . mouseScrollTimeStamp ;
// If we've already switched page, avoid accidentally switching page again.
// If we've already switched page, avoid accidentally switching again.
if ( currentTime > storedTime &&
currentTime - storedTime < MOUSE _SCROLL _COOLDOWN _TIME ) {
return ;
}
// If the user changes scroll direction, reset the accumulated scroll delta.
// If the scroll direction changed , reset the accumulated scroll delta.
if ( ( this . mouseScrollDelta > 0 && delta < 0 ) ||
( this . mouseScrollDelta < 0 && delta > 0 ) ) {
this . _resetMouseScrollState ( ) ;
@ -137,7 +134,7 @@ var PDFPresentationMode = {
@@ -137,7 +134,7 @@ var PDFPresentationMode = {
var page = PDFViewerApplication . page ;
this . _resetMouseScrollState ( ) ;
// If we're already on the first/last page, we don't need to do anything.
// If we're at the first/last page, we don't need to do anything.
if ( ( page === 1 && pageSwitchDirection === PageSwitchDirection . UP ) ||
( page === PDFViewerApplication . pagesCount &&
pageSwitchDirection === PageSwitchDirection . DOWN ) ) {
@ -158,24 +155,11 @@ var PDFPresentationMode = {
@@ -158,24 +155,11 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_fullscreenChange : function pdfPresentationModeFullscreenChange ( ) {
var self = PDFPresentationMode ;
if ( self . isFullscreen ) {
self . _enter ( ) ;
} else {
self . _exit ( ) ;
}
} ,
/ * *
* @ private
* /
_notifyStateChange : function pdfPresentationModeNotifyStateChange ( ) {
var self = PDFPresentationMode ;
_notifyStateChange : function PDFPresentationMode _notifyStateChange ( ) {
var event = document . createEvent ( 'CustomEvent' ) ;
event . initCustomEvent ( 'presentationmodechanged' , true , true , {
active : self . active ,
switchInProgress : ! ! self . switchInProgress
active : this . active ,
switchInProgress : ! ! this . switchInProgress
} ) ;
window . dispatchEvent ( event ) ;
} ,
@ -185,14 +169,15 @@ var PDFPresentationMode = {
@@ -185,14 +169,15 @@ var PDFPresentationMode = {
* i . e . when the browser is requested to enter fullscreen mode .
* This timeout is used to prevent the current page from being scrolled
* partially , or completely , out of view when entering Presentation Mode .
* NOTE : This issue seems limited to certain zoom levels ( e . g . 'page-width' ) .
* NOTE : This issue seems limited to certain zoom levels ( e . g . page - width ) .
* @ private
* /
_setSwitchInProgress : function pdf PresentationMode_setSwitchInProgress ( ) {
_setSwitchInProgress : function PDF PresentationMode_setSwitchInProgress ( ) {
if ( this . switchInProgress ) {
clearTimeout ( this . switchInProgress ) ;
}
this . switchInProgress = setTimeout ( function switchInProgressTimeout ( ) {
this . _removeFullscreenChangeListeners ( ) ;
delete this . switchInProgress ;
this . _notifyStateChange ( ) ;
} . bind ( this ) , DELAY _BEFORE _RESETTING _SWITCH _IN _PROGRESS ) ;
@ -201,7 +186,8 @@ var PDFPresentationMode = {
@@ -201,7 +186,8 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_resetSwitchInProgress : function pdfPresentationMode _resetSwitchInProgress ( ) {
_resetSwitchInProgress :
function PDFPresentationMode _resetSwitchInProgress ( ) {
if ( this . switchInProgress ) {
clearTimeout ( this . switchInProgress ) ;
delete this . switchInProgress ;
@ -211,7 +197,7 @@ var PDFPresentationMode = {
@@ -211,7 +197,7 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_enter : function pdfPresentationModeE nter( ) {
_enter : function PDFPresentationMode _e nter( ) {
this . active = true ;
this . _resetSwitchInProgress ( ) ;
this . _notifyStateChange ( ) ;
@ -223,11 +209,7 @@ var PDFPresentationMode = {
@@ -223,11 +209,7 @@ var PDFPresentationMode = {
PDFViewerApplication . setScale ( 'page-fit' , true ) ;
} . bind ( this ) , 0 ) ;
window . addEventListener ( 'mousemove' , this . _showControls , false ) ;
window . addEventListener ( 'mousedown' , this . _mouseDown , false ) ;
window . addEventListener ( 'keydown' , this . _resetMouseScrollState , false ) ;
window . addEventListener ( 'contextmenu' , this . _contextMenu , false ) ;
this . _addWindowListeners ( ) ;
this . _showControls ( ) ;
this . contextMenuOpen = false ;
this . container . setAttribute ( 'contextmenu' , 'viewerContextMenu' ) ;
@ -241,13 +223,14 @@ var PDFPresentationMode = {
@@ -241,13 +223,14 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_exit : function pdfPresentationModeE xit( ) {
_exit : function PDFPresentationMode _e xit( ) {
var page = PDFViewerApplication . page ;
// Ensure that the correct page is scrolled into view when exiting
// Presentation Mode, by waiting until fullscreen mode is disabled.
setTimeout ( function exitPresentationModeTimeout ( ) {
this . active = false ;
this . _removeFullscreenChangeListeners ( ) ;
this . _notifyStateChange ( ) ;
PDFViewerApplication . setScale ( this . args . previousScale , true ) ;
@ -255,11 +238,7 @@ var PDFPresentationMode = {
@@ -255,11 +238,7 @@ var PDFPresentationMode = {
this . args = null ;
} . bind ( this ) , 0 ) ;
window . removeEventListener ( 'mousemove' , this . _showControls , false ) ;
window . removeEventListener ( 'mousedown' , this . _mouseDown , false ) ;
window . removeEventListener ( 'keydown' , this . _resetMouseScrollState , false ) ;
window . removeEventListener ( 'contextmenu' , this . _contextMenu , false ) ;
this . _removeWindowListeners ( ) ;
this . _hideControls ( ) ;
this . _resetMouseScrollState ( ) ;
this . container . removeAttribute ( 'contextmenu' ) ;
@ -273,10 +252,9 @@ var PDFPresentationMode = {
@@ -273,10 +252,9 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_mouseDown : function pdfPresentationModeMouseDown ( evt ) {
var self = PDFPresentationMode ;
if ( self . contextMenuOpen ) {
self . contextMenuOpen = false ;
_mouseDown : function PDFPresentationMode _mouseDown ( evt ) {
if ( this . contextMenuOpen ) {
this . contextMenuOpen = false ;
evt . preventDefault ( ) ;
return ;
}
@ -296,46 +274,123 @@ var PDFPresentationMode = {
@@ -296,46 +274,123 @@ var PDFPresentationMode = {
/ * *
* @ private
* /
_contextMenu : function pdfPresentationModeContextMenu ( evt ) {
PDFPresentationMode . contextMenuOpen = true ;
_contextMenu : function PDFPresentationMode _contextMenu ( ) {
this . contextMenuOpen = true ;
} ,
/ * *
* @ private
* /
_showControls : function pdfPresentationModeShowControls ( ) {
var self = PDFPresentationMode ;
if ( self . controlsTimeout ) {
clearTimeout ( self . controlsTimeout ) ;
_showControls : function PDFPresentationMode _showControls ( ) {
if ( this . controlsTimeout ) {
clearTimeout ( this . controlsTimeout ) ;
} else {
self . container . classList . add ( SELECTOR ) ;
this . container . classList . add ( SELECTOR ) ;
}
self . controlsTimeout = setTimeout ( function showControlsTimeout ( ) {
self . container . classList . remove ( SELECTOR ) ;
delete self . controlsTimeout ;
} , DELAY _BEFORE _HIDING _CONTROLS ) ;
this . controlsTimeout = setTimeout ( function showControlsTimeout ( ) {
this . container . classList . remove ( SELECTOR ) ;
delete this . controlsTimeout ;
} . bind ( this ) , DELAY _BEFORE _HIDING _CONTROLS ) ;
} ,
/ * *
* @ private
* /
_hideControls : function pdfPresentationModeHideControls ( ) {
var self = PDFPresentationMode ;
if ( ! self . controlsTimeout ) {
_hideControls : function PDFPresentationMode _hideControls ( ) {
if ( ! this . controlsTimeout ) {
return ;
}
clearTimeout ( self . controlsTimeout ) ;
self . container . classList . remove ( SELECTOR ) ;
delete self . controlsTimeout ;
clearTimeout ( this . controlsTimeout ) ;
this . container . classList . remove ( SELECTOR ) ;
delete this . controlsTimeout ;
} ,
/ * *
* Resets the properties used for tracking mouse scrolling events .
* @ private
* /
_resetMouseScrollState : function pdfPresentationModeResetMouseScrollState ( ) {
var self = PDFPresentationMode ;
self . mouseScrollTimeStamp = 0 ;
self . mouseScrollDelta = 0 ;
_resetMouseScrollState :
function PDFPresentationMode _resetMouseScrollState ( ) {
this . mouseScrollTimeStamp = 0 ;
this . mouseScrollDelta = 0 ;
} ,
/ * *
* @ private
* /
_addWindowListeners : function PDFPresentationMode _addWindowListeners ( ) {
this . showControlsBind = this . _showControls . bind ( this ) ;
this . mouseDownBind = this . _mouseDown . bind ( this ) ;
this . resetMouseScrollStateBind = this . _resetMouseScrollState . bind ( this ) ;
this . contextMenuBind = this . _contextMenu . bind ( this ) ;
window . addEventListener ( 'mousemove' , this . showControlsBind ) ;
window . addEventListener ( 'mousedown' , this . mouseDownBind ) ;
window . addEventListener ( 'keydown' , this . resetMouseScrollStateBind ) ;
window . addEventListener ( 'contextmenu' , this . contextMenuBind ) ;
} ,
/ * *
* @ private
* /
_removeWindowListeners :
function PDFPresentationMode _removeWindowListeners ( ) {
window . removeEventListener ( 'mousemove' , this . showControlsBind ) ;
window . removeEventListener ( 'mousedown' , this . mouseDownBind ) ;
window . removeEventListener ( 'keydown' , this . resetMouseScrollStateBind ) ;
window . removeEventListener ( 'contextmenu' , this . contextMenuBind ) ;
delete this . showControlsBind ;
delete this . mouseDownBind ;
delete this . resetMouseScrollStateBind ;
delete this . contextMenuBind ;
} ,
/ * *
* @ private
* /
_fullscreenChange : function PDFPresentationMode _fullscreenChange ( ) {
if ( this . isFullscreen ) {
this . _enter ( ) ;
} else {
this . _exit ( ) ;
}
} ,
/ * *
* @ private
* /
_addFullscreenChangeListeners :
function PDFPresentationMode _addFullscreenChangeListeners ( ) {
this . fullscreenChangeBind = this . _fullscreenChange . bind ( this ) ;
window . addEventListener ( 'fullscreenchange' , this . fullscreenChangeBind ) ;
window . addEventListener ( 'mozfullscreenchange' , this . fullscreenChangeBind ) ;
//#if !(FIREFOX || MOZCENTRAL)
window . addEventListener ( 'webkitfullscreenchange' ,
this . fullscreenChangeBind ) ;
window . addEventListener ( 'MSFullscreenChange' , this . fullscreenChangeBind ) ;
//#endif
} ,
/ * *
* @ private
* /
_removeFullscreenChangeListeners :
function PDFPresentationMode _removeFullscreenChangeListeners ( ) {
window . removeEventListener ( 'fullscreenchange' , this . fullscreenChangeBind ) ;
window . removeEventListener ( 'mozfullscreenchange' ,
this . fullscreenChangeBind ) ;
//#if !(FIREFOX || MOZCENTRAL)
window . removeEventListener ( 'webkitfullscreenchange' ,
this . fullscreenChangeBind ) ;
window . removeEventListener ( 'MSFullscreenChange' ,
this . fullscreenChangeBind ) ;
//#endif
delete this . fullscreenChangeBind ;
}
} ;
return PDFPresentationMode ;
} ) ( ) ;