-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetidle.min.js
7 lines (6 loc) · 2.79 KB
/
setidle.min.js
1
2
3
4
5
6
7
/*****************************
setidle
v0.3.2
MIT license
*****************************/
!function(){function e(e,t,n){this["_on"+t]=[],this._observerNames.push(t),this["_"+t]=e.on(n,function(){for(var e=0;e<this["_on"+t].length;e++)this["_on"+t][e]()}.bind(this))}function t(t,n){t=t||window.document,this.getElement=function(){return t},n=n||{mutated:a.mutated},this._observerNames=[],this._observers=n;for(var o in n)n.hasOwnProperty(o)&&e.call(this,n[o],o,t)}function n(e,t,n){!n&&t&&"function"!=typeof t&&!isNaN(t)&&isFinite(t)&&(n=t),n=n||s.interval;var o=new r(new r.DOMEventEmitter);return o.start(e,t,{interval:n,events:s.events}),o}function o(e){e.stop()}var i;if("function"==typeof define&&define.amd)i="RequireJS";else if("object"==typeof module&&module.exports)i="CommonJS";else{if("undefined"==typeof window)throw"Error: No browser or module system detected!";i="Browser"}var r={},s={interval:3e3,events:["change","click","dblclick","scroll","touchstart","touchend","resize","mutated"]},a={mutated:{on:function(e,t){var n=new MutationObserver(t);return n.observe(e,{childList:!0,attributes:!0,attributeOldValue:!1,characterData:!1,subtree:!0,characterDataOldValue:!1,attributeFilter:[]}),n},off:function(e){e.disconnect()}}};t.observers=a,t.prototype.disconnect=function(){for(var e=0;e<this._observerNames.length;e++){var t=this["_"+this._observerNames[e]];t&&this._observers[this._observerNames[e]].off(t)}},t.prototype.on=function(e,t){this._observerNames.indexOf(e)>=0?this["_on"+e].push(t):this.getElement().addEventListener(e,t,!1)},t.prototype.off=function(e,t){if(this._observerNames.indexOf(e)>=0){var n=this["_on"+e],o=n.indexOf(t);o>=0&&n.splice(o,1)}else this.getElement().removeEventListener(e,t)};var r=function(e){this.getEmitter=function(){return e}};switch(r.DOMEventEmitter=t,r.prototype.start=function(e,t,n){function o(){i?(clearTimeout(i),i=null):t&&"function"==typeof t&&t(),i=setTimeout(function(){e&&"function"==typeof e&&e(),i=null},n.interval)}n=n||s,this._config=n,this._eventHandlers=this._eventHandlers||[];var i=null,r=this.getEmitter(),a=r.on||r.addListener;if(!a||"function"!=typeof a)throw"The provided event emitter does not implement on() or addListener().";a=a.bind(r);for(var f=0;f<n.events.length;f++)a(n.events[f],o);this._eventHandlers.push(o)},r.prototype.stop=function(){var e,t,n=this.getEmitter(),o=n.off||n.removeListener;if(!o||"function"!=typeof o)throw"The provided event emitter does not implement off() or removeListener().";for(o=o.bind(n),e=0;e<this._config.events.length;e++)for(t=0;t<this._eventHandlers.length;t++)o(this._config.events[e],this._eventHandlers[t])},r.setIdle=n,r.clearIdle=o,"undefined"!=typeof i&&"Browser"===i&&(window.setIdle=n,window.clearIdle=o),i){case"RequireJS":define(["SetIdle"],r);break;case"CommonJS":module.exports=r;break;case"Browser":window.SetIdle=r}}();