Skip to content

Instantly share code, notes, and snippets.

@rgsingh
Created March 20, 2016 14:23
Show Gist options
  • Save rgsingh/6e0c7c2ec698eff6ed2c to your computer and use it in GitHub Desktop.
Save rgsingh/6e0c7c2ec698eff6ed2c to your computer and use it in GitHub Desktop.
jQuery autologout
$(document).ready(function () {
function defineCommonLib() {
var COMMON_LIB = {};
COMMON_LIB.FALSE_FUNCTION = function () {
return false;
};
COMMON_LIB.init = function () {};
COMMON_LIB.logout = function () {
$.ajax({
url : $('#contextPath').val() + "/j_spring_security_logout",
cache : false,
success : function (html) {
window.location = $('#contextPath').val() + '/login.html';
}
});
}
return COMMON_LIB;
}
if (typeof(COMMON_LIB) === 'undefined') {
window.COMMON_LIB = defineCommonLib();
COMMON_LIB.init();
} else {
console.log("COMMON_LIB already defined.");
}
var timer,
handleTimer = function (e) {
var maxTimeout = 1 * 60 * 1000;
console.log(e.type + " fired");
window.clearTimeout(timer);
timer = window.setTimeout(COMMON_LIB.logout, maxTimeout);
};
$(document).bind('keyup keypress blur change', handleTimer);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment