Created
March 5, 2013 10:23
-
-
Save Macagare/5089308 to your computer and use it in GitHub Desktop.
JS: idle timer with callback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( function() { | |
var timeoutDuration = 30; | |
var mouseMoved = 0; | |
var keyPressed = 0; | |
var getDocument = function() { | |
if ( window ) { | |
return window.document; | |
} | |
return document; | |
} | |
var setDuration = function( duration ) { | |
this.timeoutDuration = duration; | |
}; | |
var init = function() { | |
console.log("init"); | |
getDocument().addEventListener( 'DOMContentLoaded', onDocumentLoaded ); | |
}; | |
var onDocumentLoaded = function() { | |
console.log("onDocumentLoaded"); | |
getDocument().onmousemove = onMouseMoved; | |
getDocument().onkeydown = onKeyPressed; | |
}; | |
var onMouseMoved = function( event ) { | |
console.log( "onMouseMoved" ); | |
this.mouseMoved = new Date(); | |
}; | |
var onKeyPressed = function( event ) { | |
console.log( "onKeyPressed" ); | |
this.keyPressed = new Date(); | |
}; | |
init(); | |
} )(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment