File "ifvisible.min.js"
Path: /StudyIB/js/ifvisibleminjs
File size: 4.88 KB
MIME-type: text/plain
Charset: utf-8
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(this,function(){return function(t){function e(s){if(i[s])return i[s].exports;var o=i[s]={exports:{},id:s,loaded:!1};return t[s].call(o.exports,o,o.exports,e),o.loaded=!0,o.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){t.exports=i(2)},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s,o,n="active",r="idle",u="hidden",d=void 0;!function(t){function e(t,e){r[t]||(r[t]=[]),r[t].push(e)}function i(t,e){r[t]&&r[t].forEach(function(t){t.apply(void 0,e)})}function s(t,e){r[t]&&(r[t]=r[t].filter(function(t){return e!==t}))}function o(t,e,i){return n||(n=t.addEventListener?function(t,e,i){return t.addEventListener(e,i,!1)}:"function"==typeof t.attachEvent?function(t,e,i){return t.attachEvent("on"+e,i,!1)}:function(t,e,i){return t["on"+e]=i}),n(t,e,i)}var n,r={};t.attach=e,t.fire=i,t.remove=s,t.dom=o}(o=e.Events||(e.Events={}));var a=function(){function t(t,e,i){var s=this;this.ifvisible=t,this.seconds=e,this.callback=i,this.stopped=!1,this.start(),this.ifvisible.on("statusChanged",function(t){s.stopped===!1&&(t.status===n?s.start():s.pause())})}return t.prototype.start=function(){this.stopped=!1,clearInterval(this.token),this.token=setInterval(this.callback,1e3*this.seconds)},t.prototype.stop=function(){this.stopped=!0,clearInterval(this.token)},t.prototype.resume=function(){this.start()},t.prototype.pause=function(){this.stop()},t}();e.Timer=a,e.IE=function(){for(var t,e=3,i=document.createElement("div"),s=i.getElementsByTagName("i");i.innerHTML="<!--[if gt IE "+ ++e+"]><i></i><![endif]-->",s[0];);return e>4?e:t}();var h=function(){function t(t,e){var i=this;if(this.root=t,this.doc=e,this.status=n,this.VERSION="2.0.10",this.timers=[],this.idleTime=3e4,this.isLegacyModeOn=!1,void 0!==this.doc.hidden?(s="hidden",d="visibilitychange"):void 0!==this.doc.mozHidden?(s="mozHidden",d="mozvisibilitychange"):void 0!==this.doc.msHidden?(s="msHidden",d="msvisibilitychange"):void 0!==this.doc.webkitHidden&&(s="webkitHidden",d="webkitvisibilitychange"),void 0===s)this.legacyMode();else{var r=function(){i.doc[s]?i.blur():i.focus()};r(),o.dom(this.doc,d,r)}this.startIdleTimer(),this.trackIdleStatus()}return t.prototype.legacyMode=function(){var t=this;if(!this.isLegacyModeOn){var i="blur",s="focus";e.IE<9&&(i="focusout"),o.dom(this.root,i,function(){return console.log("blurred"),t.blur()}),o.dom(this.root,s,function(){return t.focus()}),this.isLegacyModeOn=!0}},t.prototype.startIdleTimer=function(t){var e=this;t instanceof MouseEvent&&0===t.movementX&&0===t.movementY||(this.timers.map(clearTimeout),this.timers.length=0,this.status===r&&this.wakeup(),this.idleStartedTime=+new Date,this.timers.push(setTimeout(function(){if(e.status===n||e.status===u)return e.idle()},this.idleTime)))},t.prototype.trackIdleStatus=function(){o.dom(this.doc,"mousemove",this.startIdleTimer.bind(this)),o.dom(this.doc,"mousedown",this.startIdleTimer.bind(this)),o.dom(this.doc,"keyup",this.startIdleTimer.bind(this)),o.dom(this.doc,"touchstart",this.startIdleTimer.bind(this)),o.dom(this.root,"scroll",this.startIdleTimer.bind(this)),this.focus(this.startIdleTimer.bind(this))},t.prototype.on=function(t,e){return o.attach(t,e),this},t.prototype.off=function(t,e){return o.remove(t,e),this},t.prototype.setIdleDuration=function(t){return this.idleTime=1e3*t,this.startIdleTimer(),this},t.prototype.getIdleDuration=function(){return this.idleTime},t.prototype.getIdleInfo=function(){var t,e=+new Date;if(this.status===r)t={isIdle:!0,idleFor:e-this.idleStartedTime,timeLeft:0,timeLeftPer:100};else{var i=this.idleStartedTime+this.idleTime-e;t={isIdle:!1,idleFor:e-this.idleStartedTime,timeLeft:i,timeLeftPer:parseFloat((100-100*i/this.idleTime).toFixed(2))}}return t},t.prototype.idle=function(t){return t?this.on("idle",t):(this.status=r,o.fire("idle"),o.fire("statusChanged",[{status:this.status}])),this},t.prototype.blur=function(t){return t?this.on("blur",t):(this.status=u,o.fire("blur"),o.fire("statusChanged",[{status:this.status}])),this},t.prototype.focus=function(t){return t?this.on("focus",t):this.status!==n&&(this.status=n,o.fire("focus"),o.fire("wakeup"),o.fire("statusChanged",[{status:this.status}])),this},t.prototype.wakeup=function(t){return t?this.on("wakeup",t):this.status!==n&&(this.status=n,o.fire("wakeup"),o.fire("statusChanged",[{status:this.status}])),this},t.prototype.onEvery=function(t,e){return new a(this,t,e)},t.prototype.now=function(t){return void 0!==t?this.status===t:this.status===n},t}();e.IfVisible=h},function(t,e,i){(function(t){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var s=i(1),o="object"==typeof self&&self.self===self&&self||"object"==typeof t&&t.global===t&&t||this;e.ifvisible=new s.IfVisible(o,document)}).call(e,function(){return this}())}])});