mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-21 23:58:07 +02:00
Move, and modernize, Util.loadScript
from src/shared/util.js
to src/display/dom_utils.js
Not only is the `Util.loadScript` helper function unused on the Worker side, even trying to use it there would throw an Error (since `document` isn't defined/available in Workers). Hence this helper function is moved, and its code modernized slightly by having it return a Promise rather than needing a callback function. Finally, to reduced code duplication, the "new" loadScript function is exported and used in the viewer.
This commit is contained in:
parent
547f119be6
commit
07d610615c
5 changed files with 34 additions and 53 deletions
51
web/app.js
51
web/app.js
|
@ -22,8 +22,8 @@ import {
|
|||
} from './ui_utils';
|
||||
import {
|
||||
build, createBlob, getDocument, getFilenameFromUrl, GlobalWorkerOptions,
|
||||
InvalidPDFException, LinkTarget, MissingPDFException, OPS, PDFWorker, shadow,
|
||||
UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||
InvalidPDFException, LinkTarget, loadScript, MissingPDFException, OPS,
|
||||
PDFWorker, shadow, UnexpectedResponseException, UNSUPPORTED_FEATURES, version
|
||||
} from 'pdfjs-lib';
|
||||
import { CursorTool, PDFCursorTools } from './pdf_cursor_tools';
|
||||
import { PDFRenderingQueue, RenderingStates } from './pdf_rendering_queue';
|
||||
|
@ -1551,11 +1551,11 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
|
|||
}
|
||||
|
||||
function loadFakeWorker() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!GlobalWorkerOptions.workerSrc) {
|
||||
GlobalWorkerOptions.workerSrc = AppOptions.get('workerSrc');
|
||||
}
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
if (!GlobalWorkerOptions.workerSrc) {
|
||||
GlobalWorkerOptions.workerSrc = AppOptions.get('workerSrc');
|
||||
}
|
||||
if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION')) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (typeof SystemJS === 'object') {
|
||||
SystemJS.import('pdfjs/core/worker').then((worker) => {
|
||||
window.pdfjsWorker = worker;
|
||||
|
@ -1568,37 +1568,18 @@ function loadFakeWorker() {
|
|||
reject(new Error(
|
||||
'SystemJS or CommonJS must be used to load fake worker.'));
|
||||
}
|
||||
} else {
|
||||
let script = document.createElement('script');
|
||||
script.src = PDFWorker.getWorkerSrc();
|
||||
script.onload = function() {
|
||||
resolve();
|
||||
};
|
||||
script.onerror = function() {
|
||||
reject(new Error(`Cannot load fake worker at: ${script.src}`));
|
||||
};
|
||||
(document.head || document.documentElement).appendChild(script);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return loadScript(PDFWorker.getWorkerSrc());
|
||||
}
|
||||
|
||||
function loadAndEnablePDFBug(enabledTabs) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
let appConfig = PDFViewerApplication.appConfig;
|
||||
let script = document.createElement('script');
|
||||
script.src = appConfig.debuggerScriptPath;
|
||||
script.onload = function () {
|
||||
PDFBug.enable(enabledTabs);
|
||||
PDFBug.init({
|
||||
OPS,
|
||||
}, appConfig.mainContainer);
|
||||
resolve();
|
||||
};
|
||||
script.onerror = function () {
|
||||
reject(new Error('Cannot load debugger at ' + script.src));
|
||||
};
|
||||
(document.getElementsByTagName('head')[0] || document.body).
|
||||
appendChild(script);
|
||||
let appConfig = PDFViewerApplication.appConfig;
|
||||
return loadScript(appConfig.debuggerScriptPath).then(function() {
|
||||
PDFBug.enable(enabledTabs);
|
||||
PDFBug.init({
|
||||
OPS,
|
||||
}, appConfig.mainContainer);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue