Skip to content

Commit

Permalink
Renames and refactors PDFView to PDFViewerApplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
yurydelendik committed Sep 22, 2014
1 parent 518849c commit 25b1633
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 186 deletions.
12 changes: 6 additions & 6 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

/* globals chrome, PDFJS, PDFView */
/* globals chrome, PDFJS, PDFViewerApplication */
'use strict';

var ChromeCom = (function ChromeComClosure() {
Expand Down Expand Up @@ -64,10 +64,10 @@ var ChromeCom = (function ChromeComClosure() {
var streamUrl = response.streamUrl;
if (streamUrl) {
console.log('Found data stream for ' + file);
PDFView.open(streamUrl, 0, undefined, undefined, {
PDFViewerApplication.open(streamUrl, 0, undefined, undefined, {
length: response.contentLength
});
PDFView.setTitleUsingUrl(file);
PDFViewerApplication.setTitleUsingUrl(file);
return;
}
if (isFTPFile && !response.extensionSupportsFTP) {
Expand All @@ -91,7 +91,7 @@ var ChromeCom = (function ChromeComClosure() {
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
fileEntry.file(function(fileObject) {
var blobUrl = URL.createObjectURL(fileObject);
PDFView.open(blobUrl, 0, undefined, undefined, {
PDFViewerApplication.open(blobUrl, 0, undefined, undefined, {
length: fileObject.size
});
});
Expand All @@ -100,11 +100,11 @@ var ChromeCom = (function ChromeComClosure() {
// usual way of getting the File's data (via the Web worker).
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
error.message);
PDFView.open(file, 0);
PDFViewerApplication.open(file, 0);
});
return;
}
PDFView.open(file, 0);
PDFViewerApplication.open(file, 0);
});
};
return ChromeCom;
Expand Down
10 changes: 4 additions & 6 deletions web/document_attachments_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFView, DownloadManager, getFileName */
/* globals DownloadManager, getFileName */

'use strict';

var DocumentAttachmentsView = function documentAttachmentsView(attachments) {
var attachmentsView = document.getElementById('attachmentsView');
var DocumentAttachmentsView = function documentAttachmentsView(options) {
var attachments = options.attachments;
var attachmentsView = options.attachmentsView;
while (attachmentsView.firstChild) {
attachmentsView.removeChild(attachmentsView.firstChild);
}

if (!attachments) {
if (!attachmentsView.classList.contains('hidden')) {
PDFView.switchSidebarView('thumbs');
}
return;
}

Expand Down
15 changes: 7 additions & 8 deletions web/document_outline_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFView */

'use strict';

var DocumentOutlineView = function documentOutlineView(outline) {
var outlineView = document.getElementById('outlineView');
var DocumentOutlineView = function documentOutlineView(options) {
var outline = options.outline;
var outlineView = options.outlineView;
while (outlineView.firstChild) {
outlineView.removeChild(outlineView.firstChild);
}

if (!outline) {
if (!outlineView.classList.contains('hidden')) {
PDFView.switchSidebarView('thumbs');
}
return;
}

var linkService = options.linkService;

function bindItemLink(domObj, item) {
domObj.href = PDFView.getDestinationHash(item.dest);
domObj.href = linkService.getDestinationHash(item.dest);
domObj.onclick = function documentOutlineViewOnclick(e) {
PDFView.navigateTo(item.dest);
linkService.navigateTo(item.dest);
return false;
};
}
Expand Down
12 changes: 7 additions & 5 deletions web/document_properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFView, Promise, mozL10n, getPDFFileNameFromURL, OverlayManager */
/* globals Promise, mozL10n, getPDFFileNameFromURL, OverlayManager */

'use strict';

Expand All @@ -35,6 +35,8 @@ var DocumentProperties = {
producerField: null,
versionField: null,
pageCountField: null,
url: null,
pdfDocument: null,

initialize: function documentPropertiesInitialize(options) {
this.overlayName = options.overlayName;
Expand Down Expand Up @@ -72,7 +74,7 @@ var DocumentProperties = {
return;
}
// Get the file size (if it hasn't already been set).
PDFView.pdfDocument.getDownloadInfo().then(function(data) {
this.pdfDocument.getDownloadInfo().then(function(data) {
if (data.length === this.rawFileSize) {
return;
}
Expand All @@ -81,10 +83,10 @@ var DocumentProperties = {
}.bind(this));

// Get the document properties.
PDFView.pdfDocument.getMetadata().then(function(data) {
this.pdfDocument.getMetadata().then(function(data) {
var fields = [
{ field: this.fileNameField,
content: getPDFFileNameFromURL(PDFView.url) },
content: getPDFFileNameFromURL(this.url) },
{ field: this.fileSizeField, content: this.parseFileSize() },
{ field: this.titleField, content: data.info.Title },
{ field: this.authorField, content: data.info.Author },
Expand All @@ -97,7 +99,7 @@ var DocumentProperties = {
{ field: this.creatorField, content: data.info.Creator },
{ field: this.producerField, content: data.info.Producer },
{ field: this.versionField, content: data.info.PDFFormatVersion },
{ field: this.pageCountField, content: PDFView.pdfDocument.numPages }
{ field: this.pageCountField, content: this.pdfDocument.numPages }
];

// Show the properties in the dialog.
Expand Down
4 changes: 4 additions & 0 deletions web/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ IPDFLinkService.prototype = {
* @returns {string} The hyperlink to the PDF object.
*/
getAnchorUrl: function (hash) {},
/**
* @param {string} hash
*/
setHash: function (hash) {},
};

/**
Expand Down
24 changes: 12 additions & 12 deletions web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFJS, PDFView, PresentationMode */
/* globals PDFJS, PresentationMode */

'use strict';

var PDFHistory = {
initialized: false,
initialDestination: null,

initialize: function pdfHistoryInitialize(fingerprint) {
if (PDFJS.disableHistory || PDFView.isViewerEmbedded) {
// The browsing history is only enabled when the viewer is standalone,
// i.e. not when it is embedded in a web page.
return;
}
/**
* @param {string} fingerprint
* @param {IPDFLinkService} linkService
*/
initialize: function pdfHistoryInitialize(fingerprint, linkService) {
this.initialized = true;
this.reInitialized = false;
this.allowHashChange = true;
Expand All @@ -42,6 +41,7 @@ var PDFHistory = {
this.nextHashParam = '';

this.fingerprint = fingerprint;
this.linkService = linkService;
this.currentUid = this.uid = 0;
this.current = {};

Expand All @@ -52,7 +52,7 @@ var PDFHistory = {
if (state.target.dest) {
this.initialDestination = state.target.dest;
} else {
PDFView.initialBookmark = state.target.hash;
linkService.setHash(state.target.hash);
}
this.currentUid = state.uid;
this.uid = state.uid + 1;
Expand Down Expand Up @@ -203,7 +203,7 @@ var PDFHistory = {
params.hash = (this.current.hash && this.current.dest &&
this.current.dest === params.dest) ?
this.current.hash :
PDFView.getDestinationHash(params.dest).split('#')[1];
this.linkService.getDestinationHash(params.dest).split('#')[1];
}
if (params.page) {
params.page |= 0;
Expand All @@ -212,7 +212,7 @@ var PDFHistory = {
var target = window.history.state.target;
if (!target) {
// Invoked when the user specifies an initial bookmark,
// thus setting PDFView.initialBookmark, when the document is loaded.
// thus setting initialBookmark, when the document is loaded.
this._pushToHistory(params, false);
this.previousHash = window.location.hash.substring(1);
}
Expand Down Expand Up @@ -337,9 +337,9 @@ var PDFHistory = {
this.historyUnlocked = false;

if (state.target.dest) {
PDFView.navigateTo(state.target.dest);
this.linkService.navigateTo(state.target.dest);
} else {
PDFView.setHash(state.target.hash);
this.linkService.setHash(state.target.hash);
}
this.currentUid = state.uid;
if (state.uid > this.uid) {
Expand Down
22 changes: 11 additions & 11 deletions web/presentation_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFView, scrollIntoView, HandTool */
/* globals scrollIntoView, HandTool, PDFViewerApplication */

'use strict';

Expand Down Expand Up @@ -93,7 +93,7 @@ var PresentationMode = {
},

request: function presentationModeRequest() {
if (!PDFView.supportsFullscreen || this.isFullscreen ||
if (!PDFViewerApplication.supportsFullscreen || this.isFullscreen ||
!this.viewer.hasChildNodes()) {
return false;
}
Expand All @@ -113,8 +113,8 @@ var PresentationMode = {
}

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

return true;
Expand All @@ -138,8 +138,8 @@ var PresentationMode = {
// Presentation Mode, by waiting until fullscreen mode in enabled.
// Note: This is only necessary in non-Mozilla browsers.
setTimeout(function enterPresentationModeTimeout() {
PDFView.page = this.args.page;
PDFView.setScale('page-fit', true);
PDFViewerApplication.page = this.args.page;
PDFViewerApplication.setScale('page-fit', true);
}.bind(this), 0);

window.addEventListener('mousemove', this.mouseMove, false);
Expand All @@ -153,7 +153,7 @@ var PresentationMode = {
},

exit: function presentationModeExit() {
var page = PDFView.page;
var page = PDFViewerApplication.page;

// Ensure that the correct page is scrolled into view when exiting
// Presentation Mode, by waiting until fullscreen mode is disabled.
Expand All @@ -162,8 +162,8 @@ var PresentationMode = {
this.active = false;
this._notifyStateChange();

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

Expand All @@ -172,7 +172,7 @@ var PresentationMode = {
window.removeEventListener('contextmenu', this.contextMenu, false);

this.hideControls();
PDFView.clearMouseScrollState();
PDFViewerApplication.clearMouseScrollState();
HandTool.exitPresentationMode();
this.container.removeAttribute('contextmenu');
this.contextMenuOpen = false;
Expand Down Expand Up @@ -236,7 +236,7 @@ var PresentationMode = {
if (!isInternalLink) {
// Unless an internal link was clicked, advance one page.
evt.preventDefault();
PDFView.page += (evt.shiftKey ? -1 : 1);
PDFViewerApplication.page += (evt.shiftKey ? -1 : 1);
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions web/secondary_toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* globals PDFView, SCROLLBAR_PADDING */
/* globals PDFViewerApplication, SCROLLBAR_PADDING */

'use strict';

Expand Down Expand Up @@ -87,7 +87,7 @@ var SecondaryToolbar = {
},

downloadClick: function secondaryToolbarDownloadClick(evt) {
PDFView.download();
PDFViewerApplication.download();
this.close();
},

Expand All @@ -96,23 +96,23 @@ var SecondaryToolbar = {
},

firstPageClick: function secondaryToolbarFirstPageClick(evt) {
PDFView.page = 1;
PDFViewerApplication.page = 1;
this.close();
},

lastPageClick: function secondaryToolbarLastPageClick(evt) {
if (PDFView.pdfDocument) {
PDFView.page = PDFView.pdfDocument.numPages;
if (PDFViewerApplication.pdfDocument) {
PDFViewerApplication.page = PDFViewerApplication.pagesCount;
}
this.close();
},

pageRotateCwClick: function secondaryToolbarPageRotateCwClick(evt) {
PDFView.rotatePages(90);
PDFViewerApplication.rotatePages(90);
},

pageRotateCcwClick: function secondaryToolbarPageRotateCcwClick(evt) {
PDFView.rotatePages(-90);
PDFViewerApplication.rotatePages(-90);
},

documentPropertiesClick: function secondaryToolbarDocumentPropsClick(evt) {
Expand Down
Loading

0 comments on commit 25b1633

Please sign in to comment.