I want to log user activity. According other users response on StackOverflow I made a small jQuery library:
var stop_timeout = false;
$(window).blur(function(){
elvis('left the building since ');
}).focus(function(){
elvis('come back now:');
}).mousemove(function() {
zima();
}).keyup(function() {
zima();
});
function elvis(ce) {
var now=new Date();
$('.showMe').append('Elvis ' + ce + now.getHours() + ':' + now.getMinutes() +':'+now.getSeconds()+'<br>');
}
function zima() {
clearTimeout(stop_timeout);
stop_timeout = setTimeout(function() {
$('.showMe').append('No activity since 10 seconds...<br>');
}, 10000);
}
and html:
<input type="text" size="20">
<div class="showMe"></div>
The code is working Ok and, obviously, the mousemove and keyup events fires even I blur or focus on window. What I need is to fire mousemove and keyup ONLY on $(window).focus()
Thank you !
Edit: Also I made a Jfiddle here: http://jsfiddle.net/6RLBQ/5/