Created
March 20, 2016 14:23
-
-
Save rgsingh/6e0c7c2ec698eff6ed2c to your computer and use it in GitHub Desktop.
jQuery autologout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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