layer.ext.js 5.0 KB

1
  1. /*! layer弹层组件拓展类 */!function(){layer.use("skin/layer.ext.css",function(){layer.layui_layer_extendlayerextjs=!0});var m=layer.cache||{},n=function(a){return m.skin?" "+m.skin+" "+m.skin+"-"+a:""};layer.prompt=function(a,c){a=a||{};"function"==typeof a&&(c=a);var g;return layer.open($.extend({btn:["\x26#x786E;\x26#x5B9A;","\x26#x53D6;\x26#x6D88;"],content:2==a.formType?'\x3ctextarea class\x3d"layui-layer-input"\x3e'+(a.value||"")+"\x3c/textarea\x3e":'\x3cinput type\x3d"'+(1==a.formType?"password":"text")+'" class\x3d"layui-layer-input" value\x3d"'+(a.value||"")+'"\x3e',skin:"layui-layer-prompt"+n("prompt"),success:function(a){g=a.find(".layui-layer-input");g.focus()},yes:function(e){var b=g.val();""===b?g.focus():b.length>(a.maxlength||500)?layer.tips("\x26#x6700;\x26#x591A;\x26#x8F93;\x26#x5165;"+(a.maxlength||500)+"\x26#x4E2A;\x26#x5B57;\x26#x6570;",g,{tips:1}):c&&c(b,e,g)}},a))};layer.tab=function(a){a=a||{};var c=a.tab||{};return layer.open($.extend({type:1,skin:"layui-layer-tab"+n("tab"),title:function(){var a=c.length,e=1,b="";if(0<a)for(b='\x3cspan class\x3d"layui-layer-tabnow"\x3e'+c[0].title+"\x3c/span\x3e";a>e;e++)b+="\x3cspan\x3e"+c[e].title+"\x3c/span\x3e";return b}(),content:'\x3cul class\x3d"layui-layer-tabmain"\x3e'+function(){var a=c.length,e=1,b="";if(0<a)for(b='\x3cli class\x3d"layui-layer-tabli xubox_tab_layer"\x3e'+(c[0].content||"no content")+"\x3c/li\x3e";a>e;e++)b+='\x3cli class\x3d"layui-layer-tabli"\x3e'+(c[e].content||"no content")+"\x3c/li\x3e";return b}()+"\x3c/ul\x3e",success:function(a){var c=a.find(".layui-layer-title").children(),b=a.find(".layui-layer-tabmain").children();c.on("mousedown",function(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0;a=$(this);var c=a.index();a.addClass("layui-layer-tabnow").siblings().removeClass("layui-layer-tabnow");b.eq(c).show().siblings().hide()})}},a))};layer.photos=function(a,c,g){function e(a,b,c){var d=new Image;d.onload=function(){d.onload=null;b(d)};d.onerror=function(a){d.onerror=null;c(a)};d.src=a}var b={};if(a=a||{},a.photos){var k=a.photos.constructor===Object,l=k?a.photos:{},d=l.data||[],h=l.start||0;if(b.imgIndex=h+1,k){if(0===d.length)return void layer.msg("\x26#x6CA1;\x26#x6709;\x26#x56FE;\x26#x7247;")}else if(k=$(a.photos),0===k.find(a.img||"img").length||(c||k.find(l.img||"img").each(function(b){var f=$(this);d.push({alt:f.attr("alt"),pid:f.attr("layer-pid"),src:f.attr("layer-src")||f.attr("src"),thumb:f.attr("src")});f.on("click",function(){layer.photos($.extend(a,{photos:{start:b,data:d,tab:a.tab},full:a.full}),!0)})}),!c))return;b.imgprev=function(a){b.imgIndex--;1>b.imgIndex&&(b.imgIndex=d.length);b.tabimg(a)};b.imgnext=function(a,f){b.imgIndex++;b.imgIndex>d.length&&(b.imgIndex=1,f)||b.tabimg(a)};b.keyup=function(a){if(!b.end){var f=a.keyCode;a.preventDefault();37===f?b.imgprev(!0):39===f?b.imgnext(!0):27===f&&layer.close(b.index)}};b.tabimg=function(c){1>=d.length||(l.start=b.imgIndex-1,layer.close(b.index),layer.photos(a,!0,c))};b.event=function(){b.bigimg.hover(function(){b.imgsee.show()},function(){b.imgsee.hide()});b.bigimg.find(".layui-layer-imgprev").on("click",function(a){a.preventDefault();b.imgprev()});b.bigimg.find(".layui-layer-imgnext").on("click",function(a){a.preventDefault();b.imgnext()});$(document).on("keyup",b.keyup)};b.loadi=layer.load(1,{shade:"shade"in a?!1:.9,scrollbar:!1});e(d[h].src,function(c){layer.close(b.loadi);b.index=layer.open($.extend({type:1,area:function(){var b=[c.width,c.height],d=[$(window).width()-100,$(window).height()-100];return!a.full&&b[0]>d[0]&&(b[0]=d[0],b[1]=b[0]*d[1]/b[0]),[b[0]+"px",b[1]+"px"]}(),title:!1,shade:.9,shadeClose:!0,closeBtn:!1,move:".layui-layer-phimg img",moveType:1,scrollbar:!1,moveOut:!0,shift:5*Math.random()|0,skin:"layui-layer-photos"+n("photos"),content:'\x3cdiv class\x3d"layui-layer-phimg"\x3e\x3cimg src\x3d"'+d[h].src+'" alt\x3d"'+(d[h].alt||"")+'" layer-pid\x3d"'+d[h].pid+'"\x3e\x3cdiv class\x3d"layui-layer-imgsee"\x3e'+(1<d.length?'\x3cspan class\x3d"layui-layer-imguide"\x3e\x3ca href\x3d"javascript:;" class\x3d"layui-layer-iconext layui-layer-imgprev"\x3e\x3c/a\x3e\x3ca href\x3d"javascript:;" class\x3d"layui-layer-iconext layui-layer-imgnext"\x3e\x3c/a\x3e\x3c/span\x3e':"")+'\x3cdiv class\x3d"layui-layer-imgbar" style\x3d"display:'+(g?"block":"")+'"\x3e\x3cspan class\x3d"layui-layer-imgtit"\x3e\x3ca href\x3d"javascript:;"\x3e'+(d[h].alt||"")+"\x3c/a\x3e\x3cem\x3e"+b.imgIndex+"/"+d.length+"\x3c/em\x3e\x3c/span\x3e\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e",success:function(c,e){b.bigimg=c.find(".layui-layer-phimg");b.imgsee=c.find(".layui-layer-imguide,.layui-layer-imgbar");b.event(c);a.tab&&a.tab(d[h],c)},end:function(){b.end=!0;$(document).off("keyup",b.keyup)}},a))},function(){layer.close(b.loadi);layer.msg("\x26#x5F53;\x26#x524D;\x26#x56FE;\x26#x7247;\x26#x5730;\x26#x5740;\x26#x5F02;\x26#x5E38;\x3cbr\x3e\x26#x662F;\x26#x5426;\x26#x7EE7;\x26#x7EED;\x26#x67E5;\x26#x770B;\x26#x4E0B;\x26#x4E00;\x26#x5F20;\x26#xFF1F;",{time:3E4,btn:["\u4e0b\u4e00\u5f20","\u4e0d\u770b\u4e86"],yes:function(){1<d.length&&b.imgnext(!0,!0)}})})}}}();