Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fire an internal-only event if Screenshots is in a document that is b…
Browse files Browse the repository at this point in the history
…ackgrounded

Use the Page Visibility API to detect when a given window loses focus.
  • Loading branch information
jaredhirsch committed Feb 6, 2018
1 parent 6d39062 commit 2aed29b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addon/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ this.uicontrol = (function() {
});
primedDocumentHandlers.set("keyup", watchFunction(assertIsTrusted(keyupHandler)));
primedDocumentHandlers.set("keydown", watchFunction(assertIsTrusted(keydownHandler)));
window.document.addEventListener("visibilitychange", visibilityChangeHandler);
window.addEventListener('beforeunload', beforeunloadHandler);
}

Expand Down Expand Up @@ -1026,8 +1027,16 @@ this.uicontrol = (function() {
}
}

function visibilityChangeHandler(event) {
// The document is the event target
if (event.target.hidden) {
sendEvent("internal", "document-hidden");
}
}

function removeHandlers() {
window.removeEventListener("beforeunload", beforeunloadHandler);
window.document.removeEventListener("visibilitychange", visibilityChangeHandler);
for (let {name, doc, handler, useCapture} of registeredDocumentHandlers) {
doc.removeEventListener(name, handler, !!useCapture);
}
Expand Down

0 comments on commit 2aed29b

Please # to comment.