jQuery session timeout countdown with jQueryUI dialog

Very nice jQuery session timeout countdown example with the use of the jQuery idleTimer plugin.

Here’s my example with the jQueryUI dialog as the warning.

var idleTime = 2000; // number of miliseconds until the user is considered idle
var initialSessionTimeoutMessage = 'Your session will expire in <span id="sessionTimeoutCountdown"></span> seconds.<br /><br />Click on <b>OK</b> to continue your session.';
var sessionTimeoutCountdownId = 'sessionTimeoutCountdown';
var redirectAfter = 10; // number of seconds to wait before redirecting the user
var redirectTo = ' http://regretless.com/2010/02/14/jquery-session-timeout-countdown/'; // URL to relocate the user to once they have timed out
var keepAliveURL = 'keepAlive.php'; // URL to call to keep the session alive
var expiredMessage = 'Your session has expired.  You are being logged out for security reasons.'; // message to show user when the countdown reaches 0
var running = false; // var to check if the countdown is running
var timer; // reference to the setInterval timer so it can be stopped
$(document).ready(function() {
	// create the warning window and set autoOpen to false
	var sessionTimeoutWarningDialog = $("#sessionTimeoutWarning");
	$(sessionTimeoutWarningDialog).html(initialSessionTimeoutMessage);
	$(sessionTimeoutWarningDialog).dialog({
		title: 'Session Expiration Warning',
		autoOpen: false,	// set this to false so we can manually open it
		closeOnEscape: false,
		draggable: false,
		width: 460,
		minHeight: 50,
		modal: true,
		beforeclose: function() { // bind to beforeclose so if the user clicks on the "X" or escape to close the dialog, it will work too
			// stop the timer
			clearInterval(timer);

			// stop countdown
			running = false;

			// ajax call to keep the server-side session alive
			$.ajax({
			  url: keepAliveURL,
			  async: false
			});
		},
		buttons: {
			OK: function() {
				// close dialog
				$(this).dialog('close');
			}
		},
		resizable: false,
		open: function() {
			// scrollbar fix for IE
			$('body').css('overflow','hidden');
		},
		close: function() {
			// reset overflow
			$('body').css('overflow','auto');
		}
	}); // end of dialog


	// start the idle timer
	$.idleTimer(idleTime);

	// bind to idleTimer's idle.idleTimer event
	$(document).bind("idle.idleTimer", function(){
		// if the user is idle and a countdown isn't already running
		if($.data(document,'idleTimer') === 'idle' &amp;&amp; !running){
			var counter = redirectAfter;
			running = true;

			// intialisze timer
			$('#'+sessionTimeoutCountdownId).html(redirectAfter);
			// open dialog
			$(sessionTimeoutWarningDialog).dialog('open');

			// create a timer that runs every second
			timer = setInterval(function(){
				counter -= 1;

				// if the counter is 0, redirect the user
				if(counter === 0) {
					$(sessionTimeoutWarningDialog).html(expiredMessage);
					$(sessionTimeoutWarningDialog).dialog('disable');
					window.location = redirectTo;
				} else {
					$('#'+sessionTimeoutCountdownId).html(counter);
				};
			}, 1000);
		};
	});

});

Here’s my example with the jQueryUI dialog as the warning.

Colts' Superbowl loss

I’ve been a Colts fan for ~6 years now. Perhaps more than a Colts fan, I’m a Peyton Manning fan. This year’s Superbowl to me was the matchup I absolutely wanted. #1 seed in the NFC vs #1 seed in the AFC. Can’t be more perfect than that. I also respect Sean Payton and Drew Brees a lot. Therefore I thought if the Saints beat the Colts, it really will not affect me that much.

After the Colts’ loss, I had maybe 4 hours of sleep. I woke up this morning with Peyton’s interception being replayed in my head. I took the day off work and have been on the Colts official forum since I woke up. There is a lot negativity among the Colts fans. There are many who pointed out multiple turning points of the game:

  • Playing conservative at the end of the 1st half
  • Hank Baskett dropping the onside kick
  • Austin Collie running the wrong way on a screen pass
  • Pierre Garcon dropping a 3rd down catch in the 2nd quarter
  • Tracy Porter’s pick six
  • Reggie Wayne dropping the pass on the 4th and goal

Everyone has an opinion on which play really cost us the game. To me, it’s really not that important. We got outplayed as a team and lost because of that. However, with this loss, the dreaded GOAT (greatest of all time) conversation must now be blown out of proportion by the media (and fans). I will start to hear comments such as Peyton Manning choked again during the game that matters.

The GOAT talk is very annoying. I really love Peyton. I don’t know that much about NFL history. I came from China and only got into football a few years ago. I really love Peyton as a person and a football player. He’s fun to watch and he runs an unique offense. He always works and studies hard. He does not talk smack and is always respectful toward other players. In the most competitive professional sport, it’s hard to always maintain your composure. He talks like a politician and is very smart and a great role model. His commercials are the funniest. Personally I hope it could just stop at that.

But of course not. Because football is a business. Everyone needs to make money. If the media doesn’t talk about GOAT, how do they fill up their programs? Since the media runs this country, everyone is exposed to that.

When I first came to this country, I would have given a rats ass about football. I found grown men hitting each other was the the dumbest thing in the world. Until I actually learned more about the rules of the game and followed players like Peyton, I then understand why people can be crazy about it. But everything has two sides. The media debate is probably my least favorite aspect of the game. You have to put up with many idiotic analyst/commentators’ (cough Deion Sanders) “professional” opinions. But unfortunately it’s a part of the game that will always be there.

I think because Peyton is such a likable person born in a football family, he gets more coverage than a lot of other players. This will follow him to the end of his career. I’m just glad I get to watch him play. Hopefully even after he retires, he coaches or stays with football somehow.

荣荣

有些歌听了就可以让思绪无边际的自由飞翔。今天这样的歌又多了一首。每当我听到这样的歌时,我就想起你荣荣。和你那美得不切实际的爱情,那种只有小说里才形容得出来的浪漫曾经真的在我的生命中出现过。好可笑,如今我没有一点你的消息。你曾说如果和我分手你会去西藏当和尚。可能吗?分手多年后,我也无意发现分手后你给我日记里写的诗,情人节寄的卡片。我那时觉得可笑,没有把它们当回事。好多年没在收到你任何的消息了。我真的很想你,想知道你的一切。毕竟我们曾拥有过那样的爱情。有一天我也许会把那几年给你写的日记全登出来。反复回味,尤其在生命中最空虚的时候,总会心的微笑我拥有过的完美