github.com/zoomfoo/nomad@v0.8.5-0.20180907175415-f28fd3a1a056/ui/app/mixins/with-route-visibility-detection.js (about)

     1  import Ember from 'ember';
     2  import Mixin from '@ember/object/mixin';
     3  import { assert } from '@ember/debug';
     4  
     5  export default Mixin.create({
     6    visibilityHandler() {
     7      assert('visibilityHandler needs to be overridden in the Route', false);
     8    },
     9  
    10    setupDocumentVisibility: function() {
    11      if (!Ember.testing) {
    12        this.set('_visibilityHandler', this.get('visibilityHandler').bind(this));
    13        document.addEventListener('visibilitychange', this.get('_visibilityHandler'));
    14      }
    15    }.on('activate'),
    16  
    17    removeDocumentVisibility: function() {
    18      if (!Ember.testing) {
    19        document.removeEventListener('visibilitychange', this.get('_visibilityHandler'));
    20      }
    21    }.on('deactivate'),
    22  });