Skip to content

Instantly share code, notes, and snippets.

@logicaroma
Last active August 29, 2015 13:56
Show Gist options
  • Save logicaroma/9211136 to your computer and use it in GitHub Desktop.
Save logicaroma/9211136 to your computer and use it in GitHub Desktop.
var handleVisibility = function(){
if ( document.hidden ) {
// The page is hidden.
Store.set('app:hidden', Date.now());
} else if( Store.has('rabobank:app:hidden') ){
// The page is visible and has a timestamp saved.
var timestamp = new Date(Store.get('app:hidden')),
maxTimePassedAllowed = 1000 * 60 * 2,
isPast = (new Date().getTime() - timestamp < maxTimePassedAllowed) ? false : true;
if( isPast ){
services.logOff();
}
}
};
document.addEventListener('visibilitychange', handleVisibility);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment