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