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.69 KB
/
humane.min.js
1
!function(e,t,n){if(typeof module!=="undefined")module.exports=n(e,t);else if(typeof define==="function"&&typeof define.amd==="object")define(n);else t[e]=n(e,t)}("humane",this,function(e,t){var n=window;var r=document;var i={on:function(e,t,r){"addEventListener"in n?e.addEventListener(t,r,false):e.attachEvent("on"+t,r)},off:function(e,t,r){"removeEventListener"in n?e.removeEventListener(t,r,false):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:false,useFilter:/msie [678]/i.test(navigator.userAgent),_checkTransition:function(){var e=r.createElement("div");var t={webkit:"webkit",Moz:"",O:"o",ms:"MS"};for(var n in t)if(n+"Transition"in e.style){this.vendorPrefix=t[n];this.transSupport=true}}};i._checkTransition();var s=function(e){e||(e={});this.queue=[];this.baseCls=e.baseCls||"humane";this.addnCls=e.addnCls||"";this.timeout="timeout"in e?e.timeout:2500;this.waitForMove=e.waitForMove||false;this.clickToClose=e.clickToClose||false;this.timeoutAfterMove=e.timeoutAfterMove||false;this.onClick=e.onClick||null;this.container=e.container;try{this._setupEl()}catch(t){i.on(n,"load",i.bind(this._setupEl,this))}};s.prototype={constructor:s,_setupEl:function(){var e=r.createElement("div");e.style.display="none";if(!this.container){if(r.body)this.container=r.body;else throw"document.body is null"}this.container.appendChild(e);this.el=e;this.removeEvent=i.bind(function(){if(!this.timeoutAfterMove){this.remove()}else{setTimeout(i.bind(this.remove,this),this.timeout)}},this);this.transEvent=i.bind(this._afterAnimation,this);this._run()},_afterTimeout:function(){if(!i.config(this.currentMsg.waitForMove,this.waitForMove))this.remove();else if(!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=true}},_run:function(){if(this._animating||!this.queue.length||!this.el)return;this._animating=true;if(this.currentTimer){clearTimeout(this.currentTimer);this.currentTimer=null}var e=this.queue.shift();var t=i.config(e.clickToClose,this.clickToClose);if(this.onClick!==null){i.on(this.el,"click",i.bind(this.onClick,this))}if(t){i.on(this.el,"click",i.bind(this.remove,this));i.on(this.el,"touchstart",i.bind(this.remove,this))}var n=i.config(e.timeout,this.timeout);if(n>0)this.currentTimer=setTimeout(i.bind(this._afterTimeout,this),n);if(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;if(i.transSupport){this.el.style.display="block";setTimeout(i.bind(this._showMsg,this),50)}else{this._showMsg()}},_setOpacity:function(e){if(i.useFilter){try{this.el.filters.item("DXImageTransform.Microsoft.Alpha").Opacity=e*100}catch(t){}}else{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;var r=setInterval(function(){if(t<1){t+=.1;if(t>1)t=1;n._setOpacity(t)}else 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;var n=this;var r=setInterval(function(){if(t>0){t-=.1;if(t<0)t=0;n._setOpacity(t)}else{n.el.className=n.baseCls+" "+e;clearInterval(r);n._afterAnimation()}},30)}},_afterAnimation:function(){if(i.transSupport)i.off(this.el,i.vendorPrefix?i.vendorPrefix+"TransitionEnd":"transitionend",this.transEvent);if(this.currentMsg.cb)this.currentMsg.cb();this.el.style.display="none";this._animating=false;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=false;if(t&&this.currentMsg)this.currentMsg.cb=t;if(this._animating)this._hideMsg();else if(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];i.html=e;if(n)i.cb=n;this.queue.push(i);this._run();return this},spawn:function(e){var t=this;return function(n,r,i){t.log.call(t,n,r,i,e);return t}},create:function(e){return new s(e)}};return new s})