Files
blog/themes/Ying/static/js/message.min.js
T

1 line
8.3 KiB
JavaScript
Raw Normal View History

2024-07-11 08:59:32 +08:00
!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=O