open-nomad/ui/app/mixins/with-route-visibility-detec...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
764 B
JavaScript
Raw Normal View History

import Ember from 'ember';
import Mixin from '@ember/object/mixin';
2018-03-08 19:15:43 +00:00
import { assert } from '@ember/debug';
import { on } from '@ember/object/evented';
// eslint-disable-next-line ember/no-new-mixins
export default Mixin.create({
2018-03-08 19:15:43 +00:00
visibilityHandler() {
assert('visibilityHandler needs to be overridden in the Route', false);
},
2021-12-28 14:45:20 +00:00
setupDocumentVisibility: on('activate', function () {
if (!Ember.testing) {
2019-03-26 07:46:44 +00:00
this.set('_visibilityHandler', this.visibilityHandler.bind(this));
document.addEventListener('visibilitychange', this._visibilityHandler);
}
}),
2021-12-28 14:45:20 +00:00
removeDocumentVisibility: on('deactivate', function () {
if (!Ember.testing) {
2019-03-26 07:46:44 +00:00
document.removeEventListener('visibilitychange', this._visibilityHandler);
}
}),
});