//######
//## This work is licensed under the Creative Commons Attribution-Share Alike 3.0
//## United States License. To view a copy of this license,
//## visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter
//## to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
//######
(function($){
$.fn.idleTimeout = function(options) {
var defaults = {
inactivity: 1200000, //20 Minutes
noconfirm: 10000, //10 Seconds
sessionAlive: 30000, //10 Minutes
redirect_url: '/js_sandbox/',
click_reset: true,
keydown_reset: true,
mousemove_reset: true,
wheel_reset: true,
DOMMouseScroll_reset: true,
mousewheel_reset: true,
mousedown_reset: true,
touchstart_reset:true,
touchmove_reset:true,
MSPointerDown_reset: true,
MSPointerMove_reset: true,
alive_url: '/js_sandbox/',
logout_url: '/js_sandbox/',
showDialog: true,
dialogTitle: 'Auto Logout',
dialogText: 'You are about to be signed out due to inactivity',
dialogButton: 'Stay Logged In',
secondsText: "Seconds remaining",
showTimer: true
}
//##############################
//## Private Variables
//##############################
var opts = $.extend(defaults, options);
var liveTimeout, confTimeout, sessionTimeout;
var modal = "<div id='modal_pop'><p>" + opts.dialogText + ".</p><p>" + opts.secondsText + " <span id='counter'></span><p></div>";
var interval;
var modalIsOpen = false;
//##############################
//## Private Functions
//##############################
var start_liveTimeout = function()
{
if (modalIsOpen)
{
return;
}
clearTimeout(liveTimeout);
clearTimeout(confTimeout);
liveTimeout = setTimeout(logout, opts.inactivity);
if(opts.sessionAlive)
{
clearTimeout(sessionTimeout);
sessionTimeout = setTimeout(keep_session, opts.sessionAlive);
}
}
var logout = function()
{
var my_dialog;
var buttonsOpts = {};
confTimeout = setTimeout(redirect, opts.noconfirm);
buttonsOpts[opts.dialogButton] = function(){
my_dialog.dialog('close');
stay_logged_in();
my_dialog = null;
$("#counter").remove();
}
if(opts.showDialog)
{
my_dialog = $(modal).dialog({
buttons: buttonsOpts,
modal: true,
title: opts.dialogTitle,
open: function (event, ui)
{
modalIsOpen = true;
if (opts.showTimer) {
showSeconds();
}
},
close: function (event, ui)
{
modalIsOpen = false;
}
});
}
}
function showSeconds() {
var s = opts.noconfirm/1000;
interval = window.setInterval(function () {
if (s == 0) {
window.clearInterval(interval);
}
s--;
var counterElement = document.getElementById("counter");
if (counterElement != null) {
counterElement.innerHTML = s;
}
}, 983);
}
//###### //## This work is licensed under the Creative Commons Attribution-Share Alike 3.0 //## United States License. To view a copy of this license, //## visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter //## to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. //######
(function($){ $.fn.idleTimeout = function(options) { var defaults = { inactivity: 1200000, //20 Minutes noconfirm: 10000, //10 Seconds sessionAlive: 30000, //10 Minutes redirect_url: '/js_sandbox/', click_reset: true, keydown_reset: true, mousemove_reset: true, wheel_reset: true, DOMMouseScroll_reset: true, mousewheel_reset: true, mousedown_reset: true, touchstart_reset:true, touchmove_reset:true, MSPointerDown_reset: true, MSPointerMove_reset: true, alive_url: '/js_sandbox/', logout_url: '/js_sandbox/', showDialog: true, dialogTitle: 'Auto Logout', dialogText: 'You are about to be signed out due to inactivity', dialogButton: 'Stay Logged In', secondsText: "Seconds remaining", showTimer: true }
var redirect = function() { if(opts.logout_url) { $.get(opts.logout_url); } window.location.href = opts.redirect_url; }
}; })(jQuery);