This is just a simple class I wrote for something that won't be used now, so thought I'd share it instead. It's using jQuery for events but that can easily be swapped out.
function Idle(config){
idler = this;
idler.mouseTimeout = 0;
idler.state = 1;
this.Start = function(){
$(document).bind('mousemove',idler.Move);
idler.Move();
};
this.Stop = function(){
$(document).unbind('mousemove',idler.Move);
window.clearTimeout(idler.mouseTimeout);
};
this.Move = function(){
if(idler.state==0)
config.onactive();
idle.state = 1;
window.clearTimeout(idler.mouseTimeout);
idler.mouseTimeout = setTimeout(idler.Idled,config.timeout);
};
this.Idled = function(){
idler.state = 0;
config.onidle();
}
}
Here's some example usage.
var idle = new Idle({
onidle:function(){
// hide stuff
},
onactive:function(){
// show stuff
},
timeout:1000
});
idle.Start();