diff --git a/web/ui_utils.js b/web/ui_utils.js index c067dd420d3de..7c615f2f82247 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -13,8 +13,6 @@ * limitations under the License. */ -import { createPromiseCapability } from 'pdfjs-lib'; - const CSS_UNITS = 96.0 / 72.0; const DEFAULT_SCALE_VALUE = 'auto'; const DEFAULT_SCALE = 1.0; @@ -634,37 +632,35 @@ const WaitOnType = { * @returns {Promise} A promise that is resolved with a {WaitOnType} value. */ function waitOnEventOrTimeout({ target, name, delay = 0, }) { - if (typeof target !== 'object' || !(name && typeof name === 'string') || - !(Number.isInteger(delay) && delay >= 0)) { - return Promise.reject( - new Error('waitOnEventOrTimeout - invalid parameters.')); - } - let capability = createPromiseCapability(); - - function handler(type) { - if (target instanceof EventBus) { - target.off(name, eventHandler); - } else { - target.removeEventListener(name, eventHandler); + return new Promise(function(resolve, reject) { + if (typeof target !== 'object' || !(name && typeof name === 'string') || + !(Number.isInteger(delay) && delay >= 0)) { + throw new Error('waitOnEventOrTimeout - invalid parameters.'); } - if (timeout) { - clearTimeout(timeout); - } - capability.resolve(type); - } + function handler(type) { + if (target instanceof EventBus) { + target.off(name, eventHandler); + } else { + target.removeEventListener(name, eventHandler); + } - let eventHandler = handler.bind(null, WaitOnType.EVENT); - if (target instanceof EventBus) { - target.on(name, eventHandler); - } else { - target.addEventListener(name, eventHandler); - } + if (timeout) { + clearTimeout(timeout); + } + resolve(type); + } - let timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); - let timeout = setTimeout(timeoutHandler, delay); + const eventHandler = handler.bind(null, WaitOnType.EVENT); + if (target instanceof EventBus) { + target.on(name, eventHandler); + } else { + target.addEventListener(name, eventHandler); + } - return capability.promise; + const timeoutHandler = handler.bind(null, WaitOnType.TIMEOUT); + let timeout = setTimeout(timeoutHandler, delay); + }); } /**