diff --git a/web/ui_utils.js b/web/ui_utils.js index 17cad2c82f6a36..18b4c81552318f 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -756,6 +756,38 @@ const animationStarted = new Promise(function(resolve) { window.requestAnimationFrame(resolve); }); +/** + * NOTE: Only used to support various PDF viewer tests in `mozilla-central`. + */ +function dispatchDOMEvent(eventName, args = null) { + if ( + typeof PDFJSDev !== "undefined" && + !PDFJSDev.test("MOZCENTRAL || TESTING") + ) { + console.error( + "The `eventBusDispatchToDOM` option/preference is deprecated, " + + "use a manually created EventBus instance instead." + ); + } + const details = Object.create(null); + if (args && args.length > 0) { + const obj = args[0]; + for (const key in obj) { + const value = obj[key]; + if (key === "source") { + if (value === window || value === document) { + return; // No need to re-dispatch (already) global events. + } + continue; // Ignore the `source` property. + } + details[key] = value; + } + } + const event = document.createEvent("CustomEvent"); + event.initCustomEvent(eventName, true, true, details); + document.dispatchEvent(event); +} + /** * Simple event bus for an application. Listeners are attached using the `on` * and `off` methods. To raise an event, the `dispatch` method shall be used. @@ -787,7 +819,7 @@ class EventBus { if (!eventListeners || eventListeners.length === 0) { if (this._dispatchToDOM) { const args = Array.prototype.slice.call(arguments, 1); - this._dispatchDOMEvent(eventName, args); + dispatchDOMEvent(eventName, args); } return; } @@ -815,7 +847,7 @@ class EventBus { externalListeners = null; } if (this._dispatchToDOM) { - this._dispatchDOMEvent(eventName, args); + dispatchDOMEvent(eventName, args); } } @@ -848,29 +880,6 @@ class EventBus { } } } - - /** - * @private - */ - _dispatchDOMEvent(eventName, args = null) { - const details = Object.create(null); - if (args && args.length > 0) { - const obj = args[0]; - for (const key in obj) { - const value = obj[key]; - if (key === "source") { - if (value === window || value === document) { - return; // No need to re-dispatch (already) global events. - } - continue; // Ignore the `source` property. - } - details[key] = value; - } - } - const event = document.createEvent("CustomEvent"); - event.initCustomEvent(eventName, true, true, details); - document.dispatchEvent(event); - } } let globalEventBus = null;