Merge pull request #6177 from Snuffleupagus/pdfPresentationMode-pdfViewer

Pass in a `PDFViewer` instance to `PDFPresentationMode` and use it to eliminate all references to `PDFViewerApplication`
This commit is contained in:
Tim van der Meij 2015-07-06 11:19:31 +02:00
commit 56e3a66c16
2 changed files with 14 additions and 12 deletions

View File

@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals PDFViewerApplication */
'use strict'; 'use strict';
@ -27,6 +26,7 @@ var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
* @typedef {Object} PDFPresentationModeOptions * @typedef {Object} PDFPresentationModeOptions
* @property {HTMLDivElement} container - The container for the viewer element. * @property {HTMLDivElement} container - The container for the viewer element.
* @property {HTMLDivElement} viewer - (optional) The viewer element. * @property {HTMLDivElement} viewer - (optional) The viewer element.
* @property {PDFViewer} pdfViewer - The document viewer.
* @property {PDFThumbnailViewer} pdfThumbnailViewer - (optional) The thumbnail * @property {PDFThumbnailViewer} pdfThumbnailViewer - (optional) The thumbnail
* viewer. * viewer.
* @property {Array} contextMenuItems - (optional) The menuitems that are added * @property {Array} contextMenuItems - (optional) The menuitems that are added
@ -44,6 +44,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
function PDFPresentationMode(options) { function PDFPresentationMode(options) {
this.container = options.container; this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild; this.viewer = options.viewer || options.container.firstElementChild;
this.pdfViewer = options.pdfViewer;
this.pdfThumbnailViewer = options.pdfThumbnailViewer || null; this.pdfThumbnailViewer = options.pdfThumbnailViewer || null;
var contextMenuItems = options.contextMenuItems || null; var contextMenuItems = options.contextMenuItems || null;
@ -91,8 +92,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
} }
this.args = { this.args = {
page: PDFViewerApplication.page, page: this.pdfViewer.currentPageNumber,
previousScale: PDFViewerApplication.currentScaleValue previousScale: this.pdfViewer.currentScaleValue,
}; };
return true; return true;
@ -132,16 +133,16 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) { if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
var pageSwitchDirection = (this.mouseScrollDelta > 0) ? var pageSwitchDirection = (this.mouseScrollDelta > 0) ?
PageSwitchDirection.UP : PageSwitchDirection.DOWN; PageSwitchDirection.UP : PageSwitchDirection.DOWN;
var page = PDFViewerApplication.page; var page = this.pdfViewer.currentPageNumber;
this._resetMouseScrollState(); this._resetMouseScrollState();
// If we're at 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) || if ((page === 1 && pageSwitchDirection === PageSwitchDirection.UP) ||
(page === PDFViewerApplication.pagesCount && (page === this.pdfViewer.pagesCount &&
pageSwitchDirection === PageSwitchDirection.DOWN)) { pageSwitchDirection === PageSwitchDirection.DOWN)) {
return; return;
} }
PDFViewerApplication.page = (page + pageSwitchDirection); this.pdfViewer.currentPageNumber = (page + pageSwitchDirection);
this.mouseScrollTimeStamp = currentTime; this.mouseScrollTimeStamp = currentTime;
} }
}, },
@ -207,8 +208,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
// Ensure that the correct page is scrolled into view when entering // Ensure that the correct page is scrolled into view when entering
// Presentation Mode, by waiting until fullscreen mode in enabled. // Presentation Mode, by waiting until fullscreen mode in enabled.
setTimeout(function enterPresentationModeTimeout() { setTimeout(function enterPresentationModeTimeout() {
PDFViewerApplication.page = this.args.page; this.pdfViewer.currentPageNumber = this.args.page;
PDFViewerApplication.setScale('page-fit', true); this.pdfViewer.currentScaleValue = 'page-fit';
}.bind(this), 0); }.bind(this), 0);
this._addWindowListeners(); this._addWindowListeners();
@ -226,7 +227,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
* @private * @private
*/ */
_exit: function PDFPresentationMode_exit() { _exit: function PDFPresentationMode_exit() {
var page = PDFViewerApplication.page; var page = this.pdfViewer.currentPageNumber;
this.container.classList.remove(ACTIVE_SELECTOR); this.container.classList.remove(ACTIVE_SELECTOR);
// Ensure that the correct page is scrolled into view when exiting // Ensure that the correct page is scrolled into view when exiting
@ -236,8 +237,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this._removeFullscreenChangeListeners(); this._removeFullscreenChangeListeners();
this._notifyStateChange(); this._notifyStateChange();
PDFViewerApplication.setScale(this.args.previousScale, true); this.pdfViewer.currentScaleValue = this.args.previousScale;
PDFViewerApplication.page = page; this.pdfViewer.currentPageNumber = page;
this.args = null; this.args = null;
}.bind(this), 0); }.bind(this), 0);
@ -269,7 +270,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
if (!isInternalLink) { if (!isInternalLink) {
// Unless an internal link was clicked, advance one page. // Unless an internal link was clicked, advance one page.
evt.preventDefault(); evt.preventDefault();
PDFViewerApplication.page += (evt.shiftKey ? -1 : 1); this.pdfViewer.currentPageNumber += (evt.shiftKey ? -1 : 1);
} }
} }
}, },

View File

@ -220,6 +220,7 @@ var PDFViewerApplication = {
this.pdfPresentationMode = new PDFPresentationMode({ this.pdfPresentationMode = new PDFPresentationMode({
container: container, container: container,
viewer: viewer, viewer: viewer,
pdfViewer: this.pdfViewer,
pdfThumbnailViewer: this.pdfThumbnailViewer, pdfThumbnailViewer: this.pdfThumbnailViewer,
contextMenuItems: [ contextMenuItems: [
{ element: document.getElementById('contextFirstPage'), { element: document.getElementById('contextFirstPage'),