forked from henriqueboaventura/jquery.idle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.idle.min.js
9 lines (9 loc) · 1.1 KB
/
jquery.idle.min.js
1
2
3
4
5
6
7
8
9
/**
* JQuery Idle.
* A dead simple jQuery plugin that executes a callback function if the user is idle.
* About: Author
* Henrique Boaventura (hboaventura@gmail.com).
* About: Version
* 1.2.3
**/
!function(n){"use strict";n.fn.idle=function(e){var i,t,o={idle:6e4,events:"mousemove keydown mousedown touchstart",onIdle:function(){},onActive:function(){},onHide:function(){},onShow:function(){},keepTracking:!0,startAtIdle:!1},c=e.startAtIdle||!1,u=!e.startAtIdle||!0,d=n.extend({},o,e),s=null;return n(this).on("idle:stop",{},function(){n(this).off(d.events),d.keepTracking=!1,i(s,d)}),i=function(n,e){return c&&(e.onActive.call(),c=!1),clearTimeout(n),e.keepTracking?t(e):void 0},t=function(n){var e,i=setTimeout;return e=i(function(){c=!0,n.onIdle.call()},n.idle)},this.each(function(){s=t(d),n(this).on(d.events,function(){s=i(s,d)}),(d.onShow||d.onHide)&&n(document).on("visibilitychange webkitvisibilitychange mozvisibilitychange msvisibilitychange",function(){document.hidden||document.webkitHidden||document.mozHidden||document.msHidden?u&&(u=!1,d.onHide.call()):u||(u=!0,d.onShow.call())})})}}(jQuery);