Skip to content

Commit

Permalink
Chore: cleaning up DocBaseViewer (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored May 9, 2017
1 parent 687dba4 commit 9d444b3
Show file tree
Hide file tree
Showing 2 changed files with 219 additions and 219 deletions.
144 changes: 72 additions & 72 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,34 +255,6 @@ class DocBaseViewer extends BaseViewer {
this.findBar = new DocFindBar(this.findBarEl, this.findController, canDownload);
}

/**
* Sets up print notification & prepare PDF for printing.
*
* @return {void}
* @private
*/
initPrint() {
this.printPopup = new Popup(this.containerEl);

const printCheckmark = document.createElement('div');
printCheckmark.className = `bp-print-check ${CLASS_HIDDEN}`;
printCheckmark.innerHTML = ICON_PRINT_CHECKMARK.trim();

const loadingIndicator = document.createElement('div');
loadingIndicator.classList.add('bp-crawler');
loadingIndicator.innerHTML = `
<div></div>
<div></div>
<div></div>`.trim();

this.printPopup.addContent(loadingIndicator, true);
this.printPopup.addContent(printCheckmark, true);

// Save a reference so they can be hidden or shown later.
this.printPopup.loadingIndicator = loadingIndicator;
this.printPopup.printCheckmark = printCheckmark;
}

/**
* Ensures that the print blob is loaded & updates the print UI.
*
Expand Down Expand Up @@ -320,34 +292,6 @@ class DocBaseViewer extends BaseViewer {
}
}

/**
* Re-sizing logic.
*
* @override
* @return {void}
* @protected
*/
resize() {
if (!this.pdfViewer || !this.pdfViewer.pageViewsReady) {
return;
}

// Save page and return after resize
const currentPageNumber = this.pdfViewer.currentPageNumber;

this.pdfViewer.currentScaleValue = this.pdfViewer.currentScaleValue || 'auto';
this.pdfViewer.update();

this.setPage(currentPageNumber);

// Update annotations scale
if (this.annotator) {
this.annotator.setScale(this.pdfViewer.currentScale); // Set scale to current numerical scale
}

super.resize();
}

/**
* Go to previous page
*
Expand Down Expand Up @@ -628,6 +572,34 @@ class DocBaseViewer extends BaseViewer {
});
}

/**
* Re-sizing logic.
*
* @protected
* @override
* @return {void}
*/
resize() {
if (!this.pdfViewer || !this.pdfViewer.pageViewsReady) {
return;
}

// Save page and return after resize
const currentPageNumber = this.pdfViewer.currentPageNumber;

this.pdfViewer.currentScaleValue = this.pdfViewer.currentScaleValue || 'auto';
this.pdfViewer.update();

this.setPage(currentPageNumber);

// Update annotations scale
if (this.annotator) {
this.annotator.setScale(this.pdfViewer.currentScale); // Set scale to current numerical scale
}

super.resize();
}

//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
Expand Down Expand Up @@ -676,6 +648,34 @@ class DocBaseViewer extends BaseViewer {
PDFJS.maxCanvasPixels = this.isMobile ? MOBILE_MAX_CANVAS_SIZE : PDFJS.maxCanvasPixels;
}

/**
* Sets up print notification & prepare PDF for printing.
*
* @private
* @return {void}
*/
initPrint() {
this.printPopup = new Popup(this.containerEl);

const printCheckmark = document.createElement('div');
printCheckmark.className = `bp-print-check ${CLASS_HIDDEN}`;
printCheckmark.innerHTML = ICON_PRINT_CHECKMARK.trim();

const loadingIndicator = document.createElement('div');
loadingIndicator.classList.add('bp-crawler');
loadingIndicator.innerHTML = `
<div></div>
<div></div>
<div></div>`.trim();

this.printPopup.addContent(loadingIndicator, true);
this.printPopup.addContent(printCheckmark, true);

// Save a reference so they can be hidden or shown later.
this.printPopup.loadingIndicator = loadingIndicator;
this.printPopup.printCheckmark = printCheckmark;
}

/**
* Initializes annotations.
*
Expand Down Expand Up @@ -723,8 +723,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Initializes page number selector.
*
* @return {void}
* @private
* @return {void}
*/
initPageNumEl() {
const pageNumEl = this.controls.controlsEl.querySelector('.bp-doc-page-num');
Expand All @@ -741,9 +741,9 @@ class DocBaseViewer extends BaseViewer {
/**
* Fetches PDF and converts to blob for printing.
*
* @private
* @param {string} pdfUrl - URL to PDF
* @return {Promise} Promise setting print blob
* @private
*/
fetchPrintBlob(pdfUrl) {
return get(pdfUrl, 'blob').then((blob) => {
Expand All @@ -754,8 +754,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Handles logic for printing the PDF representation in browser.
*
* @return {void}
* @private
* @return {void}
*/
browserPrint() {
// For IE & Edge, use the open or save dialog since we can't open
Expand Down Expand Up @@ -810,8 +810,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Creates UI for preview controls.
*
* @return {void}
* @private
* @return {void}
*/
loadUI() {
this.controls = new Controls(this.containerEl);
Expand All @@ -822,8 +822,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Replaces the page number display with an input box that allows the user to type in a page number
*
* @return {void}
* @private
* @return {void}
*/
showPageNumInput() {
// show the input box with the current page number selected within it
Expand All @@ -841,8 +841,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Hide the page number input
*
* @return {void}
* @private
* @return {void}
*/
hidePageNumInput() {
this.controls.controlsEl.classList.remove(SHOW_PAGE_NUM_INPUT_CLASS);
Expand All @@ -853,9 +853,9 @@ class DocBaseViewer extends BaseViewer {
/**
* Update page number in page control widget.
*
* @private
* @param {number} pageNum - Number of page to update to
* @return {void}
* @private
*/
updateCurrentPage(pageNum) {
let truePageNum = pageNum;
Expand Down Expand Up @@ -886,8 +886,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Binds DOM listeners for document viewer.
*
* @return {void}
* @protected
* @return {void}
*/
bindDOMListeners() {
// When page structure is initialized, set default zoom, load controls,
Expand Down Expand Up @@ -922,8 +922,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Unbinds DOM listeners for document viewer.
*
* @return {void}
* @protected
* @return {void}
*/
unbindDOMListeners() {
if (this.docEl) {
Expand Down Expand Up @@ -951,8 +951,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Binds listeners for document controls. Overridden.
*
* @return {void}
* @protected
* @return {void}
*/
bindControlListeners() {}

Expand All @@ -977,9 +977,9 @@ class DocBaseViewer extends BaseViewer {
/**
* Keydown handler for page number input.
*
* @private
* @param {Event} event - Keydown event
* @return {void}
* @private
*/
pageNumInputKeydownHandler(event) {
const key = decodeKeydown(event);
Expand Down Expand Up @@ -1016,8 +1016,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Handler for 'pagesinit' event.
*
* @return {void}
* @private
* @return {void}
*/
pagesinitHandler() {
this.pdfViewer.currentScaleValue = 'auto';
Expand All @@ -1044,8 +1044,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Handler for 'pagerendered' event.
*
* @return {void}
* @private
* @return {void}
*/
pagerenderedHandler(event) {
const pageNumber = event.detail ? event.detail.pageNumber : undefined;
Expand All @@ -1066,9 +1066,9 @@ class DocBaseViewer extends BaseViewer {
/**
* Handler for 'pagechange' event.
*
* @private
* @param {Event} event - Pagechange event
* @return {void}
* @private
*/
pagechangeHandler(event) {
const pageNum = event.pageNumber;
Expand All @@ -1088,8 +1088,8 @@ class DocBaseViewer extends BaseViewer {
* Fullscreen entered handler. Add presentation mode class, set
* presentation mode state, and set zoom to fullscreen zoom.
*
* @return {void}
* @private
* @return {void}
*/
enterfullscreenHandler() {
this.pdfViewer.currentScaleValue = 'page-fit';
Expand All @@ -1115,8 +1115,8 @@ class DocBaseViewer extends BaseViewer {
/**
* Scroll handler. Fires an event on start and stop
*
* @return {void}
* @private
* @return {void}
*/
scrollHandler = throttle(() => {
// Reset the scroll timer if we are continuing a scroll
Expand Down
Loading

0 comments on commit 9d444b3

Please sign in to comment.