Introduce a AppOptions abstraction in preparation for a complete refactoring of the way that viewer options are handled

The way that various options are handled in the default viewer is currently a bit of a mess (to say the least). Some viewer options reside in the global `PDFJS` object, while others reside in `Preferences`. To make matters worse, some options even exist in both of the two.

Since the goal, with PDF.js version `2.0`, is to reduce our usage of the global `PDFJS` object, we'll instead want pass in the options when initializing the viewer components and when calling API methods (such as `getDocument`).
However given the current state of things in the default viewer, this wouldn't be exactly easy to implement. Hence this patch, which attempts to consolidate the way that viewer (and later API) options are handled by introducing a `AppOptions` singleton that provides *one* centralized way of interacting with the various options in the default viewer.
This commit is contained in:
Jonas Jenwald 2018-02-17 13:22:26 +01:00
parent 5894bfa449
commit 09da99b8a0
2 changed files with 76 additions and 2 deletions

View file

@ -35,9 +35,10 @@ if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
})();
}
let pdfjsWebApp;
let pdfjsWebApp, pdfjsWebAppOptions;
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('PRODUCTION')) {
pdfjsWebApp = require('./app.js');
pdfjsWebAppOptions = require('./app_options.js');
}
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
@ -180,14 +181,17 @@ function webViewerLoad() {
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
Promise.all([
SystemJS.import('pdfjs-web/app'),
SystemJS.import('pdfjs-web/app_options'),
SystemJS.import('pdfjs-web/genericcom'),
SystemJS.import('pdfjs-web/pdf_print_service'),
]).then(function([app, ...otherModules]) {
]).then(function([app, appOptions, ...otherModules]) {
window.PDFViewerApplication = app.PDFViewerApplication;
window.PDFViewerApplicationOptions = appOptions.AppOptions;
app.PDFViewerApplication.run(config);
});
} else {
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
pdfjsWebApp.PDFViewerApplication.run(config);
}
}