mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Add general support for re-dispatching events, on EventBus
instances, to the DOM
This patch is the first step to be able to eventually get rid of the `attachDOMEventsToEventBus` function, by allowing `EventBus` instances to simply re-dispatch most[1] events to the DOM. Note that the re-dispatching is purposely implemented to occur *after* all registered `EventBus` listeners have been serviced, to prevent the ordering issues that necessitated the duplicated page/scale-change events. The DOM events are currently necessary for the `mozilla-central` tests, see https://hg.mozilla.org/mozilla-central/file/tip/browser/extensions/pdfjs/test, and perhaps also for custom deployments of the PDF.js default viewer. Once this have landed, and been successfully uplifted to `mozilla-central`, I intent to submit a patch to update the test-code to utilize the new preference. This will thus, eventually, make it possible to remove the `attachDOMEventsToEventBus` functionality. *Please note:* I've successfully ran all `mozilla-central` tests locally, with these patches applied. --- [1] The exception being events that originated on the `window` or `document`, since those are already globally available anyway.
This commit is contained in:
parent
7bc4bfcc8b
commit
0b1f41c5b3
7 changed files with 91 additions and 7 deletions
|
@ -262,6 +262,45 @@ describe('ui_utils', function() {
|
|||
eventBus.dispatch('test');
|
||||
expect(count).toEqual(2);
|
||||
});
|
||||
|
||||
it('should not, by default, re-dispatch to DOM', function(done) {
|
||||
if (isNodeJS()) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
const eventBus = new EventBus();
|
||||
let count = 0;
|
||||
eventBus.on('test', function() {
|
||||
count++;
|
||||
});
|
||||
document.addEventListener('test', function() {
|
||||
count++;
|
||||
});
|
||||
eventBus.dispatch('test');
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
expect(count).toEqual(1);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should re-dispatch to DOM', function(done) {
|
||||
if (isNodeJS()) {
|
||||
pending('Document in not supported in Node.js.');
|
||||
}
|
||||
const eventBus = new EventBus({ dispatchToDOM: true, });
|
||||
let count = 0;
|
||||
eventBus.on('test', function() {
|
||||
count++;
|
||||
});
|
||||
document.addEventListener('test', function() {
|
||||
count++;
|
||||
});
|
||||
eventBus.dispatch('test');
|
||||
|
||||
Promise.resolve().then(() => {
|
||||
expect(count).toEqual(2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidRotation', function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue