Skip to content

Instantly share code, notes, and snippets.

@collingo
Created March 11, 2012 20:44
Show Gist options
  • Save collingo/2018157 to your computer and use it in GitHub Desktop.
Save collingo/2018157 to your computer and use it in GitHub Desktop.
Touch screen InactivityTimer
function InactivityTimer() {
this.timer = 0;
this.threshold = 5000;
window.addEventListener('click', this.resetTimer.bind(this), true); // binding to capture phase
this.startTimer.call(this);
}
InactivityTimer.prototype = {
startTimer: function() {
this.timer = setTimeout(this.resetContent.bind(this), this.threshold);
},
resetTimer: function() {
clearTimeout(this.timer);
this.startTimer.call(this);
},
resetContent: function() {
clearTimeout(this.timer);
// do your reset stuff here
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment