Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass in a PDFViewer instance to PDFPresentationMode and use it to eliminate all references to PDFViewerApplication #6177

Merged
merged 1 commit into from
Jul 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions web/pdf_presentation_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFViewerApplication */

'use strict';

Expand All @@ -27,6 +26,7 @@ var CONTROLS_SELECTOR = 'pdfPresentationModeControls';
* @typedef {Object} PDFPresentationModeOptions
* @property {HTMLDivElement} container - The container for the viewer element.
* @property {HTMLDivElement} viewer - (optional) The viewer element.
* @property {PDFViewer} pdfViewer - The document viewer.
* @property {PDFThumbnailViewer} pdfThumbnailViewer - (optional) The thumbnail
* viewer.
* @property {Array} contextMenuItems - (optional) The menuitems that are added
Expand All @@ -44,6 +44,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
function PDFPresentationMode(options) {
this.container = options.container;
this.viewer = options.viewer || options.container.firstElementChild;
this.pdfViewer = options.pdfViewer;
this.pdfThumbnailViewer = options.pdfThumbnailViewer || null;
var contextMenuItems = options.contextMenuItems || null;

Expand Down Expand Up @@ -91,8 +92,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
}

this.args = {
page: PDFViewerApplication.page,
previousScale: PDFViewerApplication.currentScaleValue
page: this.pdfViewer.currentPageNumber,
previousScale: this.pdfViewer.currentScaleValue,
};

return true;
Expand Down Expand Up @@ -132,16 +133,16 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
if (Math.abs(this.mouseScrollDelta) >= PAGE_SWITCH_THRESHOLD) {
var pageSwitchDirection = (this.mouseScrollDelta > 0) ?
PageSwitchDirection.UP : PageSwitchDirection.DOWN;
var page = PDFViewerApplication.page;
var page = this.pdfViewer.currentPageNumber;
this._resetMouseScrollState();

// If we're at the first/last page, we don't need to do anything.
if ((page === 1 && pageSwitchDirection === PageSwitchDirection.UP) ||
(page === PDFViewerApplication.pagesCount &&
(page === this.pdfViewer.pagesCount &&
pageSwitchDirection === PageSwitchDirection.DOWN)) {
return;
}
PDFViewerApplication.page = (page + pageSwitchDirection);
this.pdfViewer.currentPageNumber = (page + pageSwitchDirection);
this.mouseScrollTimeStamp = currentTime;
}
},
Expand Down Expand Up @@ -207,8 +208,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
// Ensure that the correct page is scrolled into view when entering
// Presentation Mode, by waiting until fullscreen mode in enabled.
setTimeout(function enterPresentationModeTimeout() {
PDFViewerApplication.page = this.args.page;
PDFViewerApplication.setScale('page-fit', true);
this.pdfViewer.currentPageNumber = this.args.page;
this.pdfViewer.currentScaleValue = 'page-fit';
}.bind(this), 0);

this._addWindowListeners();
Expand All @@ -226,7 +227,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
* @private
*/
_exit: function PDFPresentationMode_exit() {
var page = PDFViewerApplication.page;
var page = this.pdfViewer.currentPageNumber;
this.container.classList.remove(ACTIVE_SELECTOR);

// Ensure that the correct page is scrolled into view when exiting
Expand All @@ -236,8 +237,8 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
this._removeFullscreenChangeListeners();
this._notifyStateChange();

PDFViewerApplication.setScale(this.args.previousScale, true);
PDFViewerApplication.page = page;
this.pdfViewer.currentScaleValue = this.args.previousScale;
this.pdfViewer.currentPageNumber = page;
this.args = null;
}.bind(this), 0);

Expand Down Expand Up @@ -269,7 +270,7 @@ var PDFPresentationMode = (function PDFPresentationModeClosure() {
if (!isInternalLink) {
// Unless an internal link was clicked, advance one page.
evt.preventDefault();
PDFViewerApplication.page += (evt.shiftKey ? -1 : 1);
this.pdfViewer.currentPageNumber += (evt.shiftKey ? -1 : 1);
}
}
},
Expand Down
1 change: 1 addition & 0 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ var PDFViewerApplication = {
this.pdfPresentationMode = new PDFPresentationMode({
container: container,
viewer: viewer,
pdfViewer: this.pdfViewer,
pdfThumbnailViewer: this.pdfThumbnailViewer,
contextMenuItems: [
{ element: document.getElementById('contextFirstPage'),
Expand Down