2 lines
3.2 KiB
JavaScript
2 lines
3.2 KiB
JavaScript
/*! layer mobile-v2.0.0 Web 通用弹出层组件 MIT License */(function(h){"use strict";var l=document,b="querySelectorAll",d="getElementsByClassName",m=function(t){return l[b](t)},x={type:0,shade:!0,shadeClose:!0,fixed:!0,anim:"scale"},i={extend:function(t){var e=JSON.parse(JSON.stringify(x));for(var n in t)e[n]=t[n];return e},timer:{},end:{}};i.touch=function(t,e){t.addEventListener("click",function(n){e.call(this,n)},!1)};var y=0,r=["layui-m-layer"],p=function(t){var e=this;e.config=i.extend(t),e.view()};p.prototype.view=function(){var t=this,e=t.config,n=l.createElement("div");t.id=n.id=r[0]+y,n.setAttribute("class",r[0]+" "+r[0]+(e.type||0)),n.setAttribute("index",y);var o=function(){var s=typeof e.title=="object";return e.title?'<h3 style="'+(s?e.title[1]:"")+'">'+(s?e.title[0]:e.title)+"</h3>":""}(),a=function(){typeof e.btn=="string"&&(e.btn=[e.btn]);var s,v=(e.btn||[]).length;return v!==0&&e.btn?(s='<span yes type="1">'+e.btn[0]+"</span>",v===2&&(s='<span no type="0">'+e.btn[1]+"</span>"+s),'<div class="layui-m-layerbtn">'+s+"</div>"):""}();if(e.fixed||(e.top=e.hasOwnProperty("top")?e.top:100,e.style=e.style||"",e.style+=" top:"+(l.body.scrollTop+e.top)+"px"),e.type===2&&(e.content='<i></i><i class="layui-m-layerload"></i><i></i><p>'+(e.content||"")+"</p>"),e.skin&&(e.anim="up"),e.skin==="msg"&&(e.shade=!1),n.innerHTML=(e.shade?"<div "+(typeof e.shade=="string"?'style="'+e.shade+'"':"")+' class="layui-m-layershade"></div>':"")+'<div class="layui-m-layermain" '+(e.fixed?"":'style="position:static;"')+'><div class="layui-m-layersection"><div class="layui-m-layerchild '+(e.skin?"layui-m-layer-"+e.skin+" ":"")+(e.className?e.className:"")+" "+(e.anim?"layui-m-anim-"+e.anim:"")+'" '+(e.style?'style="'+e.style+'"':"")+">"+o+'<div class="layui-m-layercont">'+e.content+"</div>"+a+"</div></div></div>",!e.type||e.type===2){var u=l[d](r[0]+e.type),c=u.length;c>=1&&layer.close(u[0].getAttribute("index"))}document.body.appendChild(n);var f=t.elem=m("#"+t.id)[0];e.success&&e.success(f),t.index=y++,t.action(e,f)},p.prototype.action=function(t,e){var n=this;t.time&&(i.timer[n.index]=setTimeout(function(){layer.close(n.index)},1e3*t.time));var o=function(){var s=this.getAttribute("type");s==0?(t.no&&t.no(),layer.close(n.index)):t.yes?t.yes(n.index):layer.close(n.index)};if(t.btn)for(var a=e[d]("layui-m-layerbtn")[0].children,u=a.length,c=0;c<u;c++)i.touch(a[c],o);if(t.shade&&t.shadeClose){var f=e[d]("layui-m-layershade")[0];i.touch(f,function(){layer.close(n.index,t.end)})}t.end&&(i.end[n.index]=t.end)},h.layer={v:"2.0",index:y,open:function(t){var e=new p(t||{});return e.index},close:function(t){var e=m("#"+r[0]+t)[0];e&&(e.innerHTML="",l.body.removeChild(e),clearTimeout(i.timer[t]),delete i.timer[t],typeof i.end[t]=="function"&&i.end[t](),delete i.end[t])},closeAll:function(){for(var t=l[d](r[0]),e=0,n=t.length;e<n;e++)layer.close(0|t[0].getAttribute("index"))}},typeof define=="function"?define(function(){return layer}):function(){var t=document.scripts,e=t[t.length-1],n=e.src,o=n.substring(0,n.lastIndexOf("/")+1);e.getAttribute("merge")||document.head.appendChild(function(){var a=l.createElement("link");return a.href=o+"need/layer.css?2.0",a.type="text/css",a.rel="styleSheet",a.id="layermcss",a}())}()})(window);
|