diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:44 +0300 |
commit | 874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (patch) | |
tree | 637ee9f2da5e251bc08ebf3e972209d51966bf7c /app/assets/javascripts/smart_interval.js | |
parent | 2e4c4055181eec9186458dd5dd3219c937032ec7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/smart_interval.js')
-rw-r--r-- | app/assets/javascripts/smart_interval.js | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/app/assets/javascripts/smart_interval.js b/app/assets/javascripts/smart_interval.js index 8ca590123ae..0e52d2d8010 100644 --- a/app/assets/javascripts/smart_interval.js +++ b/app/assets/javascripts/smart_interval.js @@ -33,7 +33,7 @@ export default class SmartInterval { this.state = { intervalId: null, currentInterval: this.cfg.startingInterval, - pageVisibility: 'visible', + pagevisibile: true, }; this.initInterval(); @@ -91,8 +91,10 @@ export default class SmartInterval { } destroy() { + document.removeEventListener('visibilitychange', this.onVisibilityChange); + window.removeEventListener('blur', this.onWindowVisibilityChange); + window.removeEventListener('focus', this.onWindowVisibilityChange); this.cancel(); - document.removeEventListener('visibilitychange', this.handleVisibilityChange); $(document) .off('visibilitychange') .off('beforeunload'); @@ -124,9 +126,21 @@ export default class SmartInterval { }); } + onWindowVisibilityChange(e) { + this.state.pagevisibile = e.type === 'focus'; + this.handleVisibilityChange(); + } + + onVisibilityChange(e) { + this.state.pagevisibile = e.target.visibilityState === 'visible'; + this.handleVisibilityChange(); + } + initVisibilityChangeHandling() { - // cancel interval when tab no longer shown (prevents cached pages from polling) - document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this)); + // cancel interval when tab or window is no longer shown (prevents cached pages from polling) + document.addEventListener('visibilitychange', this.onVisibilityChange.bind(this)); + window.addEventListener('blur', this.onWindowVisibilityChange.bind(this)); + window.addEventListener('focus', this.onWindowVisibilityChange.bind(this)); } initPageUnloadHandling() { @@ -135,8 +149,7 @@ export default class SmartInterval { $(document).on('beforeunload', () => this.cancel()); } - handleVisibilityChange(e) { - this.state.pageVisibility = e.target.visibilityState; + handleVisibilityChange() { const intervalAction = this.isPageVisible() ? this.onVisibilityVisible : this.onVisibilityHidden; @@ -166,7 +179,7 @@ export default class SmartInterval { } isPageVisible() { - return this.state.pageVisibility === 'visible'; + return this.state.pagevisibile; } stopTimer() { |