|
@@ -150,6 +150,8 @@ var PDFViewerApplication = {
|
|
|
configure(_pdf.PDFJS);
|
|
|
this.appConfig = appConfig;
|
|
|
return this._readPreferences().then(function () {
|
|
|
+ return _this._parseHashParameters();
|
|
|
+ }).then(function () {
|
|
|
return _this._initializeL10n();
|
|
|
}).then(function () {
|
|
|
return _this._initializeViewerComponents();
|
|
@@ -223,14 +225,67 @@ var PDFViewerApplication = {
|
|
|
viewerPrefs['enablePrintAutoRotate'] = value;
|
|
|
})]).catch(function (reason) {});
|
|
|
},
|
|
|
- _initializeL10n: function _initializeL10n() {
|
|
|
- if (this.viewerPrefs['pdfBugEnabled']) {
|
|
|
+ _parseHashParameters: function _parseHashParameters() {
|
|
|
+ var appConfig = this.appConfig,
|
|
|
+ viewerPrefs = this.viewerPrefs;
|
|
|
+
|
|
|
+ var waitOn = [];
|
|
|
+ if (viewerPrefs['pdfBugEnabled']) {
|
|
|
var hash = document.location.hash.substring(1);
|
|
|
var hashParams = (0, _ui_utils.parseQueryString)(hash);
|
|
|
+ if ('disableworker' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
|
|
|
+ }
|
|
|
+ if ('disablerange' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
|
|
|
+ }
|
|
|
+ if ('disablestream' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
|
|
|
+ }
|
|
|
+ if ('disableautofetch' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
|
|
|
+ }
|
|
|
+ if ('disablefontface' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
|
|
|
+ }
|
|
|
+ if ('disablehistory' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
|
|
|
+ }
|
|
|
+ if ('webgl' in hashParams) {
|
|
|
+ _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
|
|
|
+ }
|
|
|
+ if ('useonlycsszoom' in hashParams) {
|
|
|
+ _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
|
|
|
+ }
|
|
|
+ if ('verbosity' in hashParams) {
|
|
|
+ _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
|
|
|
+ }
|
|
|
+ if ('textlayer' in hashParams) {
|
|
|
+ switch (hashParams['textlayer']) {
|
|
|
+ case 'off':
|
|
|
+ _pdf.PDFJS.disableTextLayer = true;
|
|
|
+ break;
|
|
|
+ case 'visible':
|
|
|
+ case 'shadow':
|
|
|
+ case 'hover':
|
|
|
+ var viewer = appConfig.viewerContainer;
|
|
|
+ viewer.classList.add('textLayer-' + hashParams['textlayer']);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ('pdfbug' in hashParams) {
|
|
|
+ _pdf.PDFJS.pdfBug = true;
|
|
|
+ var pdfBug = hashParams['pdfbug'];
|
|
|
+ var enabled = pdfBug.split(',');
|
|
|
+ waitOn.push(loadAndEnablePDFBug(enabled));
|
|
|
+ }
|
|
|
if ('locale' in hashParams) {
|
|
|
_pdf.PDFJS.locale = hashParams['locale'];
|
|
|
}
|
|
|
}
|
|
|
+ return Promise.all(waitOn);
|
|
|
+ },
|
|
|
+ _initializeL10n: function _initializeL10n() {
|
|
|
this.l10n = this.externalServices.createL10n();
|
|
|
return this.l10n.getDirection().then(function (dir) {
|
|
|
document.getElementsByTagName('html')[0].dir = dir;
|
|
@@ -239,7 +294,9 @@ var PDFViewerApplication = {
|
|
|
_initializeViewerComponents: function _initializeViewerComponents() {
|
|
|
var _this2 = this;
|
|
|
|
|
|
- var appConfig = this.appConfig;
|
|
|
+ var appConfig = this.appConfig,
|
|
|
+ viewerPrefs = this.viewerPrefs;
|
|
|
+
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
_this2.overlayManager = new _overlay_manager.OverlayManager();
|
|
|
var eventBus = appConfig.eventBus || (0, _dom_events.getGlobalEventBus)();
|
|
@@ -260,11 +317,11 @@ var PDFViewerApplication = {
|
|
|
renderingQueue: pdfRenderingQueue,
|
|
|
linkService: pdfLinkService,
|
|
|
downloadManager: downloadManager,
|
|
|
- renderer: _this2.viewerPrefs['renderer'],
|
|
|
+ renderer: viewerPrefs['renderer'],
|
|
|
l10n: _this2.l10n,
|
|
|
- enhanceTextSelection: _this2.viewerPrefs['enhanceTextSelection'],
|
|
|
- renderInteractiveForms: _this2.viewerPrefs['renderInteractiveForms'],
|
|
|
- enablePrintAutoRotate: _this2.viewerPrefs['enablePrintAutoRotate']
|
|
|
+ enhanceTextSelection: viewerPrefs['enhanceTextSelection'],
|
|
|
+ renderInteractiveForms: viewerPrefs['renderInteractiveForms'],
|
|
|
+ enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate']
|
|
|
});
|
|
|
pdfRenderingQueue.setViewer(_this2.pdfViewer);
|
|
|
pdfLinkService.setViewer(_this2.pdfViewer);
|
|
@@ -1059,7 +1116,6 @@ function webViewerInitialized() {
|
|
|
var params = (0, _ui_utils.parseQueryString)(queryString);
|
|
|
file = 'file' in params ? params.file : appConfig.defaultUrl;
|
|
|
validateFileURL(file);
|
|
|
- var waitForBeforeOpening = [];
|
|
|
var fileInput = document.createElement('input');
|
|
|
fileInput.id = appConfig.openFileInputName;
|
|
|
fileInput.className = 'fileInput';
|
|
@@ -1079,56 +1135,6 @@ function webViewerInitialized() {
|
|
|
}
|
|
|
PDFViewerApplication.eventBus.dispatch('fileinputchange', { fileInput: evt.target });
|
|
|
});
|
|
|
- if (PDFViewerApplication.viewerPrefs['pdfBugEnabled']) {
|
|
|
- var hash = document.location.hash.substring(1);
|
|
|
- var hashParams = (0, _ui_utils.parseQueryString)(hash);
|
|
|
- if ('disableworker' in hashParams) {
|
|
|
- _pdf.PDFJS.disableWorker = hashParams['disableworker'] === 'true';
|
|
|
- }
|
|
|
- if ('disablerange' in hashParams) {
|
|
|
- _pdf.PDFJS.disableRange = hashParams['disablerange'] === 'true';
|
|
|
- }
|
|
|
- if ('disablestream' in hashParams) {
|
|
|
- _pdf.PDFJS.disableStream = hashParams['disablestream'] === 'true';
|
|
|
- }
|
|
|
- if ('disableautofetch' in hashParams) {
|
|
|
- _pdf.PDFJS.disableAutoFetch = hashParams['disableautofetch'] === 'true';
|
|
|
- }
|
|
|
- if ('disablefontface' in hashParams) {
|
|
|
- _pdf.PDFJS.disableFontFace = hashParams['disablefontface'] === 'true';
|
|
|
- }
|
|
|
- if ('disablehistory' in hashParams) {
|
|
|
- _pdf.PDFJS.disableHistory = hashParams['disablehistory'] === 'true';
|
|
|
- }
|
|
|
- if ('webgl' in hashParams) {
|
|
|
- _pdf.PDFJS.disableWebGL = hashParams['webgl'] !== 'true';
|
|
|
- }
|
|
|
- if ('useonlycsszoom' in hashParams) {
|
|
|
- _pdf.PDFJS.useOnlyCssZoom = hashParams['useonlycsszoom'] === 'true';
|
|
|
- }
|
|
|
- if ('verbosity' in hashParams) {
|
|
|
- _pdf.PDFJS.verbosity = hashParams['verbosity'] | 0;
|
|
|
- }
|
|
|
- if ('textlayer' in hashParams) {
|
|
|
- switch (hashParams['textlayer']) {
|
|
|
- case 'off':
|
|
|
- _pdf.PDFJS.disableTextLayer = true;
|
|
|
- break;
|
|
|
- case 'visible':
|
|
|
- case 'shadow':
|
|
|
- case 'hover':
|
|
|
- var viewer = appConfig.viewerContainer;
|
|
|
- viewer.classList.add('textLayer-' + hashParams['textlayer']);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if ('pdfbug' in hashParams) {
|
|
|
- _pdf.PDFJS.pdfBug = true;
|
|
|
- var pdfBug = hashParams['pdfbug'];
|
|
|
- var enabled = pdfBug.split(',');
|
|
|
- waitForBeforeOpening.push(loadAndEnablePDFBug(enabled));
|
|
|
- }
|
|
|
- }
|
|
|
if (!PDFViewerApplication.supportsPrinting) {
|
|
|
appConfig.toolbar.print.classList.add('hidden');
|
|
|
appConfig.secondaryToolbar.printButton.classList.add('hidden');
|
|
@@ -1148,10 +1154,10 @@ function webViewerInitialized() {
|
|
|
appConfig.sidebar.toggleButton.addEventListener('click', function () {
|
|
|
PDFViewerApplication.pdfSidebar.toggle();
|
|
|
});
|
|
|
- Promise.all(waitForBeforeOpening).then(function () {
|
|
|
+ Promise.resolve().then(function () {
|
|
|
webViewerOpenFileViaURL(file);
|
|
|
}).catch(function (reason) {
|
|
|
- PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while opening.').then(function (msg) {
|
|
|
+ PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
|
|
|
PDFViewerApplication.error(msg, reason);
|
|
|
});
|
|
|
});
|
|
@@ -1170,9 +1176,7 @@ var webViewerOpenFileViaURL = void 0;
|
|
|
xhr.responseType = 'arraybuffer';
|
|
|
xhr.send();
|
|
|
} catch (ex) {
|
|
|
- PDFViewerApplication.l10n.get('loading_error', null, 'An error occurred while loading the PDF.').then(function (msg) {
|
|
|
- PDFViewerApplication.error(msg, ex);
|
|
|
- });
|
|
|
+ throw ex;
|
|
|
}
|
|
|
return;
|
|
|
}
|