Javascript class for tracking mouse idle time {January 04, 4:14 PM}

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();

Permalink | Comments (0) | Post RSSRSS comment feed |

Categories:

Tags:

Currently rated 1.0 by 538 people

  • Currently 1.026023/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]