-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.flyout.min.js
9 lines (9 loc) · 4.02 KB
/
jquery.flyout.min.js
1
2
3
4
5
6
7
8
9
(function(c){jQuery.fn.extend({flyout:function(G){function h(a){a=parseInt(a,10);return isNaN(a)?0:a}function u(m,C){var r=a.displayType;C&&(a.displayType="fit",r="fill");v=!0;y=c(m);g=c("img",m);w=new Image;var u=c(window).scrollLeft(),B=c(window).scrollTop();a.debug&&console.log("scroll LeftTop",u,B);d=g.offset();d.left+=a.startOffsetX;d.top+=a.startOffsetY;z=0<a.startHeight?a.startHeight:g.height();A=0<a.startWidth?a.startWidth:g.width();x=c("<div></div>").attr("id",a.loader).appendTo("body").css({position:"absolute",
top:-9999,left:-9999,height:z,width:A,opacity:a.loaderOpacity,display:"block","z-index":a.loaderZIndex,"line-height":"0px"});D=h(x.css("borderTopWidth"))+h(x.css("paddingTop"))-h(g.css("borderTopWidth"))-h(g.css("paddingTop"));E=h(x.css("borderLeftWidth"))+h(x.css("paddingLeft"))-h(g.css("borderLeftWidth"))-h(g.css("paddingLeft"));x.css({top:d.top-D,left:d.left-E});a.loadingSrc?c("#"+a.loader).append(c("<img/>").on("load",function(){c(this).css({position:"relative",top:z/2-this.height/2,left:A/2-
this.width/2}).attr("alt",a.loadingText)}).attr("src",a.loadingSrc)):c("#"+a.loader).css("background-color","#000").append(c("<span></span>").text(a.loadingText).css({position:"relative",top:"2px",left:"2px",color:"#FFF","font-size":"9px"}));c(w).on("load",function(){var h=c("<img/>").attr("src",y.attr("href")).attr("title",g.attr("title")+a.closeTip).attr("alt",g.attr("alt")+a.closeTip).height(z).width(A);a.flyOutStart.call(m);if(a.useNative||!document.doctype){a.debug&&console.log("using native window inner dims");
var t=window.innerHeight;var n=window.innerWidth}else t=c(window).height(),n=c(window).width();a.debug&&console.log("viewport WidthHeight",n,t);if(a.destElement){var p=c(a.destElement);var C=p.innerWidth()-2*a.destPadding;var e=p.innerHeight()-2*a.destPadding}else C=n-a.widthMargin,e=t-a.heightMargin;var k=w.width,l=w.height,b=n/k,f=t/l;a.debug&&console.log("flyout WidthHeight factors",b,f);"full"==r?(e=k,b=l):"fit"==r?b<f?(e=k*b,b*=l):(e=k*f,b=l*f):"fill"==r?b>f?(e=k*b,b*=l):(e=k*f,b=l*f):(b=C/k,
f=e/l,b<=f?f=b:b=f,e=Math.round(k*b),b=Math.round(l*f),e>k&&(e=k),b>l&&(b=l));a.debug&&console.log("flyout WidthHeight",e,b);a.destElement?(t=p.offset(),n=Math.round(p.outerWidth()/2-e/2+t.left),p=Math.round(p.outerHeight()/2-b/2+t.top)):(n=Math.round(n/2-e/2+u),p=Math.round(t/2-b/2+B));a.debug&&console.log("flyout LeftTop",n,p);c("#"+a.loader).empty().css({opacity:a.inOpacity,top:d.top-D,left:d.left-E}).append(h).width("auto").height("auto").animate({top:p,left:n,opacity:a.outOpacity},{duration:a.outSpeed,
queue:!1,easing:a.outEase});c("#"+a.loader+" img").animate({height:b,width:e,opacity:a.outOpacity},a.outSpeed,a.outEase,function(){a.flyOutFinish.call(m);q=m;y.addClass(a.shownClass);v=!1;c("#"+a.loader+" img").click(function(){F(null)})})});w.src=y.attr("href")}function F(m){if(!0===v||!1===q)return!1;a.putAwayStart.call(q);v=!0;d=g.offset();d.left+=a.startOffsetX-E;d.top+=a.startOffsetY-D;c("#"+a.loader).animate({top:d.top,left:d.left,opacity:a.inOpacity},{duration:a.inSpeed,queue:!1,easing:a.inEase});
c("#"+a.loader+" img").animate({height:z,width:A,opacity:a.inOpacity},a.inSpeed,a.inEase,function(){c("#"+a.loader).css("display","none").remove();a.putAwayFinish.call(q);v=!1;w=null;m&&m!==q&&(q=!1,u(m));q=!1;y.removeClass(a.shownClass)})}var a=jQuery.extend({outSpeed:1E3,inSpeed:500,outEase:"swing",inEase:"swing",loadingSrc:null,loader:"loader",loaderZIndex:500,loaderOpacity:.5,widthMargin:40,heightMargin:40,loadingText:"Loading...",closeTip:" - Click here to close",destPadding:20,startOffsetX:0,
startOffsetY:0,startHeight:0,startWidth:0,flyOutStart:function(){},flyOutFinish:function(){},putAwayStart:function(){},putAwayFinish:function(){},shownClass:"shown",inOpacity:1,outOpacity:1,useNative:!1,dblClickSpeed:0,displayType:"default",debug:!1},G),q=!1,v=!1,w=new Image,y,g,x,d,z,A,D,E,B,r=0;this.click(function(c){if(!0===v)return!1;r++;var d=this;1===r?B=setTimeout(function(){q?F(d):u(d,!1);r=0},a.dblClickSpeed):(clearTimeout(B),q?F(d):u(d,!0),r=0);return!1}).dblclick(function(a){a.preventDefault()});
return this}})})(jQuery);