mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 00:23:25 +02:00
27 lines
698 B
JavaScript
27 lines
698 B
JavaScript
module.exports = function pageVisibilityDirective($document, $rootScope) {
|
|
return {
|
|
restrict: 'A',
|
|
link: function (scope) {
|
|
function pageVisibilityChanged() {
|
|
if (document.hidden) {
|
|
$rootScope.$broadcast('pageHidden')
|
|
} else {
|
|
$rootScope.$broadcast('pageVisible')
|
|
// Application is visible to the user
|
|
// Adjust polling rates and display update for active display mode
|
|
}
|
|
}
|
|
|
|
document.addEventListener(
|
|
'visibilitychange'
|
|
, pageVisibilityChanged
|
|
, false
|
|
)
|
|
|
|
scope.$on('$destroy', function () {
|
|
angular.element(document).unbind('visibilitychange');
|
|
})
|
|
}
|
|
}
|
|
}
|