User-presence detection with jQuery-IdleCat

“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. // Create an instance of idleCat on a jQuery object.
  2. var instance = $('#status').idleCat({
  3.  
  4.     // Number of seconds to wait between two scans of user activity.
  5.     interval: 2,
  6.  
  7.     // How many seconds to hold the activity from the moment of knowing there was not any activity.
  8.     release: 2,
  9.  
  10.     // The default state of the idleness (use 'active' or 'idle').
  11.     state: 'idle',
  12.  
  13.     // Callback fired after the discovery of user activity on the page.
  14.     activeCallback: function() {
  15.         $(this).addClass('active');
  16.     },
  17.  
  18.     // Callback fired after the discovery of used idleness on the page.
  19.     // (+ number of seconds defined in the 'release' property)
  20.     idleCallback: function(element) {
  21.         $(this).removeClass('active');
  22.     },
  23.  
  24.     // See below for more options...
  25.  
  26. });
  27.  
  28. // Log current state from idleCat attached to that jQuery object.
  29. window.setInterval(function() {
  30.     console.log(instance.getState());
  31. }, 1000)

GitHub

Alex

I am a full-stack developer. 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."

Recent Posts

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

4 weeks ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

2 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago

Archaeology Travel Booth – Travel Innovation Summit 2023

Archaeology Travel is an online travel guide for people who enjoy exploring the world’s pasts.… Read More

6 months ago