Replace unnecessary var self = this
statements with arrow functions in web/app.js
Also replaces `var` with `let` in the functions/methods that are touched in the patch. Please note that this should be completely safe, for two separate reasons, since trying to access `let` in a scope where it's not defined is first of all a runtime error and second of all an ESLint error (thanks to the `no-undef` rule).
This commit is contained in:
parent
0dbc68a6d6
commit
240a3926f4
332
web/app.js
332
web/app.js
@ -258,131 +258,131 @@ var PDFViewerApplication = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_initializeViewerComponents() {
|
_initializeViewerComponents() {
|
||||||
var self = this;
|
let appConfig = this.appConfig;
|
||||||
var appConfig = this.appConfig;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var eventBus = appConfig.eventBus || getGlobalEventBus();
|
let eventBus = appConfig.eventBus || getGlobalEventBus();
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
|
|
||||||
var pdfRenderingQueue = new PDFRenderingQueue();
|
let pdfRenderingQueue = new PDFRenderingQueue();
|
||||||
pdfRenderingQueue.onIdle = self.cleanup.bind(self);
|
pdfRenderingQueue.onIdle = this.cleanup.bind(this);
|
||||||
self.pdfRenderingQueue = pdfRenderingQueue;
|
this.pdfRenderingQueue = pdfRenderingQueue;
|
||||||
|
|
||||||
var pdfLinkService = new PDFLinkService({
|
let pdfLinkService = new PDFLinkService({
|
||||||
eventBus,
|
eventBus,
|
||||||
});
|
});
|
||||||
self.pdfLinkService = pdfLinkService;
|
this.pdfLinkService = pdfLinkService;
|
||||||
|
|
||||||
var downloadManager = self.externalServices.createDownloadManager();
|
let downloadManager = this.externalServices.createDownloadManager();
|
||||||
self.downloadManager = downloadManager;
|
this.downloadManager = downloadManager;
|
||||||
|
|
||||||
var container = appConfig.mainContainer;
|
let container = appConfig.mainContainer;
|
||||||
var viewer = appConfig.viewerContainer;
|
let viewer = appConfig.viewerContainer;
|
||||||
self.pdfViewer = new PDFViewer({
|
this.pdfViewer = new PDFViewer({
|
||||||
container,
|
container,
|
||||||
viewer,
|
viewer,
|
||||||
eventBus,
|
eventBus,
|
||||||
renderingQueue: pdfRenderingQueue,
|
renderingQueue: pdfRenderingQueue,
|
||||||
linkService: pdfLinkService,
|
linkService: pdfLinkService,
|
||||||
downloadManager,
|
downloadManager,
|
||||||
renderer: self.viewerPrefs['renderer'],
|
renderer: this.viewerPrefs['renderer'],
|
||||||
enhanceTextSelection: self.viewerPrefs['enhanceTextSelection'],
|
enhanceTextSelection: this.viewerPrefs['enhanceTextSelection'],
|
||||||
renderInteractiveForms: self.viewerPrefs['renderInteractiveForms'],
|
renderInteractiveForms: this.viewerPrefs['renderInteractiveForms'],
|
||||||
enablePrintAutoRotate: self.viewerPrefs['enablePrintAutoRotate'],
|
enablePrintAutoRotate: this.viewerPrefs['enablePrintAutoRotate'],
|
||||||
});
|
});
|
||||||
pdfRenderingQueue.setViewer(self.pdfViewer);
|
pdfRenderingQueue.setViewer(this.pdfViewer);
|
||||||
pdfLinkService.setViewer(self.pdfViewer);
|
pdfLinkService.setViewer(this.pdfViewer);
|
||||||
|
|
||||||
var thumbnailContainer = appConfig.sidebar.thumbnailView;
|
let thumbnailContainer = appConfig.sidebar.thumbnailView;
|
||||||
self.pdfThumbnailViewer = new PDFThumbnailViewer({
|
this.pdfThumbnailViewer = new PDFThumbnailViewer({
|
||||||
container: thumbnailContainer,
|
container: thumbnailContainer,
|
||||||
renderingQueue: pdfRenderingQueue,
|
renderingQueue: pdfRenderingQueue,
|
||||||
linkService: pdfLinkService,
|
linkService: pdfLinkService,
|
||||||
});
|
});
|
||||||
pdfRenderingQueue.setThumbnailViewer(self.pdfThumbnailViewer);
|
pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer);
|
||||||
|
|
||||||
self.pdfHistory = new PDFHistory({
|
this.pdfHistory = new PDFHistory({
|
||||||
linkService: pdfLinkService,
|
linkService: pdfLinkService,
|
||||||
eventBus,
|
eventBus,
|
||||||
});
|
});
|
||||||
pdfLinkService.setHistory(self.pdfHistory);
|
pdfLinkService.setHistory(this.pdfHistory);
|
||||||
|
|
||||||
self.findController = new PDFFindController({
|
this.findController = new PDFFindController({
|
||||||
pdfViewer: self.pdfViewer,
|
pdfViewer: this.pdfViewer,
|
||||||
});
|
});
|
||||||
self.findController.onUpdateResultsCount = function (matchCount) {
|
this.findController.onUpdateResultsCount = (matchCount) => {
|
||||||
if (self.supportsIntegratedFind) {
|
if (this.supportsIntegratedFind) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.findBar.updateResultsCount(matchCount);
|
this.findBar.updateResultsCount(matchCount);
|
||||||
};
|
};
|
||||||
self.findController.onUpdateState = function (state, previous,
|
this.findController.onUpdateState = (state, previous, matchCount) => {
|
||||||
matchCount) {
|
if (this.supportsIntegratedFind) {
|
||||||
if (self.supportsIntegratedFind) {
|
this.externalServices.updateFindControlState({
|
||||||
self.externalServices.updateFindControlState(
|
result: state,
|
||||||
{result: state, findPrevious: previous});
|
findPrevious: previous,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
self.findBar.updateUIState(state, previous, matchCount);
|
this.findBar.updateUIState(state, previous, matchCount);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.pdfViewer.setFindController(self.findController);
|
this.pdfViewer.setFindController(this.findController);
|
||||||
|
|
||||||
// FIXME better PDFFindBar constructor parameters
|
// FIXME better PDFFindBar constructor parameters
|
||||||
var findBarConfig = Object.create(appConfig.findBar);
|
let findBarConfig = Object.create(appConfig.findBar);
|
||||||
findBarConfig.findController = self.findController;
|
findBarConfig.findController = this.findController;
|
||||||
findBarConfig.eventBus = eventBus;
|
findBarConfig.eventBus = eventBus;
|
||||||
self.findBar = new PDFFindBar(findBarConfig);
|
this.findBar = new PDFFindBar(findBarConfig);
|
||||||
|
|
||||||
self.overlayManager = OverlayManager;
|
this.overlayManager = OverlayManager;
|
||||||
|
|
||||||
self.handTool = new HandTool({
|
this.handTool = new HandTool({
|
||||||
container,
|
container,
|
||||||
eventBus,
|
eventBus,
|
||||||
preferences: this.preferences,
|
preferences: this.preferences,
|
||||||
});
|
});
|
||||||
|
|
||||||
self.pdfDocumentProperties =
|
this.pdfDocumentProperties =
|
||||||
new PDFDocumentProperties(appConfig.documentProperties);
|
new PDFDocumentProperties(appConfig.documentProperties);
|
||||||
|
|
||||||
self.toolbar = new Toolbar(appConfig.toolbar, container, eventBus);
|
this.toolbar = new Toolbar(appConfig.toolbar, container, eventBus);
|
||||||
|
|
||||||
self.secondaryToolbar =
|
this.secondaryToolbar =
|
||||||
new SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
|
new SecondaryToolbar(appConfig.secondaryToolbar, container, eventBus);
|
||||||
|
|
||||||
if (self.supportsFullscreen) {
|
if (this.supportsFullscreen) {
|
||||||
self.pdfPresentationMode = new PDFPresentationMode({
|
this.pdfPresentationMode = new PDFPresentationMode({
|
||||||
container,
|
container,
|
||||||
viewer,
|
viewer,
|
||||||
pdfViewer: self.pdfViewer,
|
pdfViewer: this.pdfViewer,
|
||||||
eventBus,
|
eventBus,
|
||||||
contextMenuItems: appConfig.fullscreen
|
contextMenuItems: appConfig.fullscreen
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay);
|
this.passwordPrompt = new PasswordPrompt(appConfig.passwordOverlay);
|
||||||
|
|
||||||
self.pdfOutlineViewer = new PDFOutlineViewer({
|
this.pdfOutlineViewer = new PDFOutlineViewer({
|
||||||
container: appConfig.sidebar.outlineView,
|
container: appConfig.sidebar.outlineView,
|
||||||
eventBus,
|
eventBus,
|
||||||
linkService: pdfLinkService,
|
linkService: pdfLinkService,
|
||||||
});
|
});
|
||||||
|
|
||||||
self.pdfAttachmentViewer = new PDFAttachmentViewer({
|
this.pdfAttachmentViewer = new PDFAttachmentViewer({
|
||||||
container: appConfig.sidebar.attachmentsView,
|
container: appConfig.sidebar.attachmentsView,
|
||||||
eventBus,
|
eventBus,
|
||||||
downloadManager,
|
downloadManager,
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME better PDFSidebar constructor parameters
|
// FIXME better PDFSidebar constructor parameters
|
||||||
var sidebarConfig = Object.create(appConfig.sidebar);
|
let sidebarConfig = Object.create(appConfig.sidebar);
|
||||||
sidebarConfig.pdfViewer = self.pdfViewer;
|
sidebarConfig.pdfViewer = this.pdfViewer;
|
||||||
sidebarConfig.pdfThumbnailViewer = self.pdfThumbnailViewer;
|
sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
|
||||||
sidebarConfig.pdfOutlineViewer = self.pdfOutlineViewer;
|
sidebarConfig.pdfOutlineViewer = this.pdfOutlineViewer;
|
||||||
sidebarConfig.eventBus = eventBus;
|
sidebarConfig.eventBus = eventBus;
|
||||||
self.pdfSidebar = new PDFSidebar(sidebarConfig);
|
this.pdfSidebar = new PDFSidebar(sidebarConfig);
|
||||||
self.pdfSidebar.onToggled = self.forceRendering.bind(self);
|
this.pdfSidebar.onToggled = this.forceRendering.bind(this);
|
||||||
|
|
||||||
resolve(undefined);
|
resolve(undefined);
|
||||||
});
|
});
|
||||||
@ -590,7 +590,7 @@ var PDFViewerApplication = {
|
|||||||
* @returns {Promise} - Returns the promise, which is resolved when document
|
* @returns {Promise} - Returns the promise, which is resolved when document
|
||||||
* is opened.
|
* is opened.
|
||||||
*/
|
*/
|
||||||
open: function pdfViewOpen(file, args) {
|
open(file, args) {
|
||||||
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
|
if ((typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) &&
|
||||||
(arguments.length > 2 || typeof args === 'number')) {
|
(arguments.length > 2 || typeof args === 'number')) {
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@ -606,7 +606,7 @@ var PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var parameters = Object.create(null), scale;
|
let parameters = Object.create(null), scale;
|
||||||
if (typeof file === 'string') { // URL
|
if (typeof file === 'string') { // URL
|
||||||
this.setTitleUsingUrl(file);
|
this.setTitleUsingUrl(file);
|
||||||
parameters.url = file;
|
parameters.url = file;
|
||||||
@ -622,7 +622,7 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
for (var prop in args) {
|
for (let prop in args) {
|
||||||
parameters[prop] = args[prop];
|
parameters[prop] = args[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -634,54 +634,46 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
this.downloadComplete = false;
|
||||||
self.downloadComplete = false;
|
|
||||||
|
|
||||||
var loadingTask = getDocument(parameters);
|
let loadingTask = getDocument(parameters);
|
||||||
this.pdfLoadingTask = loadingTask;
|
this.pdfLoadingTask = loadingTask;
|
||||||
|
|
||||||
loadingTask.onPassword = function passwordNeeded(updateCallback, reason) {
|
loadingTask.onPassword = (updateCallback, reason) => {
|
||||||
self.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
this.passwordPrompt.setUpdateCallback(updateCallback, reason);
|
||||||
self.passwordPrompt.open();
|
this.passwordPrompt.open();
|
||||||
};
|
};
|
||||||
|
|
||||||
loadingTask.onProgress = function getDocumentProgress(progressData) {
|
loadingTask.onProgress = ({ loaded, total, }) => {
|
||||||
self.progress(progressData.loaded / progressData.total);
|
this.progress(loaded / total);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Listen for unsupported features to trigger the fallback UI.
|
// Listen for unsupported features to trigger the fallback UI.
|
||||||
loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
loadingTask.onUnsupportedFeature = this.fallback.bind(this);
|
||||||
|
|
||||||
return loadingTask.promise.then(
|
return loadingTask.promise.then((pdfDocument) => {
|
||||||
function getDocumentCallback(pdfDocument) {
|
this.load(pdfDocument, scale);
|
||||||
self.load(pdfDocument, scale);
|
}, (exception) => {
|
||||||
},
|
let message = exception && exception.message;
|
||||||
function getDocumentError(exception) {
|
let loadingErrorMessage = mozL10n.get('loading_error', null,
|
||||||
var message = exception && exception.message;
|
'An error occurred while loading the PDF.');
|
||||||
var loadingErrorMessage = mozL10n.get('loading_error', null,
|
|
||||||
'An error occurred while loading the PDF.');
|
|
||||||
|
|
||||||
if (exception instanceof InvalidPDFException) {
|
if (exception instanceof InvalidPDFException) {
|
||||||
// change error message also for other builds
|
// change error message also for other builds
|
||||||
loadingErrorMessage = mozL10n.get('invalid_file_error', null,
|
loadingErrorMessage = mozL10n.get('invalid_file_error', null,
|
||||||
'Invalid or corrupted PDF file.');
|
'Invalid or corrupted PDF file.');
|
||||||
} else if (exception instanceof MissingPDFException) {
|
} else if (exception instanceof MissingPDFException) {
|
||||||
// special message for missing PDF's
|
// special message for missing PDF's
|
||||||
loadingErrorMessage = mozL10n.get('missing_file_error', null,
|
loadingErrorMessage = mozL10n.get('missing_file_error', null,
|
||||||
'Missing PDF file.');
|
'Missing PDF file.');
|
||||||
} else if (exception instanceof UnexpectedResponseException) {
|
} else if (exception instanceof UnexpectedResponseException) {
|
||||||
loadingErrorMessage = mozL10n.get('unexpected_response_error', null,
|
loadingErrorMessage = mozL10n.get('unexpected_response_error', null,
|
||||||
'Unexpected server response.');
|
'Unexpected server response.');
|
||||||
}
|
|
||||||
|
|
||||||
var moreInfo = {
|
|
||||||
message,
|
|
||||||
};
|
|
||||||
self.error(loadingErrorMessage, moreInfo);
|
|
||||||
|
|
||||||
throw new Error(loadingErrorMessage);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
this.error(loadingErrorMessage, { message, });
|
||||||
|
throw new Error(loadingErrorMessage);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
download: function pdfViewDownload() {
|
download: function pdfViewDownload() {
|
||||||
@ -842,24 +834,26 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
load: function pdfViewLoad(pdfDocument, scale) {
|
load(pdfDocument, scale) {
|
||||||
var self = this;
|
|
||||||
scale = scale || UNKNOWN_SCALE;
|
scale = scale || UNKNOWN_SCALE;
|
||||||
|
|
||||||
this.pdfDocument = pdfDocument;
|
this.pdfDocument = pdfDocument;
|
||||||
|
|
||||||
var downloadedPromise = pdfDocument.getDownloadInfo().then(function() {
|
pdfDocument.getDownloadInfo().then(() => {
|
||||||
self.downloadComplete = true;
|
this.downloadComplete = true;
|
||||||
self.loadingBar.hide();
|
this.loadingBar.hide();
|
||||||
|
|
||||||
|
firstPagePromise.then(() => {
|
||||||
|
this.eventBus.dispatch('documentload', { source: this, });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
this.toolbar.setPagesCount(pdfDocument.numPages, false);
|
||||||
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
this.secondaryToolbar.setPagesCount(pdfDocument.numPages);
|
||||||
|
|
||||||
var id = this.documentFingerprint = pdfDocument.fingerprint;
|
let id = this.documentFingerprint = pdfDocument.fingerprint;
|
||||||
var store = this.store = new ViewHistory(id);
|
let store = this.store = new ViewHistory(id);
|
||||||
|
|
||||||
var baseDocumentUrl;
|
let baseDocumentUrl;
|
||||||
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
||||||
baseDocumentUrl = null;
|
baseDocumentUrl = null;
|
||||||
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||||
@ -870,48 +864,44 @@ var PDFViewerApplication = {
|
|||||||
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
this.pdfLinkService.setDocument(pdfDocument, baseDocumentUrl);
|
||||||
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
this.pdfDocumentProperties.setDocument(pdfDocument, this.url);
|
||||||
|
|
||||||
var pdfViewer = this.pdfViewer;
|
let pdfViewer = this.pdfViewer;
|
||||||
pdfViewer.currentScale = scale;
|
pdfViewer.currentScale = scale;
|
||||||
pdfViewer.setDocument(pdfDocument);
|
pdfViewer.setDocument(pdfDocument);
|
||||||
var firstPagePromise = pdfViewer.firstPagePromise;
|
let firstPagePromise = pdfViewer.firstPagePromise;
|
||||||
var pagesPromise = pdfViewer.pagesPromise;
|
let pagesPromise = pdfViewer.pagesPromise;
|
||||||
var onePageRendered = pdfViewer.onePageRendered;
|
let onePageRendered = pdfViewer.onePageRendered;
|
||||||
|
|
||||||
this.pageRotation = 0;
|
this.pageRotation = 0;
|
||||||
|
|
||||||
var pdfThumbnailViewer = this.pdfThumbnailViewer;
|
let pdfThumbnailViewer = this.pdfThumbnailViewer;
|
||||||
pdfThumbnailViewer.setDocument(pdfDocument);
|
pdfThumbnailViewer.setDocument(pdfDocument);
|
||||||
|
|
||||||
firstPagePromise.then((pdfPage) => {
|
firstPagePromise.then((pdfPage) => {
|
||||||
downloadedPromise.then(function () {
|
this.loadingBar.setWidth(this.appConfig.viewerContainer);
|
||||||
self.eventBus.dispatch('documentload', {source: self});
|
|
||||||
});
|
|
||||||
|
|
||||||
self.loadingBar.setWidth(self.appConfig.viewerContainer);
|
if (!PDFJS.disableHistory && !this.isViewerEmbedded) {
|
||||||
|
|
||||||
if (!PDFJS.disableHistory && !self.isViewerEmbedded) {
|
|
||||||
// The browsing history is only enabled when the viewer is standalone,
|
// The browsing history is only enabled when the viewer is standalone,
|
||||||
// i.e. not when it is embedded in a web page.
|
// i.e. not when it is embedded in a web page.
|
||||||
if (!self.viewerPrefs['showPreviousViewOnLoad']) {
|
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
|
||||||
self.pdfHistory.clearHistoryState();
|
this.pdfHistory.clearHistoryState();
|
||||||
}
|
}
|
||||||
self.pdfHistory.initialize(self.documentFingerprint);
|
this.pdfHistory.initialize(this.documentFingerprint);
|
||||||
|
|
||||||
if (self.pdfHistory.initialDestination) {
|
if (this.pdfHistory.initialDestination) {
|
||||||
self.initialDestination = self.pdfHistory.initialDestination;
|
this.initialDestination = this.pdfHistory.initialDestination;
|
||||||
} else if (self.pdfHistory.initialBookmark) {
|
} else if (this.pdfHistory.initialBookmark) {
|
||||||
self.initialBookmark = self.pdfHistory.initialBookmark;
|
this.initialBookmark = this.pdfHistory.initialBookmark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var initialParams = {
|
let initialParams = {
|
||||||
destination: this.initialDestination,
|
destination: this.initialDestination,
|
||||||
bookmark: this.initialBookmark,
|
bookmark: this.initialBookmark,
|
||||||
hash: null,
|
hash: null,
|
||||||
};
|
};
|
||||||
var storedHash = this.viewerPrefs['defaultZoomValue'] ?
|
let storedHash = this.viewerPrefs['defaultZoomValue'] ?
|
||||||
('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
|
('zoom=' + this.viewerPrefs['defaultZoomValue']) : null;
|
||||||
var sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
|
let sidebarView = this.viewerPrefs['sidebarViewOnLoad'];
|
||||||
|
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
|
if (!this.viewerPrefs['showPreviousViewOnLoad']) {
|
||||||
@ -967,12 +957,12 @@ var PDFViewerApplication = {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pdfDocument.getPageLabels().then(function (labels) {
|
pdfDocument.getPageLabels().then((labels) => {
|
||||||
if (!labels || self.viewerPrefs['disablePageLabels']) {
|
if (!labels || this.viewerPrefs['disablePageLabels']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var i = 0, numLabels = labels.length;
|
let i = 0, numLabels = labels.length;
|
||||||
if (numLabels !== self.pagesCount) {
|
if (numLabels !== this.pagesCount) {
|
||||||
console.error('The number of Page Labels does not match ' +
|
console.error('The number of Page Labels does not match ' +
|
||||||
'the number of pages in the document.');
|
'the number of pages in the document.');
|
||||||
return;
|
return;
|
||||||
@ -990,46 +980,46 @@ var PDFViewerApplication = {
|
|||||||
|
|
||||||
// Changing toolbar page display to use labels and we need to set
|
// Changing toolbar page display to use labels and we need to set
|
||||||
// the label of the current page.
|
// the label of the current page.
|
||||||
self.toolbar.setPagesCount(pdfDocument.numPages, true);
|
this.toolbar.setPagesCount(pdfDocument.numPages, true);
|
||||||
self.toolbar.setPageNumber(pdfViewer.currentPageNumber,
|
this.toolbar.setPageNumber(pdfViewer.currentPageNumber,
|
||||||
pdfViewer.currentPageLabel);
|
pdfViewer.currentPageLabel);
|
||||||
});
|
});
|
||||||
|
|
||||||
pagesPromise.then(function() {
|
pagesPromise.then(() => {
|
||||||
if (self.supportsPrinting) {
|
if (!this.supportsPrinting) {
|
||||||
pdfDocument.getJavaScript().then(function(javaScript) {
|
return;
|
||||||
if (javaScript.length) {
|
|
||||||
console.warn('Warning: JavaScript is not supported');
|
|
||||||
self.fallback(UNSUPPORTED_FEATURES.javaScript);
|
|
||||||
}
|
|
||||||
// Hack to support auto printing.
|
|
||||||
var regex = /\bprint\s*\(/;
|
|
||||||
for (var i = 0, ii = javaScript.length; i < ii; i++) {
|
|
||||||
var js = javaScript[i];
|
|
||||||
if (js && regex.test(js)) {
|
|
||||||
setTimeout(function() {
|
|
||||||
window.print();
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
pdfDocument.getJavaScript().then((javaScript) => {
|
||||||
|
if (javaScript.length) {
|
||||||
Promise.all([onePageRendered, animationStarted]).then(function() {
|
console.warn('Warning: JavaScript is not supported');
|
||||||
pdfDocument.getOutline().then(function(outline) {
|
this.fallback(UNSUPPORTED_FEATURES.javaScript);
|
||||||
self.pdfOutlineViewer.render({ outline, });
|
}
|
||||||
});
|
// Hack to support auto printing.
|
||||||
pdfDocument.getAttachments().then(function(attachments) {
|
let regex = /\bprint\s*\(/;
|
||||||
self.pdfAttachmentViewer.render({ attachments, });
|
for (let i = 0, ii = javaScript.length; i < ii; i++) {
|
||||||
|
let js = javaScript[i];
|
||||||
|
if (js && regex.test(js)) {
|
||||||
|
setTimeout(function() {
|
||||||
|
window.print();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
pdfDocument.getMetadata().then(function(data) {
|
Promise.all([onePageRendered, animationStarted]).then(() => {
|
||||||
var info = data.info, metadata = data.metadata;
|
pdfDocument.getOutline().then((outline) => {
|
||||||
self.documentInfo = info;
|
this.pdfOutlineViewer.render({ outline, });
|
||||||
self.metadata = metadata;
|
});
|
||||||
|
pdfDocument.getAttachments().then((attachments) => {
|
||||||
|
this.pdfAttachmentViewer.render({ attachments, });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
pdfDocument.getMetadata().then(({ info, metadata, }) => {
|
||||||
|
this.documentInfo = info;
|
||||||
|
this.metadata = metadata;
|
||||||
|
|
||||||
// Provides some basic debug information
|
// Provides some basic debug information
|
||||||
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
|
console.log('PDF ' + pdfDocument.fingerprint + ' [' +
|
||||||
@ -1038,9 +1028,9 @@ var PDFViewerApplication = {
|
|||||||
' (PDF.js: ' + (version || '-') +
|
' (PDF.js: ' + (version || '-') +
|
||||||
(!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
|
(!PDFJS.disableWebGL ? ' [WebGL]' : '') + ')');
|
||||||
|
|
||||||
var pdfTitle;
|
let pdfTitle;
|
||||||
if (metadata && metadata.has('dc:title')) {
|
if (metadata && metadata.has('dc:title')) {
|
||||||
var title = metadata.get('dc:title');
|
let title = metadata.get('dc:title');
|
||||||
// Ghostscript sometimes return 'Untitled', sets the title to 'Untitled'
|
// Ghostscript sometimes return 'Untitled', sets the title to 'Untitled'
|
||||||
if (title !== 'Untitled') {
|
if (title !== 'Untitled') {
|
||||||
pdfTitle = title;
|
pdfTitle = title;
|
||||||
@ -1052,19 +1042,19 @@ var PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (pdfTitle) {
|
if (pdfTitle) {
|
||||||
self.setTitle(pdfTitle + ' - ' + document.title);
|
this.setTitle(pdfTitle + ' - ' + document.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.IsAcroFormPresent) {
|
if (info.IsAcroFormPresent) {
|
||||||
console.warn('Warning: AcroForm/XFA is not supported');
|
console.warn('Warning: AcroForm/XFA is not supported');
|
||||||
self.fallback(UNSUPPORTED_FEATURES.forms);
|
this.fallback(UNSUPPORTED_FEATURES.forms);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof PDFJSDev !== 'undefined' &&
|
if (typeof PDFJSDev !== 'undefined' &&
|
||||||
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
|
||||||
var versionId = String(info.PDFFormatVersion).slice(-1) | 0;
|
let versionId = String(info.PDFFormatVersion).slice(-1) | 0;
|
||||||
var generatorId = 0;
|
let generatorId = 0;
|
||||||
var KNOWN_GENERATORS = [
|
const KNOWN_GENERATORS = [
|
||||||
'acrobat distiller', 'acrobat pdfwriter', 'adobe livecycle',
|
'acrobat distiller', 'acrobat pdfwriter', 'adobe livecycle',
|
||||||
'adobe pdf library', 'adobe photoshop', 'ghostscript', 'tcpdf',
|
'adobe pdf library', 'adobe photoshop', 'ghostscript', 'tcpdf',
|
||||||
'cairo', 'dvipdfm', 'dvips', 'pdftex', 'pdfkit', 'itext', 'prince',
|
'cairo', 'dvipdfm', 'dvips', 'pdftex', 'pdfkit', 'itext', 'prince',
|
||||||
@ -1080,9 +1070,9 @@ var PDFViewerApplication = {
|
|||||||
return true;
|
return true;
|
||||||
}.bind(null, info.Producer.toLowerCase()));
|
}.bind(null, info.Producer.toLowerCase()));
|
||||||
}
|
}
|
||||||
var formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
let formType = !info.IsAcroFormPresent ? null : info.IsXFAPresent ?
|
||||||
'xfa' : 'acroform';
|
'xfa' : 'acroform';
|
||||||
self.externalServices.reportTelemetry({
|
this.externalServices.reportTelemetry({
|
||||||
type: 'documentInfo',
|
type: 'documentInfo',
|
||||||
version: versionId,
|
version: versionId,
|
||||||
generator: generatorId,
|
generator: generatorId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user