Merge pull request #10318 from Snuffleupagus/disablePreferences
In `GENERIC` builds, dispatch a "webviewerloaded" event (from the `webViewerLoad` function) before initializing the viewer
This commit is contained in:
commit
c91f437eaa
19
web/app.js
19
web/app.js
@ -169,21 +169,14 @@ let PDFViewerApplication = {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
async _readPreferences() {
|
async _readPreferences() {
|
||||||
// A subset of the Preferences that `AppOptions`, for compatibility reasons,
|
if (AppOptions.get('disablePreferences') === true) {
|
||||||
// is allowed to override if the `AppOptions` values matches the ones below.
|
// Give custom implementations of the default viewer a simpler way to
|
||||||
const OVERRIDES = {
|
// opt-out of having the `Preferences` override existing `AppOptions`.
|
||||||
disableFontFace: true,
|
return;
|
||||||
disableRange: true,
|
}
|
||||||
disableStream: true,
|
|
||||||
textLayerMode: TextLayerMode.DISABLE,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const prefs = await this.preferences.getAll();
|
const prefs = await this.preferences.getAll();
|
||||||
for (let name in prefs) {
|
for (const name in prefs) {
|
||||||
if ((name in OVERRIDES) && AppOptions.get(name) === OVERRIDES[name]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
AppOptions.set(name, prefs[name]);
|
AppOptions.set(name, prefs[name]);
|
||||||
}
|
}
|
||||||
} catch (reason) { }
|
} catch (reason) { }
|
||||||
|
@ -58,6 +58,9 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER,
|
kind: OptionKind.VIEWER,
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* The `disablePreferences` is, conditionally, defined below.
|
||||||
|
*/
|
||||||
enablePrintAutoRotate: {
|
enablePrintAutoRotate: {
|
||||||
/** @type {boolean} */
|
/** @type {boolean} */
|
||||||
value: false,
|
value: false,
|
||||||
@ -218,6 +221,11 @@ const defaultOptions = {
|
|||||||
};
|
};
|
||||||
if (typeof PDFJSDev === 'undefined' ||
|
if (typeof PDFJSDev === 'undefined' ||
|
||||||
PDFJSDev.test('!PRODUCTION || GENERIC')) {
|
PDFJSDev.test('!PRODUCTION || GENERIC')) {
|
||||||
|
defaultOptions.disablePreferences = {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: false,
|
||||||
|
kind: OptionKind.VIEWER,
|
||||||
|
};
|
||||||
defaultOptions.locale = {
|
defaultOptions.locale = {
|
||||||
/** @type {string} */
|
/** @type {string} */
|
||||||
value: (typeof navigator !== 'undefined' ? navigator.language : 'en-US'),
|
value: (typeof navigator !== 'undefined' ? navigator.language : 'en-US'),
|
||||||
|
@ -203,6 +203,16 @@ function webViewerLoad() {
|
|||||||
|
|
||||||
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
|
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
|
||||||
window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
|
window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
|
||||||
|
|
||||||
|
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('GENERIC')) {
|
||||||
|
// Give custom implementations of the default viewer a simpler way to
|
||||||
|
// set various `AppOptions`, by dispatching an event once all viewer
|
||||||
|
// files are loaded but *before* the viewer initialization has run.
|
||||||
|
const event = document.createEvent('CustomEvent');
|
||||||
|
event.initCustomEvent('webviewerloaded', true, true, {});
|
||||||
|
document.dispatchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
pdfjsWebApp.PDFViewerApplication.run(config);
|
pdfjsWebApp.PDFViewerApplication.run(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user