I am trying to update my server to let it know that the user had some activity in the past 15 minutes. In order to do that, I made this implementation:
var page = {
updated: false,
change_state: function(e) {
var self = this;
if(!this.updated){
debugConsole.log('Moved mouse');
setTimeout(function(){
self.updated = false;
}, // 10000); //10 seconds
120000); //2 minutes
this.updated = true;
$.ajax({
url: 'comet/update.php',
success: function(data){
debugConsole.log('Moved mouse at: ' + data);
}
})
}
},
mouse_click: function(e) {
this.updated = false;
}
}
$("*").live('mousemove',function(e){
e.stopPropagation();
page.change_state(e); });
$("*").live('click',function(e){
page.mouse_click(e); });
I made it so that it only takes effect after 2 minutes from the last action, unless the last action was a click.
Is this the best way of doing it?