angular-page-visibility is a tiny lib which integrate Page Visibility API with Angular.
It is exposed as a scope, which $broadcast-s pageFocused and pageBlurred when page is focused / blurred. For old browsers not supporting page visibility API, it ignores it silently.
To use angular-page-visibility, just inject it, then listen to the events.
angular.module('app') .controller('MyController', function($scope, $pageVisibility) { $pageVisibility.$on('pageFocused', function(){ // page is focused }); $pageVisibility.$on('pageBlurred', function(){ // page is blurred }); });- include script: script can be included via
boweror downloading directly
-
via bower:
$ bower install angular-page-visibility -
download directly
<script src="https://raw.githubusercontent.com/mz026/angular_page_visibility/v0.0.3/dist/page_visibility.min.js" type="text/javascript"></script>- include the module:
angular.app('myApp', [ 'angular-page-visibility' ])to test angular-page-visibility, grunt, karma are needed.
$ npm install$ bower install$ npm test
MIT