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

18 lines
592 B
JavaScript
Raw Normal View History

import Mixin from '@ember/object/mixin';
2018-03-08 19:15:43 +00:00
import { assert } from '@ember/debug';
export default Mixin.create({
2018-03-08 19:15:43 +00:00
visibilityHandler() {
assert('visibilityHandler needs to be overridden in the Route', false);
},
setupDocumentVisibility: function() {
this.set('_visibilityHandler', this.get('visibilityHandler').bind(this));
document.addEventListener('visibilitychange', this.get('_visibilityHandler'));
}.on('activate'),
removeDocumentVisibility: function() {
document.removeEventListener('visibilitychange', this.get('_visibilityHandler'));
}.on('deactivate'),
});