-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidle-monitor.min.js
2 lines (2 loc) · 1.33 KB
/
idle-monitor.min.js
1
2
/*! idle-monitor - v0.1.0 - 2014-08-22 */
!function(a){"function"==typeof define&&define.amd&&define(["backbone","underscore"],a)}(function(a,b){function c(c){b.extend(this,a.Events),this.timeout=null,this.lastAction=null,this.warningFired=!1,this.options=b.defaults(c||{},{checkIntervalSecs:10,events:{document:"click keyup"},warningSecs:840,timeoutSecs:900}),b.each(b.keys(this.options.events),b.bind(function(c){var d="document"===c?document:c;a.$(d).on(this.options.events[c],b.bind(this.actionCallback,this))},this))}var d="IdleMonitor.actionTime";return c.prototype.actionCallback=function(){localStorage.setItem(d,(new Date).getTime()),this.trigger("action")},c.prototype.checkCallback=function(){var a=parseInt(localStorage.getItem(d),10),b=((new Date).getTime()-new Date(a).getTime())/1e3;return this.lastAction&&this.lastAction!==a?(this.trigger("action"),this.warningFired=!1,void(this.lastAction=a)):(this.lastAction=a,!this.warningFired&&b>=this.options.warningSecs&&(this.trigger("warning"),this.warningFired=!0),void(b>=this.options.timeoutSecs&&this.trigger("timeout")))},c.prototype.start=function(){this.stop(),this.actionCallback(),this.timeout=setInterval(b.bind(this.checkCallback,this),1e3*this.options.checkIntervalSecs)},c.prototype.stop=function(){this.timeout&&(clearTimeout(this.timeout),this.timeout=null),this.warningFired=!1},c});