forked from ajlkn/jquery.poptrox
/
jquery.poptrox.min.js
21 lines (21 loc) · 10.1 KB
/
jquery.poptrox.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* jquery.poptrox.js v2.3.3 | (c) n33 | n33.co | MIT licensed */
(function(d){d.fn.poptrox_disableSelection=function(){return d(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")};d.fn.poptrox=function(v){function y(){z=d(window).width();w=d(window).height()+a.windowHeightPad}if(1<this.length){for(var n=0;n<this.length;n++)d(this[n]).poptrox(v);return d(this)}var a=d.extend({preload:!1,baseZIndex:1E3,fadeSpeed:300,overlayColor:"#000000",overlayOpacity:0.6,
windowMargin:50,windowHeightPad:0,selector:"a",popupSpeed:300,popupWidth:200,popupHeight:100,popupIsFixed:!1,useBodyOverflow:!0,usePopupEasyClose:!0,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},v);v=d(this);var F=d("body"),h=d("<div></div>"),A=d(window),z,w,x=[],t=0,m=!1,H=[],G=(n=navigator.userAgent.match(/MSIE ([0-9]+)\./)&&6==RegExp.$1)?"absolute":"fixed";a.usePopupLoader||
(a.popupLoaderSelector=null);a.usePopupCloser||(a.popupCloserSelector=null);a.usePopupCaption||(a.popupCaptionSelector=null);a.usePopupNav||(a.popupNavPreviousSelector=null,a.popupNavNextSelector=null);var c;c=a.popupSelector?d(a.popupSelector):d('<div class="'+a.popupClass+'">'+(a.popupLoaderSelector?'<div class="loader">'+a.popupLoaderText+"</div>":"")+'<div class="pic"></div>'+(a.popupCaptionSelector?'<div class="caption"></div>':"")+(a.popupCloserSelector?'<span class="closer">'+a.popupCloserText+
"</span>":"")+(a.popupNavPreviousSelector?'<div class="nav-previous"></div>':"")+(a.popupNavNextSelector?'<div class="nav-next"></div>':"")+"</div>");var s=c.find(".pic"),f=d(),p=c.find(a.popupLoaderSelector),k=c.find(a.popupCaptionSelector),r=c.find(a.popupCloserSelector),B=c.find(a.popupNavNextSelector),C=c.find(a.popupNavPreviousSelector),u=B.add(C);if(a.usePopupDefaultStyling){c.css("background",a.popupBackgroundColor);c.css("color",a.popupTextColor);c.css("padding",a.popupPadding+"px");0<k.length&&
(c.css("padding-bottom",a.popupCaptionHeight+"px"),k.css("position","absolute").css("left","0").css("bottom","0").css("width","100%").css("text-align","center").css("height",a.popupCaptionHeight+"px").css("line-height",a.popupCaptionHeight+"px"),a.popupCaptionTextSize&&k.css("font-size",popupCaptionTextSize));0<r.length&&r.html(a.popupCloserText).css("font-size",a.popupCloserTextSize).css("background",a.popupCloserBackgroundColor).css("color",a.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");if(0<p.length)p.html("").css("position","relative").css("font-size",a.popupLoaderTextSize).on("startSpinning",function(I){var b=d("<div>"+a.popupLoaderText+"</div>");b.css("height",Math.floor(a.popupHeight/2)+"px").css("overflow","hidden").css("line-height",Math.floor(a.popupHeight/2)+"px").css("text-align",
"center").css("margin-top",Math.floor((c.height()-b.height()+(0<k.length?k.height():0))/2)).css("color",a.popupTextColor?a.popupTextColor:"").on("xfin",function(){b.fadeTo(300,0.5,function(){b.trigger("xfout")})}).on("xfout",function(){b.fadeTo(300,0.05,function(){b.trigger("xfin")})}).trigger("xfin");p.append(b)}).on("stopSpinning",function(a){p.find("div").remove()});if(2==u.length){u.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 D,E;a.usePopupEasyClose?E=D="100px":(D="75%",E="25%");B.css("right","0").css("width",D).html('<div style="position: absolute; height: 100px; width: 125px; top: 50%; right: 0; margin-top: -50px;">></div>');C.css("left","0").css("width",E).html('<div style="position: absolute; height: 100px; width: 125px; top: 50%; left: 0; margin-top: -50px;"><</div>')}}A.on("orientationchange",
function(){A.trigger("resize")}).resize(function(){y();c.trigger("poptrox_close")});k.on("update",function(c,b){b&&0!=b.length||(b=a.popupBlankCaptionText);k.html(b)});r.css("cursor","pointer").on("click",function(a){a.preventDefault();a.stopPropagation();c.trigger("poptrox_close");return!0});B.on("click",function(){c.trigger("poptrox_next")});C.on("click",function(){c.trigger("poptrox_previous")});h.prependTo("body").hide();n?h.css("position","absolute"):h.css("position",G).css("left",0).css("top",
0).css("z-index",a.baseZIndex).css("width","200%").css("height","200%").css("background-color",a.overlayColor);h.css("cursor","pointer").on("click",function(a){a.preventDefault();a.stopPropagation();c.trigger("poptrox_close")});if(a.usePopupEasyClose)s.css("cursor","pointer").on("click",function(a){a.preventDefault();a.stopPropagation();c.trigger("poptrox_close")});c.on("poptrox_next",function(){var a=t+1;a>=x.length&&(a=0);c.trigger("poptrox_switch",[a])}).on("poptrox_previous",function(){var a=
t-1;0>a&&(a=x.length-1);c.trigger("poptrox_switch",[a])}).on("poptrox_reset",function(){y();c.css("position",G).css("z-index",a.baseZIndex+1).css("width",a.popupWidth+"px").css("height",a.popupHeight+"px").css("left",z/2+"px").css("top",w/2+"px").css("top",w/2+"px").css("margin-left",-1*(c.outerWidth()/2)+"px").css("margin-top",-1*(c.outerHeight()/2)+"px");p.hide().trigger("stopSpinning");k.hide();r.hide();u.hide();s.hide();f.detach()}).on("poptrox_open",function(d,b){if(m)return!0;m=!0;a.useBodyOverflow&&
F.css("overflow","hidden");if(a.onPopupOpen)a.onPopupOpen();h.fadeTo(a.fadeSpeed,a.overlayOpacity,function(){c.trigger("poptrox_switch",[b,!0])})}).on("poptrox_switch",function(h,b,e){var g;if(!e&&m)return!0;m=!0;k.hide();f.attr("src")&&f.attr("src","");f.detach();g=x[b];f=g.object;f.off("load");s.css("text-indent","-9999em").show().append(f);"ajax"==g.type?d.get(g.src,function(a){f.html(a);f.trigger("load")}):f.attr("src",g.src);"image"!=g.type&&f.css("position","relative").css("outline","0").css("z-index",
a.baseZIndex+100).width(g.width).height(g.height);p.trigger("startSpinning").fadeIn(300);c.show();a.popupIsFixed?(c.width(a.popupWidth).height(a.popupHeight).css("margin-left",-1*(c.innerWidth()/2)+"px").css("margin-top",-1*(c.innerHeight()/2)+"px"),f.load(function(){f.off("load");p.hide().trigger("stopSpinning");k.trigger("update",[g.captionText]).fadeIn(a.fadeSpeed);r.fadeIn(a.fadeSpeed);s.css("text-indent",0).hide().fadeIn(a.fadeSpeed,function(){m=!1});t=b;u.fadeIn(a.fadeSpeed)})):f.load(function(){f.off("load");
y();var d=Math.abs(c.width()-c.outerWidth()),e=Math.abs(c.height()-c.outerHeight()),l=f.width(),q=f.height(),h=z-2*a.windowMargin-d,n=w-2*a.windowMargin-e;p.hide().trigger("stopSpinning");if(l>h||q>n)h=Math.min(h/l,n/q),l=Math.floor(h*l),q=Math.floor(h*q),f.width(l).height(q);c.innerWidth()==l+d&&c.innerHeight()==q+e?(k.trigger("update",[g.captionText]).fadeIn(a.fadeSpeed),r.fadeIn(a.fadeSpeed),s.css("text-indent",0).hide().fadeIn(a.fadeSpeed,function(){m=!1}),t=b):c.animate({width:l,height:q,marginLeft:-1*
(l/2)-d/2,marginTop:-1*(q/2)-e/2},a.popupSpeed,"swing",function(){k.trigger("update",[g.captionText]).fadeIn(a.fadeSpeed);r.fadeIn(a.fadeSpeed);s.css("text-indent",0).hide().fadeIn(a.fadeSpeed,function(){m=!1});t=b;u.fadeIn(a.fadeSpeed)})});"image"!=g.type&&f.trigger("load")}).on("poptrox_close",function(){if(m)return!0;m=!0;c.hide().trigger("poptrox_reset");if(a.onPopupClose)a.onPopupClose();h.fadeOut(a.fadeSpeed,function(){a.useBodyOverflow&&F.css("overflow","auto");m=!1})}).prependTo("body").hide().trigger("poptrox_reset");
A.keydown(function(d){if(c.is(":visible"))switch(d.keyCode){case 37:case 32:if(a.usePopupNav)return c.trigger("poptrox_previous"),!1;break;case 39:if(a.usePopupNav)return c.trigger("poptrox_next"),!1;break;case 27:return c.trigger("poptrox_close"),!1}});v.find(a.selector).each(function(f){var b,e,g=d(this),h=g.find("img");e=g.data("poptrox");b={src:g.attr("href"),captionText:h.attr("title"),width:g.attr("width"),height:g.attr("height"),type:null,object:null};if(e){var k,l=e.split(",");for(k in l)(e=
l[k].match(/([0-9]+)x([0-9]+)/))&&3==e.length?(b.width=e[1],b.height=e[2]):b.type=l[k]}if(!b.type){e=b.src.match(/http[s]?:\/\/([a-z0-9\.]+)\/.*/);if(!e||3>e.length)e=[!1];switch(e[1]){case "api.soundcloud.com":b.type="soundcloud";break;case "youtu.be":b.type="youtube";break;case "vimeo.com":b.type="vimeo";break;default:b.type="image"}}if(e=b.src.match(/http([s]?):\/\/[a-z0-9\.]+\/(.*)/))b.prefix="http"+("s"==e[1]?"s":"");switch(b.type){case "ignore":break;case "iframe":b.object=d('<iframe src="" frameborder="0"></iframe>');
b.object.on("click",function(a){a.stopPropagation()}).css("cursor","auto");break;case "ajax":b.object=d('<div class="poptrox-ajax"></div>');b.object.on("click",function(a){a.stopPropagation()}).css("cursor","auto").css("overflow","auto");break;case "soundcloud":b.object=d('<iframe scrolling="no" frameborder="no" src=""></iframe>');b.src=b.prefix+"://w.soundcloud.com/player/?url="+escape(b.src);b.width="600";b.height="166";break;case "youtube":b.object=d('<iframe src="" frameborder="0" allowfullscreen="1"></iframe>');
b.src=b.prefix+"://www.youtube.com/embed/"+e[2];break;case "vimeo":b.object=d('<iframe src="" frameborder="0" allowFullScreen="1"></iframe>');b.src=b.prefix+"://player.vimeo.com/video/"+e[2];break;default:b.object=d('<img src="" alt="" />'),a.preload&&(e=document.createElement("img"),e.src=b.src,H.push(e))}x.push(b);h.attr("title","");if("ignore"!=b.type)g.attr("href","").css("outline",0).on("click",function(a){a.preventDefault();a.stopPropagation();c.trigger("poptrox_open",[f])})});return d(this)}})(jQuery);