forked from ajlkn/jquery.poptrox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.poptrox.min.js
1 lines (1 loc) · 11.7 KB
/
jquery.poptrox.min.js
1
!function(e){e.fn.poptrox_disableSelection=function(){return e(this).css("user-select","none").css("-khtml-user-select","none").css("-moz-user-select","none").css("-o-user-select","none").css("-webkit-user-select","none")},e.fn.poptrox=function(o){function t(){p=e(window).width(),s=e(window).height()+n.windowHeightPad;var o=Math.abs(x.width()-x.outerWidth()),t=Math.abs(x.height()-x.outerHeight()),i=(w.width(),w.height(),p-2*n.windowMargin-o),r=s-2*n.windowMargin-t;x.css("min-width",n.popupWidth).css("min-height",n.popupHeight),v.children().css("max-width",i).css("max-height",r)}if(0==this.length)return e(this);if(this.length>1){for(var i=0;i<this.length;i++)e(this[i]).poptrox(o);return e(this)}var p,s,n=e.extend({preload:!1,baseZIndex:1e3,fadeSpeed:300,overlayColor:"#000000",overlayOpacity:.6,overlayClass:"poptrox-overlay",windowMargin:50,windowHeightPad:0,selector:"a",caption:null,parent:"body",popupSpeed:300,popupWidth:200,popupHeight:100,popupIsFixed:!1,useBodyOverflow:!1,usePopupEasyClose:!0,usePopupForceClose:!1,usePopupLoader:!0,usePopupCloser:!0,usePopupCaption:!1,usePopupNav:!1,usePopupDefaultStyling:!0,popupBackgroundColor:"#FFFFFF",popupTextColor:"#000000",popupLoaderTextSize:"2em",popupCloserBackgroundColor:"#000000",popupCloserTextColor:"#FFFFFF",popupCloserTextSize:"20px",popupPadding:10,popupCaptionHeight:60,popupCaptionTextSize:null,popupBlankCaptionText:"(untitled)",popupCloserText:"×",popupLoaderText:"••••",popupClass:"poptrox-popup",popupSelector:null,popupLoaderSelector:".loader",popupCloserSelector:".closer",popupCaptionSelector:".caption",popupNavPreviousSelector:".nav-previous",popupNavNextSelector:".nav-next",onPopupClose:null,onPopupOpen:null,onCaptionLoaded:null},o),r=e(this),a=e("body"),l=e('<div class="'+n.overlayClass+'"></div>'),u=e(window),d=[],h=0,g=!1,f=new Array;n.usePopupLoader||(n.popupLoaderSelector=null),n.usePopupCloser||(n.popupCloserSelector=null),n.usePopupCaption||(n.popupCaptionSelector=null),n.usePopupNav||(n.popupNavPreviousSelector=null,n.popupNavNextSelector=null);var x;x=e(n.popupSelector?n.popupSelector:'<div class="'+n.popupClass+'">'+(n.popupLoaderSelector?'<div class="loader">'+n.popupLoaderText+"</div>":"")+'<div class="pic"></div>'+(n.popupCaptionSelector?'<div class="caption"></div>':"")+(n.popupCloserSelector?'<span class="closer">'+n.popupCloserText+"</span>":"")+(n.popupNavPreviousSelector?'<div class="nav-previous"></div>':"")+(n.popupNavNextSelector?'<div class="nav-next"></div>':"")+"</div>");var v=x.find(".pic"),w=e(),b=x.find(n.popupLoaderSelector),m=x.find(n.popupCaptionSelector),C=x.find(n.popupCloserSelector),y=x.find(n.popupNavNextSelector),S=x.find(n.popupNavPreviousSelector),P=y.add(S);if(n.usePopupDefaultStyling&&(x.css("background",n.popupBackgroundColor).css("color",n.popupTextColor).css("padding",n.popupPadding+"px"),m.length>0&&(x.css("padding-bottom",n.popupCaptionHeight+"px"),m.css("position","absolute").css("left","0").css("bottom","0").css("width","100%").css("text-align","center").css("height",n.popupCaptionHeight+"px").css("line-height",n.popupCaptionHeight+"px"),n.popupCaptionTextSize&&m.css("font-size",popupCaptionTextSize)),C.length>0&&C.html(n.popupCloserText).css("font-size",n.popupCloserTextSize).css("background",n.popupCloserBackgroundColor).css("color",n.popupCloserTextColor).css("display","block").css("width","40px").css("height","40px").css("line-height","40px").css("text-align","center").css("position","absolute").css("text-decoration","none").css("outline","0").css("top","0").css("right","-40px"),b.length>0&&b.html("").css("position","relative").css("font-size",n.popupLoaderTextSize).on("startSpinning",function(o){var t=e("<div>"+n.popupLoaderText+"</div>");t.css("height",Math.floor(n.popupHeight/2)+"px").css("overflow","hidden").css("line-height",Math.floor(n.popupHeight/2)+"px").css("text-align","center").css("margin-top",Math.floor((x.height()-t.height()+(m.length>0?m.height():0))/2)).css("color",n.popupTextColor?n.popupTextColor:"").on("xfin",function(){t.fadeTo(300,.5,function(){t.trigger("xfout")})}).on("xfout",function(){t.fadeTo(300,.05,function(){t.trigger("xfin")})}).trigger("xfin"),b.append(t)}).on("stopSpinning",function(e){var o=b.find("div");o.remove()}),2==P.length)){P.css("font-size","75px").css("text-align","center").css("color","#fff").css("text-shadow","none").css("height","100%").css("position","absolute").css("top","0").css("opacity","0.35").css("cursor","pointer").css("box-shadow","inset 0px 0px 10px 0px rgba(0,0,0,0)").poptrox_disableSelection();var k,T;n.usePopupEasyClose?(k="100px",T="100px"):(k="75%",T="25%"),y.css("right","0").css("width",k).html('<div style="position: absolute; height: 100px; width: 125px; top: 50%; right: 0; margin-top: -50px;">></div>'),S.css("left","0").css("width",T).html('<div style="position: absolute; height: 100px; width: 125px; top: 50%; left: 0; margin-top: -50px;"><</div>')}return u.on("resize orientationchange",function(){t()}),m.on("update",function(e,o){o&&0!=o.length||(o=n.popupBlankCaptionText),m.html(o),n.onCaptionLoaded&&n.onCaptionLoaded(x)}),C.css("cursor","pointer").on("click",function(e){return e.preventDefault(),e.stopPropagation(),x.trigger("poptrox_close"),!0}),y.on("click",function(e){e.stopPropagation(),e.preventDefault(),x.trigger("poptrox_next")}),S.on("click",function(e){e.stopPropagation(),e.preventDefault(),x.trigger("poptrox_previous")}),l.css("position","fixed").css("left",0).css("top",0).css("z-index",n.baseZIndex).css("width","100%").css("height","100%").css("text-align","center").css("cursor","pointer").appendTo(n.parent).prepend('<div style="display:inline-block;height:100%;vertical-align:middle;"></div>').append('<div style="position:absolute;left:0;top:0;width:100%;height:100%;background:'+n.overlayColor+";opacity:"+n.overlayOpacity+";filter:alpha(opacity="+100*n.overlayOpacity+');"></div>').hide().on("touchmove",function(e){return!1}).on("click",function(e){e.preventDefault(),e.stopPropagation(),x.trigger("poptrox_close")}),x.css("display","inline-block").css("vertical-align","middle").css("position","relative").css("z-index",1).css("cursor","auto").appendTo(l).hide().on("poptrox_next",function(){var e=h+1;e>=d.length&&(e=0),x.trigger("poptrox_switch",[e])}).on("poptrox_previous",function(){var e=h-1;0>e&&(e=d.length-1),x.trigger("poptrox_switch",[e])}).on("poptrox_reset",function(){t(),x.data("width",n.popupWidth).data("height",n.popupHeight),b.hide().trigger("stopSpinning"),m.hide(),C.hide(),P.hide(),v.hide(),w.attr("src","").detach()}).on("poptrox_open",function(e,o){return g?!0:(g=!0,n.useBodyOverflow&&a.css("overflow","hidden"),n.onPopupOpen&&n.onPopupOpen(),void l.fadeTo(n.fadeSpeed,1,function(){x.trigger("poptrox_switch",[o,!0])}))}).on("poptrox_switch",function(o,i,p){var s;if(!p&&g)return!0;if(g=!0,x.css("width",x.data("width")).css("height",x.data("height")),m.hide(),w.attr("src")&&w.attr("src",""),w.detach(),s=d[i],w=s.object,w.off("load"),v.css("text-indent","-9999px").show().append(w),"ajax"==s.type?e.get(s.src,function(e){w.html(e),w.trigger("load")}):w.attr("src",s.src),"image"!=s.type){var r,a;r=s.width,a=s.height,"%"==r.slice(-1)&&(r=parseInt(r.substring(0,r.length-1))/100*u.width()),"%"==a.slice(-1)&&(a=parseInt(a.substring(0,a.length-1))/100*u.height()),w.css("position","relative").css("outline","0").css("z-index",n.baseZIndex+100).width(r).height(a)}b.trigger("startSpinning").fadeIn(300),x.show(),n.popupIsFixed?(x.width(n.popupWidth).height(n.popupHeight),w.load(function(){w.off("load"),b.hide().trigger("stopSpinning"),m.trigger("update",[s.captionText]).fadeIn(n.fadeSpeed),C.fadeIn(n.fadeSpeed),v.css("text-indent",0).hide().fadeIn(n.fadeSpeed,function(){g=!1}),h=i,P.fadeIn(n.fadeSpeed)})):w.load(function(){t(),w.off("load"),b.hide().trigger("stopSpinning");var e=w.width(),o=w.height(),p=function(){m.trigger("update",[s.captionText]).fadeIn(n.fadeSpeed),C.fadeIn(n.fadeSpeed),v.css("text-indent",0).hide().fadeIn(n.fadeSpeed,function(){g=!1}),h=i,P.fadeIn(n.fadeSpeed),x.data("width",e).data("height",o).css("width","auto").css("height","auto")};e==x.data("width")&&o==x.data("height")?p():x.animate({width:e,height:o},n.popupSpeed,"swing",p)}),"image"!=s.type&&w.trigger("load")}).on("poptrox_close",function(){return g&&!n.usePopupForceClose?!0:(g=!0,x.hide().trigger("poptrox_reset"),n.onPopupClose&&n.onPopupClose(),void l.fadeOut(n.fadeSpeed,function(){n.useBodyOverflow&&a.css("overflow","auto"),g=!1}))}).trigger("poptrox_reset"),n.usePopupEasyClose?(m.on("click","a",function(e){e.stopPropagation()}),x.css("cursor","pointer").on("click",function(e){e.stopPropagation(),e.preventDefault(),x.trigger("poptrox_close")})):x.on("click",function(e){e.stopPropagation()}),u.keydown(function(e){if(x.is(":visible"))switch(e.keyCode){case 37:case 32:if(n.usePopupNav)return x.trigger("poptrox_previous"),!1;break;case 39:if(n.usePopupNav)return x.trigger("poptrox_next"),!1;break;case 27:return x.trigger("poptrox_close"),!1}}),r.find(n.selector).each(function(o){var t,i,p=e(this),s=p.find("img"),r=p.data("poptrox");if("ignore"!=r&&p.attr("href")){if(t={src:p.attr("href"),captionText:s.attr("title"),width:null,height:null,type:null,object:null,options:null},n.caption){if("function"==typeof n.caption)c=n.caption(p);else if("selector"in n.caption){var a;a=p.find(n.caption.selector),"attribute"in n.caption?c=a.attr(n.caption.attribute):(c=a.html(),n.caption.remove===!0&&a.remove())}}else c=s.attr("title");if(t.captionText=c,r){var l=r.split(",");0 in l&&(t.type=l[0]),1 in l&&(i=l[1].match(/([0-9%]+)x([0-9%]+)/),i&&3==i.length&&(t.width=i[1],t.height=i[2])),2 in l&&(t.options=l[2])}if(!t.type)switch(i=t.src.match(/\/\/([a-z0-9\.]+)\/.*/),(!i||i.length<2)&&(i=[!1]),i[1]){case"api.soundcloud.com":t.type="soundcloud";break;case"youtu.be":t.type="youtube";break;case"vimeo.com":t.type="vimeo";break;case"wistia.net":t.type="wistia";break;case"bcove.me":t.type="bcove";break;default:t.type="image"}switch(i=t.src.match(/\/\/[a-z0-9\.]+\/(.*)/),t.type){case"iframe":t.object=e('<iframe src="" frameborder="0"></iframe>'),t.object.on("click",function(e){e.stopPropagation()}).css("cursor","auto"),t.width&&t.height||(t.width="600",t.height="400");break;case"ajax":t.object=e('<div class="poptrox-ajax"></div>'),t.object.on("click",function(e){e.stopPropagation()}).css("cursor","auto").css("overflow","auto"),t.width&&t.height||(t.width="600",t.height="400");break;case"soundcloud":t.object=e('<iframe scrolling="no" frameborder="no" src=""></iframe>'),t.src="//w.soundcloud.com/player/?url="+escape(t.src)+(t.options?"&"+t.options:""),t.width="600",t.height="166";break;case"youtube":t.object=e('<iframe src="" frameborder="0" allowfullscreen="1"></iframe>'),t.src="//www.youtube.com/embed/"+i[1]+(t.options?"?"+t.options:""),t.width&&t.height||(t.width="800",t.height="480");break;case"vimeo":t.object=e('<iframe src="" frameborder="0" allowFullScreen="1"></iframe>'),t.src="//player.vimeo.com/video/"+i[1]+(t.options?"?"+t.options:""),t.width&&t.height||(t.width="800",t.height="480");break;case"wistia":t.object=e('<iframe src="" frameborder="0" allowFullScreen="1"></iframe>'),t.src="//fast.wistia.net/"+i[1]+(t.options?"?"+t.options:""),t.width&&t.height||(t.width="800",t.height="480");break;case"bcove":t.object=e('<iframe src="" frameborder="0" allowFullScreen="1" width="100%"></iframe>'),t.src="//bcove.me/"+i[1]+(t.options?"?"+t.options:""),t.width&&t.height||(t.width="640",t.height="360");break;default:if(t.object=e('<img src="" alt="" style="vertical-align:bottom" />'),n.preload){var i=document.createElement("img");i.src=t.src,f.push(i)}t.width=p.attr("width"),t.height=p.attr("height")}"file:"==window.location.protocol&&t.src.match(/^\/\//)&&(t.src="http:"+t.src),d.push(t),s.attr("title",""),p.attr("href","").css("outline",0).on("click",function(e){e.preventDefault(),e.stopPropagation(),x.trigger("poptrox_open",[o])})}}),e(this)}}(jQuery);