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:
Jonas Jenwald 2018-06-07 13:52:40 +02:00
parent 547f119be6
commit 07d610615c
5 changed files with 34 additions and 53 deletions

View file

@ -428,6 +428,19 @@ class DummyStatTimer {
}
}
function loadScript(src) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = src;
script.onload = resolve;
script.onerror = function() {
reject(new Error(`Cannot load script at: ${script.src}`));
};
(document.head || document.documentElement).appendChild(script);
});
}
export {
PageViewport,
RenderingCancelledException,
@ -440,4 +453,5 @@ export {
DOMSVGFactory,
StatTimer,
DummyStatTimer,
loadScript,
};