Skip to content

Instantly share code, notes, and snippets.

@nickcoyne
Created February 23, 2017 00:33
Show Gist options
  • Save nickcoyne/16450cd364e40c0b984122ae233c4ffb to your computer and use it in GitHub Desktop.
Save nickcoyne/16450cd364e40c0b984122ae233c4ffb to your computer and use it in GitHub Desktop.
var timoutWarning = 60000; // Display warning in 1 min.
var timoutNow = 60000; // Warning has been shown, give the user 1 minute to interact
var logoutUrl = '/timeout'; // URL to logout page.
var warningTimer;
var timeoutTimer;
// Start warning timer.
function StartWarningTimer() {
warningTimer = setTimeout("IdleWarning()", timoutWarning);
}
// Reset timers.
function ResetTimeOutTimer() {
clearTimeout(timeoutTimer);
StartWarningTimer();
BetterModals.closeModal($("#modalLogoutWarning"));
}
// Show idle timeout warning dialog.
function IdleWarning() {
clearTimeout(warningTimer);
timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
BetterModals.showModal($("#modalLogoutWarning"));
}
// Logout the user.
function IdleTimeout() {
window.location = logoutUrl;
}
StartWarningTimer();
// Button click handlers
// close page
$(document).on("click", ".js-temp-user-logout", function() {
IdleTimeout();
});
// continue
$(document).on("click", ".js-temp-user-continue", function() {
ResetTimeOutTimer();
});
// we should reset the timer when
// submitting responses
// switching tabs
// we should suspend the timer
// while watching video
// we should restart the timer
// when stopping video play
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment