filesbox/web/dist/design/mobile/js/layerMobile/layer.js

2 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2024-07-26 06:10:54 +00:00
/*! layer mobile-v2.0 弹层组件移动版 License LGPL http://layer.layui.com/mobile By 贤心 */(function(h){"use strict";var r=document,b="querySelectorAll",d="getElementsByClassName",p=function(t){return r[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,a=["layui-m-layer"],m=function(t){var e=this;e.config=i.extend(t),e.view()};m.prototype.view=function(){var t=this,e=t.config,n=r.createElement("div");t.id=n.id=a[0]+y,n.setAttribute("class",a[0]+" "+a[0]+(e.type||0)),n.setAttribute("index",y);var o=function(){var l=typeof e.title=="object";return e.title?'<h3 style="'+(l?e.title[1]:"")+'">'+(l?e.title[0]:e.title)+"</h3>":""}(),s=function(){typeof e.btn=="string"&&(e.btn=[e.btn]);var l,v=(e.btn||[]).length;return v!==0&&e.btn?(l='<span yes type="1">'+e.btn[0]+"</span>",v===2&&(l='<span no type="0">'+e.btn[1]+"</span>"+l),'<div class="layui-m-layerbtn">'+l+"</div>"):""}();if(e.fixed||(e.top=e.hasOwnProperty("top")?e.top:100,e.style=e.style||"",e.style+=" top:"+(r.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>"+s+"</div></div></div>",!e.type||e.type===2){var u=r[d](a[0]+e.type),c=u.length;c>=1&&layer.close(u[0].getAttribute("index"))}document.body.appendChild(n);var f=t.elem=p("#"+t.id)[0];e.success&&e.success(f),t.index=y++,t.action(e,f)},m.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 l=this.getAttribute("type");l==0?(t.no&&t.no(),layer.close(n.index)):t.yes?t.yes(n.index):layer.close(n.index)};if(t.btn)for(var s=e[d]("layui-m-layerbtn")[0].children,u=s.length,c=0;u>c;c++)i.touch(s[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 m(t||{});return e.index},close:function(t){var e=p("#"+a[0]+t)[0];e&&(e.innerHTML="",r.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=r[d](a[0]),e=0,n=t.length;n>e;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 s=r.createElement("link");return s.href=o+"need/layer.css?2.0",s.type="text/css",s.rel="styleSheet",s.id="layermcss",s}())}()})(window);