www.gusucode.com > 简洁的js弹出层、弹出框插件及示例代码源码程序 > 简洁的js弹出层、弹出框插件及示例代码/layerv1.5.2/layer-v1.5.2/layer/layer.min.js

    /**************************************************************

 @Name : layer v1.5.2 弹层组件压缩版
 @author: 贤心
 @date: 2013-06-06
 @blog: http://sentsin.com
 @微博:http://weibo.com/SentsinXu
 @QQ群:176047238(layUI交流群)
 @Copyright: Sentsin Xu(贤心)
 @官网说明:http://sentsin.com/jquery/layer
 @赞助layer: https://me.alipay.com/sentsin
		
 *************************************************************/

;!function(a,b){
var e,f,h,i,
c=!0, //是否采用自动获取绝对路径。!1(即false, 将采用下述变量中的配置),!0为true
d="../../lily/lib/layer/", //当前js所在路径,上述变量为!0才有效
g={iE6:!-[1,]&&!a.XMLHttpRequest,times:0};g.getPath=function(){var a=document.scripts||e("script"),b=a[a.length-1].src;return b.substring(0,b.lastIndexOf("/")+1)},g.load=function(){c&&(d=this.getPath());var a=e("head")[0],b=document.createElement("link");b.setAttribute("type","text/css"),b.setAttribute("rel","stylesheet"),b.setAttribute("href",d+"skin/layer.css"),a.appendChild(b)},this.layer={v:"1.5.2",ready:function(a){var b="#layerCss";return e(b).ready(function(){a()})},alert:function(a,b,c,d){return e.layer({dialog:{msg:a,type:b,yes:d},title:c,area:["auto","auto"]})},confirm:function(a,b,c,d){return e.layer({dialog:{msg:a,type:4,btns:2,yes:b,no:d},title:c})},msg:function(a,c,d,f){return(""==a||a==b)&&(a="&nbsp;"),(c==b||""==c)&&(c=2),e.layer({dialog:{msg:a,type:d},time:c,title:["",!1],closeBtn:["",!1],end:function(){f&&f()}})},tips:function(a,b,c,d,f,g){return e.layer({type:4,shade:!1,time:c,maxWidth:d,tips:{msg:a,guide:f,follow:b,style:g}})},load:function(a,b,c){var d=!0;return 3===b&&(d=!1),e.layer({time:a,shade:c,loading:{type:b},border:[10,.3,"#000",d],type:3,title:["",!1],closeBtn:[0,!1]})}},h=function(a){g.times++,this.index=g.times;var b=this.config;this.config=e.extend({},b,a),this.config.dialog=e.extend({},b.dialog,a.dialog),this.config.page=e.extend({},b.page,a.page),this.config.iframe=e.extend({},b.iframe,a.iframe),this.config.loading=e.extend({},b.loading,a.loading),this.config.tips=e.extend({},b.tips,a.tips),this.creat()},h.pt=h.prototype,h.pt.config={type:0,shade:[.3,"#000",!0],shadeClose:!1,fix:!0,move:[".xubox_title",!0],moveOut:!1,title:["信息",!0],offset:["200px","50%"],area:["310px","auto"],closeBtn:[0,!0],time:0,bgcolor:"#fff",border:[10,.3,"#000",!0],zIndex:19891014,maxWidth:400,dialog:{btns:1,btn:["确定","取消"],type:3,msg:"",yes:function(a){layer.close(a)},no:function(a){layer.close(a)}},page:{dom:"#xulayer",html:""},iframe:{src:"http://sentsin.com"},loading:{type:0},tips:{msg:"",follow:"",guide:0,isGuide:!0,style:["background-color:#FF9900; color:#fff;","#FF9900"]},success:function(){},close:function(a){layer.close(a)},end:function(){}},h.pt.type=["dialog","page","iframe","loading","tips"],h.pt.space=function(a){var b,c,d,e,f,g,h,i,j,k,l,m;return a=a||"",b=this.index,c=this.config,d=c.dialog,e=['<div class="xubox_dialog"><span class="xubox_msg xulayer_png32 xubox_msgico xubox_msgtype'+d.type+'"></span><span class="xubox_msg xubox_text">'+d.msg+"</span></div>",'<div class="xubox_page">'+a+"</div>",'<iframe allowtransparency="true" id="xubox_iframe" name="xubox_iframe" onload="$(this).removeClass(\'xubox_load\');" class="xubox_iframe" frameborder="0" src="'+c.iframe.src+'"></iframe>','<span class="xubox_loading xubox_loading_'+c.loading.type+'"></span>','<div class="xubox_tips" style="'+c.tips.style[0]+'"><div class="xubox_tipsMsg">'+c.tips.msg+'</div><i class="layerTipsG"></i></div>'],f="",g="",h=c.zIndex+b,i="z-index:"+h+"; background-color:"+c.shade[1]+"; opacity:"+c.shade[0]+"; filter:alpha(opacity="+100*c.shade[0]+");",c.shade[2]&&(f='<div times="'+b+'" id="xubox_shade'+b+'" class="xubox_shade" style="'+i+'"></div>'),c.zIndex=h,j="",k="",l="z-index:"+(h-1)+";  background-color: "+c.border[2]+"; opacity:"+c.border[1]+"; filter:alpha(opacity="+100*c.border[1]+"); top:-"+c.border[0]+"px; left:-"+c.border[0]+"px;",c.border[3]&&(g='<div id="xubox_border'+b+'" class="xubox_border" style="'+l+'"></div>'),c.closeBtn[1]&&(k='<a class="xubox_close xulayer_png32 xubox_close'+c.closeBtn[0]+'" href="javascript:;"></a>'),c.title[1]&&(j='<h2 class="xubox_title"><em>'+c.title[0]+"</em></h2>"),m='<div times="'+b+'" showtime="'+c.time+'" style="z-index:'+h+'" id="xubox_layer'+b+'" class="xubox_layer">'+'<div style="background-color:'+c.bgcolor+"; z-index:"+h+'" class="xubox_main">'+e[c.type]+j+k+'<span class="xubox_botton"></span>'+"</div>"+g+"</div>",[f,m]},h.pt.creat=function(){var i,j,k,l,m,n,a=this,b="",c=this.config,d=c.dialog,h=a.config.title;switch(h.constructor===Array||(a.config.title=[h,!0]),h===!1&&(a.config.title=[h,!1]),i=c.page,j=e("body"),k=function(c){var c=c||"";b=a.space(c),j.append(b[0])},c.type){case 1:if(""!==i.html)k('<div id="xuboxPageHtml">'+i.html+"</div>"),j.append(b[1]);else{if(0!=e(i.dom).parents(".xubox_page").length)return;k(),e(i.dom).show().wrap(b[1])}break;case 2:e(".xubox_iframe")[0]&&layer.close(e(".xubox_iframe").parents(".xubox_layer").attr("times")),k(),j.append(b[1]);break;case 3:c.title=["",!1],c.area=["auto","auto"],c.closeBtn=["",!1],e(".xubox_loading")[0]&&layer.close(e(".xubox_loading").parents(".xubox_layer").attr("times")),k(),j.append(b[1]);break;case 4:c.title=["",!1],c.area=["auto","auto"],c.fix=!1,c.border=!1,e(".xubox_tips")[0]&&layer.close(e(".xubox_tips").parents(".xubox_layer").attr("times")),k(),j.append(b[1]),e("#xubox_layer"+g.times).find(".xubox_close").css({top:5,right:5});break;default:c.title[1]||(c.area=["auto","auto"]),e(".xubox_dialog")[0]&&layer.close(e(".xubox_dialog").parents(".xubox_layer").attr("times")),k(),j.append(b[1])}if(l=g.times,this.layerS=e("#xubox_shade"+l),this.layerB=e("#xubox_border"+l),this.layerE=e("#xubox_layer"+l),m=this.layerE,this.layerMian=m.find(".xubox_main"),this.layerTitle=m.find(".xubox_title"),this.layerText=m.find(".xubox_text"),this.layerPage=m.find(".xubox_page"),this.layerBtn=m.find(".xubox_botton"),n=-1!=c.offset[1].indexOf("px")?parseInt(c.offset[1]):"50%"==c.offset[1]?c.offset[1]:parseInt(c.offset[1])/100*f.width(),m.css({left:n+c.border[0],width:c.area[0],height:c.area[1]}),c.fix?m.css({top:parseInt(c.offset[0])+c.border[0]}):m.css({top:parseInt(c.offset[0])+f.scrollTop()+c.border[0],position:"absolute"}),0==c.type&&c.title[1])switch(d.btns){case 0:a.layerBtn.html("").hide();break;case 2:a.layerBtn.html('<a href="javascript:;" class="xubox_yes xubox_botton2">'+d.btn[0]+"</a>"+'<a href="javascript:;" class="xubox_no xubox_botton3">'+d.btn[1]+"</a>");break;default:a.layerBtn.html('<a href="javascript:;" class="xubox_yes xubox_botton1">'+d.btn[0]+"</a>")}"auto"===m.css("left")?(m.hide(),setTimeout(function(){m.show(),a.reset(l)},500)):a.reset(l),this.callback()},h.pt.reset=function(a){var i,j,k,l,m,n,o,p,q,r,s,t,b=this,c=this.layerE,d=this.config,h=d.page;switch(b.autoArea(a),d.time<=0||b.autoclose(),d.move[1]?c.find(d.move[0]).css({cursor:"move"}):c.find(d.move[0]).css({cursor:"auto"}),d.title[1]?g.iE6&&b.layerTitle.css({width:c.outerWidth()}):4!=d.type&&c.find(".xubox_close").addClass("xubox_close1"),c.attr({type:b.type[d.type]}),d.type){case 1:c.find(h.dom).addClass("layer_pageContent"),b.layerPage.css({width:c.width()}),d.shade[2]&&c.css({zIndex:d.zIndex+1}),d.title[1]&&b.layerPage.css({top:b.layerTitle.outerHeight()});break;case 2:i=c.find(".xubox_iframe"),j=c.height(),i.addClass("xubox_load").css({width:c.width()}),d.title[1]?i.css({top:b.layerTitle.height(),height:j-b.layerTitle.height()}):i.css({top:0,height:j}),g.iE6&&i.attr("src",d.iframe.src);break;case 4:k=e(d.tips.follow),l=k.offset().top,m=l-c.outerHeight(),n=k.offset().left,o=n,p=d.tips.style[1],q=k.outerHeight(),r=k.outerWidth(),s=c.find(".layerTipsG"),r>d.maxWidth&&k.width(d.maxWidth),1===d.tips.guide?(t=f.width()-o-r-c.outerWidth()-10,m=l,t>0?(o=o+k.outerWidth()+10,s.removeClass("layerTipsL").addClass("layerTipsR").css({"border-right-color":p})):(o=o-c.outerWidth()-10,s.removeClass("layerTipsR").addClass("layerTipsL").css({"border-left-color":p}))):m-f.scrollTop()-12<=0?(m=l+q+10,s.removeClass("layerTipsT").addClass("layerTipsB").css({"border-bottom-color":p})):(m-=10,s.removeClass("layerTipsB").addClass("layerTipsT").css({"border-top-color":p})),d.tips.isGuide||s.remove(),c.css({top:m,left:o});break;default:this.layerMian.css({"background-color":"#fff"}),d.title[1]?this.layerText.css({paddingTop:18+b.layerTitle.outerHeight()}):(c.find(".xubox_msgico").css({top:"10px"}),b.layerText.css({marginTop:12}))}this.move()},h.pt.autoArea=function(){var m,n,o,p,q,b=this,c=b.layerE,d=b.config,f=d.page,h=b.layerMian,i=b.layerBtn,j=b.layerText,k=b.layerPage,l=b.layerB;switch("auto"===d.area[0]&&h.outerWidth()>=d.maxWidth&&c.css({width:d.maxWidth}),m=d.title[1]?b.layerTitle.innerHeight():0,d.type){case 0:n=i.find("a"),o=j.outerHeight()+20,p=n.length>0?n.outerHeight()+20:0;break;case 1:p=0,o=e(f.dom).outerHeight(),"auto"===d.area[0]&&c.css({width:k.outerWidth()}),""!==f.html&&(o=k.outerHeight());break;case 3:q=e(".xubox_loading"),p=0,o=q.outerHeight(),h.css({width:q.width()})}"50%"!==d.offset[1]&&""!=d.offset[1]||4===d.type?c.css({marginLeft:0}):c.css({marginLeft:-c.outerWidth()/2}),"auto"===d.area[1]&&h.css({height:m+o+p}),l.css({width:c.outerWidth()+2*d.border[0],height:c.outerHeight()+2*d.border[0]}),g.iE6&&"auto"!=d.area[0]&&h.css({width:c.outerWidth()})},h.pt.move=function(){var d,g,h,i,j,a=this,b=this.config,c=a.layerE.find(b.move[0]),k=0,l=0;b.move[1]&&c.attr("move","ok"),e(b.move[0]).on("mousedown",function(a){if(a.preventDefault(),"ok"===e(this).attr("move")){g=!0,d=e(this).parents(".xubox_layer");var b=d.offset().left,c=d.offset().top,m=d.width()-6,n=d.height()-6;e("#xubox_moves")[0]||e("body").append('<div id="xubox_moves" class="xubox_moves" style="left:'+b+"px; top:"+c+"px; width:"+m+"px; height:"+n+'px; z-index:30000000"></div>'),j=e("#xubox_moves"),h=a.pageX-j.position().left,i=a.pageY-j.position().top,k=f.scrollLeft(),"fixed"!==d.css("position")||(l=f.scrollTop())}}),e(document).mousemove(function(a){var c,e,k,l,m;g&&(a.preventDefault(),c=a.pageX-h,e="fixed"===d.css("position")?a.pageY-i:a.pageY-i,b.moveOut||(k=f.width()-j.outerWidth()-b.border[0],l=f.scrollTop(),m=b.border[0]+l,c<b.border[0]&&(c=b.border[0]),c>k&&(c=k),m>e&&(e=m),e>f.height()-j.outerHeight()-b.border[0]+l&&(e=f.height()-j.outerHeight()-b.border[0]+l)),j.css({left:c,top:e}))}).mouseup(function(){var a;g&&(a=0==parseInt(d.css("margin-left"))?parseInt(j.css("left")):parseInt(j.css("left"))+-parseInt(d.css("margin-left")),"fixed"===d.css("position")||(a-=d.parent().offset().left),d.css({left:a,top:parseInt(j.css("top"))-l}),j.remove()),g=!1})},h.pt.autoclose=function(){var a=this,b=this.config.time,c=function(){b--,0===b&&(layer.close(a.index),clearInterval(a.autotime))};this.autotime=setInterval(c,1e3)},g.config={end:{}},h.pt.callback=function(){this.openLayer();var a=this,b=this.layerE,c=this.config,d=c.dialog;this.config.success(b),g.iE6&&this.IE6(),b.find(".xubox_close").off("click").on("click",function(b){b.preventDefault(),c.close(a.index)}),b.find(".xubox_yes").off("click").on("click",function(b){b.preventDefault(),d.yes(a.index)}),b.find(".xubox_no").off("click").on("click",function(b){b.preventDefault(),d.no(a.index)}),this.layerS.off("click").on("click",function(b){b.preventDefault(),a.config.shadeClose&&layer.close(a.index)}),g.config.end[this.index]=c.end},h.pt.IE6=function(){var g,b=this.layerE,c=e("select"),d=b.offset().top;g=this.config.fix?function(){b.css({top:e(document).scrollTop()+d})}:function(){b.css({top:d})},g(),f.scroll(g),e.each(c,function(){var c=e(this);c.parents(".xubox_layer")[0]||"none"==c.css("display")||c.attr({layer:"1"}).hide()}),this.reselect=function(){e.each(c,function(){var c=e(this);c.parents(".xubox_layer")[0]||1==c.attr("layer")&&e(".xubox_layer").length<1&&c.removeAttr("layer").show()})}},h.pt.openLayer=function(){var a=this;layer.autoArea=function(b){return a.autoArea(b)},layer.getIndex=function(a){return e(a).parents(".xubox_layer").attr("times")},layer.getChildFrame=function(a){return e("#xubox_iframe").contents().find(a)},layer.getFrameIndex=function(){return e("#xubox_iframe").parents(".xubox_layer").attr("times")},layer.iframeAuto=function(){var g,a=[this.getChildFrame("body").outerWidth(),this.getChildFrame("body").outerHeight()],b=e("#xubox_iframe").parents(".xubox_layer"),c=b.attr("times"),d=b.find(".xubox_title"),f=0;!d||(f=d.height()),b.css({width:a[0],height:a[1]+f}),d.css({width:a[0]}),g=-parseInt(e("#xubox_border"+c).css("left")),e("#xubox_border"+c).css({width:a[0]+2*g,height:a[1]+2*g+f}),e("#xubox_iframe").css({width:a[0],height:a[1]})},layer.close=function(b){var f,c=e("#xubox_layer"+b),d=e("#xubox_shade"+b);if(c.attr("type")==a.type[1])if(c.find("#xuboxPageHtml")[0])c.remove();else for(c.find(".xubox_close,.xubox_botton,.xubox_title,.xubox_border").remove(),f=0;3>f;f++)c.find(".layer_pageContent").unwrap().hide();else!-[1,]&&c.find("#xubox_iframe").remove(),c.remove();d.remove(),g.iE6&&a.reselect(),"function"==typeof g.config.end[b]&&g.config.end[b](),delete g.config.end[b]},layer.loadClose=function(){var a=e(".xubox_loading").parents(".xubox_layer"),b=a.attr("times");layer.close(b)},layer.shift=function(b,c){var l,d=a.config,e=g.iE6,h=a.layerE,i=0,j=f.width(),k=f.height();switch(i="50%"==d.offset[1]||""==d.offset[1]?h.outerWidth()/2:h.outerWidth(),l={t:{top:d.border[0]},b:{top:k-h.outerHeight()-d.border[0]},cl:i+d.border[0],ct:-h.outerHeight(),cr:j-i-d.border[0],fn:function(){e&&a.IE6()}},b){case"left-top":h.css({left:l.cl,top:l.ct}).animate(l.t,c,l.fn);break;case"right-top":h.css({left:l.cr,top:l.ct}).animate(l.t,c,l.fn);break;case"left-bottom":h.css({left:l.cl,top:k}).animate(l.b,c,l.fn);break;case"right-bottom":h.css({left:l.cr,top:k}).animate(l.b,c,l.fn)}},layer.setMove=function(){return a.move()}},g.run=function(){e=jQuery,f=e(a),this.load(),e.layer=function(a){var b=new h(a);return b.index}},i="../../init/jquery","function"==typeof define&&"object"==typeof seajs?define([i],function(b,c){g.run(),c.layer=[a.layer,a.$.layer]}):g.run()}(window);