forked from wavded/humane-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
humane.min.js
1 lines (1 loc) · 4.16 KB
/
humane.min.js
1
!function(e,t,n){typeof module!="undefined"?module.exports=n(e,t):typeof define=="function"&&typeof define.amd=="object"?define(n):t[e]=n(e,t)}("humane",this,function(e,t){var n=window,r=document,i={on:function(e,t,r){"addEventListener"in n?e.addEventListener(t,r,!1):e.attachEvent("on"+t,r)},off:function(e,t,r){"removeEventListener"in n?e.removeEventListener(t,r,!1):e.detachEvent("on"+t,r)},bind:function(e,t){return function(){e.apply(t,arguments)}},isArray:Array.isArray||function(e){return Object.prototype.toString.call(e)==="[object Array]"},config:function(e,t){return e!=null?e:t},transSupport:!1,useFilter:/msie [678]/i.test(navigator.userAgent),_checkTransition:function(){var e=r.createElement("div"),t={webkit:"webkit",Moz:"",O:"o",ms:"MS"};for(var n in t)n+"Transition"in e.style&&(this.vendorPrefix=t[n],this.transSupport=!0)}};i._checkTransition();var s=function(e){e||(e={}),this.queue=[],this.baseCls=e.baseCls||"humane",this.addnCls=e.addnCls||"",this.timeout=e.timeout||2500,this.waitForMove=e.waitForMove||!1,this.clickToClose=e.clickToClose||!1,this.forceNew=e.forceNew||!1;try{this._setupEl()}catch(t){i.on(n,"load",i.bind(this._setupEl,this))}};return s.prototype={constructor:s,_setupEl:function(){var e=r.createElement("div");e.style.display="none",r.body.appendChild(e),this.el=e,this.removeEvent=i.bind(this.remove,this),this.transEvent=i.bind(this._afterAnimation,this),this._run()},_afterTimeout:function(){i.config(this.currentMsg.waitForMove,this.waitForMove)?this.removeEventsSet||(i.on(r.body,"mousemove",this.removeEvent),i.on(r.body,"click",this.removeEvent),i.on(r.body,"keypress",this.removeEvent),i.on(r.body,"touchstart",this.removeEvent),this.removeEventsSet=!0):this.remove()},_run:function(){if(this._animating||!this.queue.length||!this.el)return;this._animating=!0,this.currentTimer&&(clearTimeout(this.currentTimer),this.currentTimer=null);var e=this.queue.shift(),t=i.config(e.clickToClose,this.clickToClose);t&&(i.on(this.el,"click",this.removeEvent),i.on(this.el,"touchstart",this.removeEvent));var n=i.config(e.timeout,this.timeout);n>0&&(this.currentTimer=setTimeout(i.bind(this._afterTimeout,this),n)),i.isArray(e.html)&&(e.html="<ul><li>"+e.html.join("<li>")+"</ul>"),this.el.innerHTML=e.html,this.currentMsg=e,this.el.className=this.baseCls,i.transSupport?(this.el.style.display="block",setTimeout(i.bind(this._showMsg,this),50)):this._showMsg()},_setOpacity:function(e){i.useFilter?this.el.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=e*100:this.el.style.opacity=String(e)},_showMsg:function(){var e=i.config(this.currentMsg.addnCls,this.addnCls);if(i.transSupport)this.el.className=this.baseCls+" "+e+" "+this.baseCls+"-animate";else{var t=0;this.el.className=this.baseCls+" "+e+" "+this.baseCls+"-js-animate",this._setOpacity(0),this.el.style.display="block";var n=this,r=setInterval(function(){t<1?(t+=.1,t>1&&(t=1),n._setOpacity(t)):clearInterval(r)},30)}},_hideMsg:function(){var e=i.config(this.currentMsg.addnCls,this.addnCls);if(i.transSupport)this.el.className=this.baseCls+" "+e,i.on(this.el,i.vendorPrefix?i.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent);else var t=1,n=this,r=setInterval(function(){t>0?(t-=.1,t<0&&(t=0),n._setOpacity(t)):(n.el.className=n.baseCls+" "+e,clearInterval(r),n._afterAnimation())},30)},_afterAnimation:function(){i.transSupport&&i.off(this.el,i.vendorPrefix?i.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent),this.currentMsg.cb&&this.currentMsg.cb(),this.el.style.display="none",this._animating=!1,this._run()},remove:function(e){var t=typeof e=="function"?e:null;i.off(r.body,"mousemove",this.removeEvent),i.off(r.body,"click",this.removeEvent),i.off(r.body,"keypress",this.removeEvent),i.off(r.body,"touchstart",this.removeEvent),i.off(this.el,"click",this.removeEvent),i.off(this.el,"touchstart",this.removeEvent),this.removeEventsSet=!1,t&&(this.currentMsg.cb=t),this._animating?this._hideMsg():t&&t()},log:function(e,t,n,r){var i={};if(r)for(var s in r)i[s]=r[s];if(typeof t=="function")n=t;else if(t)for(var s in t)i[s]=t[s];return i.html=e,n&&(i.cb=n),this.queue.push(i),this._run(),this},spawn:function(e){var t=this;return function(n,r,i){return t.log.call(t,n,r,i,e),t}},create:function(e){return new s(e)}},new s});