Skip to content

Commit

Permalink
Merge pull request #12801 from Snuffleupagus/FirefoxCom-document-list…
Browse files Browse the repository at this point in the history
…ener

Modernize the `FirefoxCom.request` method
  • Loading branch information
timvandermeij authored Jan 1, 2021
2 parents f305e04 + 8b3b542 commit 0432154
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions web/firefoxcom.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const FirefoxCom = (function FirefoxComClosure() {
});
request.dispatchEvent(sender);
const response = sender.detail.response;
document.documentElement.removeChild(request);
request.remove();

return response;
},

Expand All @@ -63,15 +64,16 @@ const FirefoxCom = (function FirefoxComClosure() {
request(action, data, callback) {
const request = document.createTextNode("");
if (callback) {
document.addEventListener("pdf.js.response", function listener(event) {
const node = event.target;
const response = event.detail.response;

document.documentElement.removeChild(node);

document.removeEventListener("pdf.js.response", listener);
return callback(response);
});
request.addEventListener(
"pdf.js.response",
event => {
const response = event.detail.response;
event.target.remove();

callback(response);
},
{ once: true }
);
}
document.documentElement.appendChild(request);

Expand Down

0 comments on commit 0432154

Please sign in to comment.