villaresources.blogg.se

Idle timer js
Idle timer js












idle timer js

var _API_JQUERY = 1 var _API_PROTOTYPE = 2 var _api var _idleTimeout = 30000 // 30 seconds var _awayTimeout = 600000 // 10 minutes var _idleNow = false var _idleTimestamp = null var _idleTimer = null var _awayNow = false var _awayTimestamp = null var _awayTimer = null function setIdleTimeout ( ms ) // End of file. idle.js (c) Alexios Chouchoulas 2009 // Released under the terms of the GNU Public License version 2.0 (or later). Moving the mouse or pressing keys should fade them again. Wait a few seconds and the ‘idle’ and ‘away’ boxes will highlight. You can see this running with exaggerated timeouts (two and four seconds for idle and away respectively). Here's a simple example, using jQuery (the only jQuery-specific thing is the code inside the function() event handlers):

idle timer js

The parameters are either true or false, depending on whether idle and/or away states have been established. The third callback, document.onBack(isIdle, isAway), is called when user activity is detected. There are three event-like callbacks: document.onIdle and document.onAway are called without parameters when the idle and away timeouts occur. There are two functions, setIdleTimeout(ms) and setAwayTimeout(ms) to set the idle and away timeouts respectively. If you're after a modern, simpler, jQuery-only solution to this problem without an API, look at this Stack Overflow question. My solution is clunky by modern standards, it pollutes the JavaScript namespace, it displays all sorts of bad coding practices. Or just see it as some sort of ancient artifact, best seen but not touched. You should be ignoring it and/or learning from it. When you move your mouse over the page or start typing, you're considered 'active'. By 2018 standards, this code is about as ancient as it is evil. The idle timer is built on jQuery and provides two events: idle.idleTimer and active.idleTimer, which fire when the user's idle state has changed.














Idle timer js