I'm trying to implement some idle detection code. I have it working, thanks to some other SO posts, but I want it to be part of a Polymer Element so I can just stick <idle-fire></idle-fire>
anywhere in my app and pass some parameters. Here is what I have:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="idle-fire">
<script>
Polymer({
is: 'idle-fire',
properties: {
idlelimit: {
type: Number,
value: 10
}
},
ready: function() {
}
});
</script>
</dom-module>
<script>
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
console.log("tick (" + idleTime + ")");
if (idleTime >= 2) { // in minutes
console.log("Idle event fired!")
}
}
</script>
If I try to move any piece of the <script>
tag to the Polymer ready
function it fails to work. And with it the way it is, I can't access the idlelimit
property.
Any direction appreciated.