open-nomad/ui/app/mixins/with-route-visibility-detection.js
Buck Doyle 9b2fb14e51
UI: Update Ember to 3.12 LTS (#6419)
This is mostly deprecation fixes and blueprint changes. There
are some dependency updates too; the changes to Ember
Basic Dropdown necessitated changing it to angle bracket
component invocation. The conversion of the rest of the
templates will happen separately.
2019-10-15 13:32:58 -05:00

24 lines
714 B
JavaScript

import Ember from 'ember';
import Mixin from '@ember/object/mixin';
import { assert } from '@ember/debug';
import { on } from '@ember/object/evented';
export default Mixin.create({
visibilityHandler() {
assert('visibilityHandler needs to be overridden in the Route', false);
},
setupDocumentVisibility: on('activate', function() {
if (!Ember.testing) {
this.set('_visibilityHandler', this.visibilityHandler.bind(this));
document.addEventListener('visibilitychange', this._visibilityHandler);
}
}),
removeDocumentVisibility: on('deactivate', function() {
if (!Ember.testing) {
document.removeEventListener('visibilitychange', this._visibilityHandler);
}
}),
});