-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpsshowlayer.min.js
1 lines (1 loc) · 5.24 KB
/
lpsshowlayer.min.js
1
!function(a){a.fn.lpsShowLayer=function(b){var c,d,e,f,g,h,i,j,k;for(b=a.extend({address:a(this).attr("src"),closeBtnStyle:"",closeLayer:!1,layerPadding:"60px",stretch:!1,title:a(this).attr("alt"),titleStyle:"",layerBoxStyle:"box-shadow:0 4px 16px #000;",layerCoverStyle:"",type:"img",show:function(){},html:"",drag:!1,resize:!1},b),c="",d="LpsLayer";a("#LpsLayer"+c).length>0;c++);return a("body").append("<div style='width: 100%; height: 100%; position: absolute; background: none; top: 0; left: 0; z-index: 9999;' id='"+d+c+"'><div id='"+d+"Con"+c+"' style='position: relative;height:100%;'><div id='"+d+"Title"+c+"' style='overflow: hidden; background: #eee; height: 30px; line-height: 30px;width: 100%;'><span style='padding:0 26px 0 10px;display:block;'>"+(b.title?b.title:"")+"</span></div><span style='border: 1px solid #ccc; background: #fff; font-family: Microsoft Yahei; position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; line-height: 20px; text-align: center; cursor: pointer;' id='"+d+"Close"+c+"'>X</span><div id='"+d+"ConInner"+c+"' style='overflow:hidden;background:#fff;'></div><i id='"+d+"resizebtn"+c+"' style='display:none;position:absolute;right:0;bottom:0;height:0;line-height:1px;border-bottom:12px solid #000;border-left:12px solid transparent;_border-left-color:#fff;z-index:10;cursor:nw-resize;'></i></div></div><div style='position: absolute; z-index: 999; background: #ccc; opacity: 0.6; filter: alpha(opacity=60); top: 0; left: 0; width: 100%; height: 100%;' id='"+d+"Cover"+c+"'></div>"),"img"==b.type?a("#"+d+"ConInner"+c).html("<img style='display:block;margin:0 auto;height:100%;' src='"+b.address+"'/>"):a("#"+d+"ConInner"+c).html("<iframe style='width:100%;height:100%;' frameBorder='0' src='"+b.address+"'></iframe>"),e={html:a("html"),body:function(){return this.html.find("body")},btnclose:function(){return this.html.find("#"+d+"Close"+c)},contentinner:function(){return this.html.find("#"+d+"ConInner"+c)},iframe:function(){return this.contentinner().find("iframe")},img:function(){return this.contentinner().find("img")},layer:function(){return this.html.find("#"+d+c)},layercover:function(){return this.html.find("#"+d+"Cover"+c)},title:function(){return this.html.find("#"+d+"Title"+c)},resizebtn:function(){return this.html.find("#"+d+"resizebtn"+c)},win:a(window)},b.titleStyle&&(e.title()[0].style.cssText+=";"+b.titleStyle),b.closeBtnStyle&&(e.btnclose()[0].style.cssText+=";"+b.closeBtnStyle),b.layerCoverStyle&&(e.layercover()[0].style.cssText+=";"+b.layerCoverStyle),b.layerBoxStyle&&(e.layer()[0].style.cssText+=";"+b.layerBoxStyle),f=function(){var a,c;e.html.css("overflow","hidden"),e.body().css("overflow","hidden"),a=function(){var a=e.win.scrollTop(),c=e.win.scrollLeft();e.layercover().css({top:a,height:e.win.height()}),e.layer().css({overflow:"hidden",top:a+parseInt(b.layerPadding),left:c+parseInt(b.layerPadding),width:e.win.width()-2*parseInt(b.layerPadding),height:e.win.height()-2*parseInt(b.layerPadding)}),e.contentinner().height(e.win.height()-2*parseInt(b.layerPadding)-e.title().innerHeight())},a(),e.win.resize(function(){a()}),"img"!=b.type||b.stretch?e.img().css({width:"100%",height:"100%"}):(c=function(){var a=1*(e.contentinner().width()/e.contentinner().height()),b=parseInt(e.img().width())/parseInt(e.img().height());a/b>1?e.img().css({width:"",height:e.contentinner().height()}):e.img().css({width:e.contentinner().width(),height:""})},c(),e.win.resize(function(){c()}))},g=function(){var b;for(a("#"+d+c).remove(),a("#"+d+"Cover"+c).remove(),b="";a("#"+d+b).length>0;b++);""==b&&(e.html.css("overflow",""),e.body().css("overflow",""))},b.closeLayer?(g(),void 0):"img"==b.type&&b.address&&(h=b.address.split("/"),i=h[h.length-1].toLowerCase(),!/\.(gif|jpg|jpeg|png|pic)$/.test(i))?(g(),!1):(f(),b.drag&&(e.title().css("cursor","move"),j=!1,e.title().mousedown(function(a){e.layer().appendTo(e.body()),e.layercover().css("height","100%"),j=!0;var b=a.pageX,c=a.pageY,d=e.layer().offset().left,f=e.layer().offset().top;e.html.mousemove(function(a){return j?(e.layer().css({left:d+a.pageX-b,top:f+a.pageY-c}),/MSIE/.test(navigator.userAgent)&&a.preventDefault(),!1):void 0}),e.html.mouseup(function(){e.html.unbind("mousemove"),j=!1})})),b.resize&&(k=!1,e.layer().hover(function(){e.resizebtn().css("display","block")},function(){e.resizebtn().css("display","none")}),e.resizebtn().mousedown(function(a){k=!0;var c=a.pageX,d=a.pageY,f=e.layer().width(),g=e.layer().height();e.html.mousemove(function(a){var h,i;return"img"!=b.type||b.stretch?e.img().css({width:"100%",height:"100%"}):(h=1*(e.contentinner().width()/e.contentinner().height()),i=parseInt(e.img().width())/parseInt(e.img().height()),h/i>1?e.img().css({width:"",height:e.contentinner().height()}):e.img().css({width:e.contentinner().width(),height:""})),k?(e.layer().css({width:f+a.pageX-c,height:g+a.pageY-d}),e.contentinner().css("height",e.layer().height()-e.title().height()),/MSIE/.test(navigator.userAgent)&&a.preventDefault(),!1):void 0}),e.html.mouseup(function(){e.html.unbind("mousemove"),k=!1})})),e.btnclose().click(function(a){g(),a.stopPropagation()}),b.show({close:g}),e.html.bind("click keydown",function(b){(a(b.target).attr("id")==d+"Cover"+c||"27"==b.keyCode)&&(g(),b.stopPropagation())}),b.html&&a("#"+d+"ConInner"+c).html(b.html),void 0)},a.lpsShowLayer=a.fn.lpsShowLayer}(jQuery);