butterfly-halo-theme
Version:
一个Halo博客主题,Butterfly
1 lines • 8.54 kB
JavaScript
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b:"function"==typeof define&&define.amd?define([],function(){return b(a)}):a.Qmsg=b(a)}(this,function(a){"use strict";function h(){var b,a=c;for(b=0;b<arguments.length;++b)a+="-"+arguments[b];return a}function i(a){var g,i,k,l,m,o,p,q,r,s,b=this;b.settings=Object.assign({},e,a||{}),b.id=n.instanceCount,g=b.settings.timeout,g=g&&parseInt(g>=0)&&parseInt(g)<=Math.NEGATIVE_INFINITY?parseInt(g):e.timeout,b.timeout=g,b.settings.timeout=g,b.timer=null,i=document.createElement("div"),k=f[b.settings.type||"info"],l=h("content-"+b.settings.type||"info"),l+=b.settings.showClose?" "+h("content-with-close"):"",m=b.settings.content||"",o=f["close"],p=b.settings.showClose?'<i class="qmsg-icon qmsg-icon-close">'+o+"</i>":"",q=document.createElement("span"),b.settings.html?q.innerHTML=m:q.innerText=m,i.innerHTML='<div class="qmsg-content"> <div class="'+l+'"> <i class="qmsg-icon">'+k+"</i>"+q.outerHTML+p+"</div> </div>",i.classList.add(h("item")),i.style.textAlign=b.settings.position,r=document.querySelector("."+c),r||(r=document.createElement("div"),r.classList.add(c),r.classList.add(h("wrapper")),r.classList.add(h("is-initialized")),document.body.appendChild(r)),r.appendChild(i),b.$wrapper=r,b.$elem=i,j(b,"opening"),b.settings.showClose&&i.querySelector(".qmsg-icon-close").addEventListener("click",function(){b.close()}.bind(i)),i.addEventListener("animationend",function(a){var b=a.target,c=a.animationName;c===d["closing"]&&(clearInterval(this.timer),this.destroy()),b.style.animationName=""}.bind(b)),b.settings.autoClose&&(s=10,b.timer=setInterval(function(){this.timeout-=s,this.timeout<=0&&(clearInterval(this.timer),this.close())}.bind(b),s),b.$elem.addEventListener("mouseover",function(){clearInterval(this.timer)}.bind(b)),b.$elem.addEventListener("mouseout",function(){"closing"!==this.state&&(this.timer=setInterval(function(){this.timeout-=s,this.timeout<=0&&(clearInterval(this.timer),this.close())}.bind(b),s))}.bind(b)))}function j(a,b){b&&d[b]&&(a.state=b,a.$elem.style.animationName=d[b])}function k(a){var b=h("count"),c=a.$elem.querySelector('[class^="qmsg-content-"]'),d=c.querySelector("."+b);d||(d=document.createElement("span"),d.classList.add(b),c.appendChild(d)),d.innerHTML=a.count,d.style.animationName="",d.style.animationName="MessageShake",a.timeout=a.settings.timeout||e.timeout}function l(a,b){var c=Object.assign({},e);return 0===arguments.length?c:a instanceof Object?Object.assign(c,a):(c.content=a.toString(),b instanceof Object?Object.assign(c,b):c)}function m(a){var b,c,d,e,f,g,h,j,l,m;a=a||{},b=JSON.stringify(a),c=-1;for(e in this.oMsgs)if(f=this.oMsgs[e],f.config===b){c=e,d=f.inst;break}if(0>c){if(this.instanceCount++,g={},g.id=this.instanceCount,g.config=b,d=new i(a),d.id=this.instanceCount,d.count="",g.inst=d,this.oMsgs[this.instanceCount]=g,h=this.oMsgs.length,j=this.maxNums,h>j)for(l=0,m=this.oMsgs,l;h-j>l;l++)m[l]&&m[l].inst.settings.autoClose&&m[l].inst.close()}else d.count=d.count?d.count>=99?d.count:d.count+1:2,k(d);return d.$elem.setAttribute("data-count",d.count),d}var b,c,d,e,f,g,n;return"function"!=typeof Object.assign&&(Object.assign=function(a){var b,c,d;if(null==a)throw new TypeError("Cannot convert undefined or null to object");for(a=Object(a),b=1;b<arguments.length;b++)if(c=arguments[b],null!=c)for(d in c)Object.prototype.hasOwnProperty.call(c,d)&&(a[d]=c[d]);return a}),"classList"in document.documentElement||Object.defineProperty(HTMLElement.prototype,"classList",{get:function(){function b(b){return function(c){var d=a.className.split(/\s+/g),e=d.indexOf(c);b(d,e,c),a.className=d.join(" ")}}var a=this;return{add:b(function(a,b,c){~b||a.push(c)}),remove:b(function(a,b){~b&&a.splice(b,1)}),toggle:b(function(a,b,c){~b?a.splice(b,1):a.push(c)}),contains:function(b){return!!~a.className.split(/\s+/g).indexOf(b)},item:function(b){return a.className.split(/\s+/g)[b]||null}}}}),b="qmsg",c=a&&a.QMSG_GLOBALS&&a.QMSG_GLOBALS.NAMESPACE||b,d={opening:"MessageMoveIn",done:"",closing:"MessageMoveOut"},e=Object.assign({position:"center",type:"info",showClose:!1,timeout:2500,animation:!0,autoClose:!0,content:"",onClose:null,maxNums:5,html:!1},a&&a.QMSG_GLOBALS&&a.QMSG_GLOBALS.DEFAULTS),f={info:'<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M512 64q190.016 4.992 316.512 131.488T960 512q-4.992 190.016-131.488 316.512T512 960q-190.016-4.992-316.512-131.488T64 512q4.992-190.016 131.488-316.512T512 64zm67.008 275.008q26.016 0 43.008-15.488t16.992-41.504-16.992-41.504-42.496-15.488-42.496 15.488-16.992 41.504 16.992 41.504 42.016 15.488zm12 360q0-6.016.992-16T592 664l-52.992 60.992q-8 8.992-16.512 14.016T508 742.016q-8.992-4-8-14.016l88-276.992q4.992-28-8.992-48t-44.992-24q-35.008.992-76.512 29.504t-72.512 72.512v15.008q-.992 10.016 0 19.008l52.992-60.992q8-8.992 16.512-14.016T468 437.024q10.016 4.992 7.008 16l-87.008 276q-7.008 24.992 7.008 44.512T444 800.032q50.016-.992 84-28.992t63.008-72z" fill="#909399"/></svg>',warning:'<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M512 64C264.64 64 64 264.64 64 512c0 247.424 200.64 448 448 448 247.488 0 448-200.576 448-448 0-247.36-200.512-448-448-448zm0 704c-26.432 0-48-21.504-48-48s21.568-48 48-48c26.624 0 48 21.504 48 48s-21.376 48-48 48zm48-240c0 26.56-21.376 48-48 48-26.432 0-48-21.44-48-48V304c0-26.56 21.568-48 48-48 26.624 0 48 21.44 48 48v224z" fill="#E6A23C"/></svg>',error:'<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M512 64C264.58 64 64 264.58 64 512s200.58 448 448 448 448-200.57 448-448S759.42 64 512 64zm158.39 561.14a32 32 0 1 1-45.25 45.26L512 557.26 398.86 670.4a32 32 0 0 1-45.25-45.26L466.75 512 353.61 398.86a32 32 0 0 1 45.25-45.25L512 466.74l113.14-113.13a32 32 0 0 1 45.25 45.25L557.25 512z" fill="#F56C6C"/></svg>',success:'<svg viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="16" height="16"><path d="M512 64q190.016 4.992 316.512 131.488T960 512q-4.992 190.016-131.488 316.512T512 960q-190.016-4.992-316.512-131.488T64 512q4.992-190.016 131.488-316.512T512 64zm-56 536l-99.008-99.008q-12-11.008-27.488-11.008t-27.008 11.488-11.488 26.496 11.008 27.008l127.008 127.008q11.008 11.008 27.008 11.008t27.008-11.008l263.008-263.008q15.008-15.008 9.504-36.512t-27.008-27.008-36.512 9.504z" fill="#67C23A"/></svg>',loading:'<svg class="animate-turn" width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill="#fff" fill-opacity=".01" d="M0 0h48v48H0z"/><path d="M4 24c0 11.046 8.954 20 20 20s20-8.954 20-20S35.046 4 24 4" stroke="#409eff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M36 24c0-6.627-5.373-12-12-12s-12 5.373-12 12 5.373 12 12 12" stroke="#409eff" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>',close:'<svg width="16" height="16" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect width="48" height="48" fill="white" fill-opacity="0.01"/><path d="M14 14L34 34" stroke="#909399" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M14 34L34 14" stroke="#909399" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>'},g=function(){var a=document.createElement("div").style;return void 0!==a.animationName||void 0!==a.WebkitAnimationName||void 0!==a.MozAnimationName||void 0!==a.msAnimationName||void 0!==a.OAnimationName}(),i.prototype.destroy=function(){this.$elem.parentNode&&this.$elem.parentNode.removeChild(this.$elem),clearInterval(this.timer),n.remove(this.id)},i.prototype.close=function(){j(this,"closing"),g?n.remove(this.id):this.destroy();var a=this.settings.onClose;a&&a instanceof Function&&a.call(this)},n={version:"0.0.1",instanceCount:0,oMsgs:[],maxNums:e.maxNums||5,config:function(a){e=a&&a instanceof Object?Object.assign(e,a):e,this.maxNums=e.maxNums&&e.maxNums>0?parseInt(e.maxNums):3},info:function(a,b){var c=l(a,b);return c.type="info",m.call(this,c)},warning:function(a,b){var c=l(a,b);return c.type="warning",m.call(this,c)},success:function(a,b){var c=l(a,b);return c.type="success",m.call(this,c)},error:function(a,b){var c=l(a,b);return c.type="error",m.call(this,c)},loading:function(a,b){var c=l(a,b);return c.type="loading",c.autoClose=!1,m.call(this,c)},remove:function(a){this.oMsgs[a]&&delete this.oMsgs[a]},closeAll:function(){for(var a in this.oMsgs)this.oMsgs[a]&&this.oMsgs[a].inst.close()}}});