mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 06:23:39 +08:00
37 lines
701 B
Plaintext
37 lines
701 B
Plaintext
|
function gotFocus() {
|
||
|
if (!Discourse.get("hasFocus")) {
|
||
|
Discourse.setProperties({ hasFocus: true, notify: false });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function lostFocus() {
|
||
|
if (Discourse.get("hasFocus")) {
|
||
|
Discourse.set("hasFocus", false);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
let onchange;
|
||
|
|
||
|
export default Ember.Mixin.create({
|
||
|
ready() {
|
||
|
this._super(...arguments);
|
||
|
|
||
|
onchange = () => {
|
||
|
document.visibilityState === "hidden" ? lostFocus() : gotFocus();
|
||
|
};
|
||
|
|
||
|
// Default to true
|
||
|
Discourse.set("hasFocus", true);
|
||
|
|
||
|
document.addEventListener("visibilitychange", onchange);
|
||
|
},
|
||
|
|
||
|
reset() {
|
||
|
this._super(...arguments);
|
||
|
|
||
|
document.removeEventListener("visibilitychange", onchange);
|
||
|
|
||
|
onchange = undefined;
|
||
|
}
|
||
|
});
|