“Have you ever needed to perform a single or periodic task on your page based on user’s actual presence? Do you think you really need to fetch new notifications from your servers all the time, or isn’t such task quite pointless unless there actually is an active user sitting in front of your page?”
jQuery-IdleCat to the rescue …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// Create an instance of idleCat on a jQuery object. var instance = $('#status').idleCat({ // Number of seconds to wait between two scans of user activity. interval: 2, // How many seconds to hold the activity from the moment of knowing there was not any activity. release: 2, // The default state of the idleness (use 'active' or 'idle'). state: 'idle', // Callback fired after the discovery of user activity on the page. activeCallback: function() { $(this).addClass('active'); }, // Callback fired after the discovery of used idleness on the page. // (+ number of seconds defined in the 'release' property) idleCallback: function(element) { $(this).removeClass('active'); }, // See below for more options... }); // Log current state from idleCat attached to that jQuery object. window.setInterval(function() { console.log(instance.getState()); }, 1000) |
I am a full-stack developer. My expertise include:
I love programming, design and know my way around server architecture as well. I would never feel complete, with one of these missing.
I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest.
Apart from that, I am a peace loving guy who tries to have people around him that think the same. I truly believe in the principle: “If you help someone, someone will help you, when you need it."