1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Remove the eventBusDispatchToDOM option/preference, and thus the general ability to dispatch "viewer components" events to the DOM

This functionality was only added to the default viewer for backwards compatibility and to support the various PDF viewer tests in mozilla-central, with the intention to eventually remove it completely.
While the different mozilla-central tests cannot be *easily* converted from DOM events, it's however possible to limit that functionality to only MOZCENTRAL builds *and* when tests are running.

Rather than depending of the re-dispatching of internal events to the DOM, the default viewer can instead be used in e.g. the following way:
```javascript
document.addEventListener("webviewerloaded", function() {
  PDFViewerApplication.initializedPromise.then(function() {
    // The viewer has now been initialized, and its properties can be accessed.

    PDFViewerApplication.eventBus.on("pagerendered", function(event) {
      console.log("Has rendered page number: " + event.pageNumber);
    });
  });
});
```
This commit is contained in:
Jonas Jenwald 2020-02-27 15:25:33 +01:00
parent 7fd5f2dd61
commit 664b79abe0
6 changed files with 29 additions and 74 deletions

View file

@ -312,7 +312,7 @@ describe("ui_utils", function() {
expect(count).toEqual(2);
});
it("should not, by default, re-dispatch to DOM", function(done) {
it("should not re-dispatch to DOM", function(done) {
if (isNodeJS) {
pending("Document in not supported in Node.js.");
}
@ -329,54 +329,6 @@ describe("ui_utils", function() {
eventBus.dispatch("test");
Promise.resolve().then(() => {
expect(count).toEqual(1);
document.removeEventListener("test", domEventListener);
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(evt) {
expect(evt).toEqual(undefined);
count++;
});
function domEventListener(evt) {
expect(evt.detail).toEqual({});
count++;
}
document.addEventListener("test", domEventListener);
eventBus.dispatch("test");
Promise.resolve().then(() => {
expect(count).toEqual(2);
document.removeEventListener("test", domEventListener);
done();
});
});
it("should re-dispatch to DOM, with arguments (without internal listeners)", function(done) {
if (isNodeJS) {
pending("Document in not supported in Node.js.");
}
const eventBus = new EventBus({ dispatchToDOM: true });
let count = 0;
function domEventListener(evt) {
expect(evt.detail).toEqual({ abc: 123 });
count++;
}
document.addEventListener("test", domEventListener);
eventBus.dispatch("test", {
abc: 123,
});
Promise.resolve().then(() => {
expect(count).toEqual(1);