Do not request live information in case tab is not active #6625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
refs #6545
At first I used the window.blur/focus events but noticed it would also
stop refreshing if tab is active but browser window is not active. I
reckon many people might want to leave the browser open in one window
and follow the live visitors while working on something else. That's
why we should use the page visibility API which is supported by most
browsers (I think not in <= IE9). I used a different library first
but noticed it adds many event listeners like mousemove etc and it can
make Piwik slow so used the visibility.js library in the end. If someone
uses an old browser nothing will change compared to before so that
should be ok. In a next version we could initiate a refresh immediately
once the browser tab becomes active again.