Merge pull request #13905 from Snuffleupagus/refactor-loadAndEnablePDFBug

Re-factor `loadAndEnablePDFBug` and `PDFBug.init`
This commit is contained in:
Tim van der Meij 2021-08-21 14:39:57 +02:00 committed by GitHub
commit 50dffdaf55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 16 deletions

View File

@ -377,7 +377,7 @@ const PDFViewerApplication = {
AppOptions.set("fontExtraProperties", true); AppOptions.set("fontExtraProperties", true);
const enabled = params.get("pdfbug").split(","); const enabled = params.get("pdfbug").split(",");
waitOn.push(loadAndEnablePDFBug(enabled)); waitOn.push(initPDFBug(enabled));
} }
// It is not possible to change locale for the (various) extension builds. // It is not possible to change locale for the (various) extension builds.
if ( if (
@ -2139,17 +2139,15 @@ async function loadFakeWorker() {
} }
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) { if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("PRODUCTION")) {
window.pdfjsWorker = await import("pdfjs/core/worker.js"); window.pdfjsWorker = await import("pdfjs/core/worker.js");
return undefined; return;
} }
return loadScript(PDFWorker.workerSrc); await loadScript(PDFWorker.workerSrc);
} }
function loadAndEnablePDFBug(enabledTabs) { async function initPDFBug(enabledTabs) {
const appConfig = PDFViewerApplication.appConfig; const { debuggerScriptPath, mainContainer } = PDFViewerApplication.appConfig;
return loadScript(appConfig.debuggerScriptPath).then(function () { await loadScript(debuggerScriptPath);
PDFBug.enable(enabledTabs); PDFBug.init({ OPS }, mainContainer, enabledTabs);
PDFBug.init({ OPS }, appConfig.mainContainer);
});
} }
function reportPageStatsPDFBug({ pageNumber }) { function reportPageStatsPDFBug({ pageNumber }) {

View File

@ -540,7 +540,8 @@ window.PDFBug = (function PDFBugClosure() {
}); });
} }
}, },
init(pdfjsLib, container) { init(pdfjsLib, container, ids) {
this.enable(ids);
/* /*
* Basic Layout: * Basic Layout:
* PDFBug * PDFBug
@ -589,12 +590,8 @@ window.PDFBug = (function PDFBugClosure() {
tool.init(pdfjsLib); tool.init(pdfjsLib);
} else { } else {
panel.textContent = panel.textContent =
tool.name + `${tool.name} is disabled. To enable add "${tool.id}" to ` +
" is disabled. To enable add " + "the pdfBug parameter and refresh (separate multiple by commas).";
' "' +
tool.id +
'" to the pdfBug parameter ' +
"and refresh (separate multiple by commas).";
} }
buttons.push(panelButton); buttons.push(panelButton);
} }