pelican-alchemy/alchemy/static/js/jquery.fluidbox.min.js
Anthony Oduor 688fc0fbae Add support for fancy fluidbox #75
Updated base template
2015-01-30 08:22:01 +03:00

1 line
No EOL
6.2 KiB
JavaScript

function whichTransitionEvent(){var a,b=document.createElement("fakeelement"),c={transition:"transitionend",OTransition:"oTransitionEnd",MozTransition:"transitionend",WebkitTransition:"webkitTransitionEnd"};for(a in c)if(void 0!==b.style[a])return c[a]}!function(a,b){var c=function(a,b,c){var d;return function(){function g(){c||a.apply(e,f),d=null}var e=this,f=arguments;d?clearTimeout(d):c&&a.apply(e,f),d=setTimeout(g,b||100)}};jQuery.fn[b]=function(a){return a?this.bind("resize",c(a)):this.trigger(b)}}(jQuery,"smartresize");var customTransitionEnd=whichTransitionEvent();!function(a){var b=0;a.fn.fluidbox=function(c){var d=a.extend(!0,{viewportFill:.95,debounceResize:!0,stackIndex:1e3,stackIndexDelta:10,closeTrigger:[{selector:".fluidbox-overlay",event:"click"},{selector:"document",event:"keyup",keyCode:27}],immediateOpen:!1},c),e=["keyup","keydown","keypress"];d.stackIndex<d.stackIndexDelta&&(d.stackIndexDelta=d.stackIndex),$fbOverlay=a("<div />",{"class":"fluidbox-overlay",css:{"z-index":d.stackIndex}});var h,f=this,g=a(window),i=function(b){a(b+".fluidbox-opened").trigger("click")},j=function(b,c){var e=b.find("img"),f=b.find(".fluidbox-ghost"),i=b.find(".fluidbox-wrap"),j=b.data(),k=0,l=0;e.data().imgRatio=j.natWidth/j.natHeight;var m,n,o;h>e.data().imgRatio?(k=j.natHeight<g.height()*d.viewportFill?j.natHeight:g.height()*d.viewportFill,j.imgScale=k/e.height(),j.imgScaleY=j.imgScale,m=e.height()*j.imgScaleY,n=m/j.natHeight,o=j.natWidth*n/e.width(),j.imgScaleX=o):(l=j.natWidth<g.width()*d.viewportFill?j.natWidth:g.width()*d.viewportFill,j.imgScale=l/e.width(),j.imgScaleX=j.imgScale,newWidth=e.width()*j.imgScaleX,n=newWidth/j.natWidth,o=j.natHeight*n/e.height(),j.imgScaleY=o);var p=g.scrollTop()-e.offset().top+.5*e.data("imgHeight")*(e.data("imgScale")-1)+.5*(g.height()-e.data("imgHeight")*e.data("imgScale")),q=.5*e.data("imgWidth")*(e.data("imgScale")-1)+.5*(g.width()-e.data("imgWidth")*e.data("imgScale"))-e.offset().left,r=parseInt(1e3*j.imgScaleX)/1e3+","+parseInt(1e3*j.imgScaleY)/1e3;f.css({transform:"translate("+parseInt(10*q)/10+"px,"+parseInt(10*p)/10+"px) scale("+r+")",top:e.offset().top-i.offset().top,left:e.offset().left-i.offset().left}).one(customTransitionEnd,function(){a.each(c,function(a,c){b.trigger(c)})})},k=function(a){function i(){f.imgWidth=b.width(),f.imgHeight=b.height(),f.imgRatio=b.width()/b.height(),c.css({width:b.width(),height:b.height(),top:b.offset().top-e.offset().top+parseInt(b.css("borderTopWidth"))+parseInt(b.css("paddingTop")),left:b.offset().left-e.offset().left+parseInt(b.css("borderLeftWidth"))+parseInt(b.css("paddingLeft"))}),f.imgScale=h>f.imgRatio?g.height()*d.viewportFill/b.height():g.width()*d.viewportFill/b.width()}if(h=g.width()/g.height(),a.hasClass("fluidbox")){var b=a.find("img"),c=a.find(".fluidbox-ghost"),e=a.find(".fluidbox-wrap"),f=b.data();i(),b.load(i)}},l=function(b){if(a(this).hasClass("fluidbox")){var c=a(this),e=a(this).find("img"),f=a(this).find(".fluidbox-ghost"),g=a(this).find(".fluidbox-wrap"),h={},i=function(){c.trigger("openstart"),c.append($fbOverlay).data("fluidbox-state",1).removeClass("fluidbox-closed").addClass("fluidbox-opened"),h.close&&window.clearTimeout(h.close),h.open=window.setTimeout(function(){a(".fluidbox-overlay").css({opacity:1})},10),a(".fluidbox-wrap").css({zIndex:d.stackIndex-d.stackIndexDelta-1}),g.css({"z-index":d.stackIndex+d.stackIndexDelta})},k=function(){c.trigger("closestart"),c.data("fluidbox-state",0).removeClass("fluidbox-opened fluidbox-loaded fluidbox-loading").addClass("fluidbox-closed"),h.open&&window.clearTimeout(h.open),h.close=window.setTimeout(function(){a(".fluidbox-overlay").remove(),g.css({"z-index":d.stackIndex-d.stackIndexDelta})},10),a(".fluidbox-overlay").css({opacity:0}),f.css({transform:"translate(0,0) scale(1)",opacity:0,top:e.offset().top-g.offset().top+parseInt(e.css("borderTopWidth"))+parseInt(e.css("paddingTop")),left:e.offset().left-g.offset().left+parseInt(e.css("borderLeftWidth"))+parseInt(e.css("paddingLeft"))}).one(customTransitionEnd,function(){c.trigger("closeend")}),e.css({opacity:1})};0!==a(this).data("fluidbox-state")&&a(this).data("fluidbox-state")?k():(c.addClass("fluidbox-loading"),e.css({opacity:0}),f.css({"background-image":"url("+e.attr("src")+")",opacity:1}),d.immediateOpen?(c.data("natWidth",e[0].naturalWidth).data("natHeight",e[0].naturalHeight),i(),j(c,["openend"]),a("<img />",{src:c.attr("href")}).load(function(){c.trigger("imageloaddone").trigger("delayedloaddone").removeClass("fluidbox-loading").addClass("fluidbox-loaded").data("natWidth",a(this)[0].naturalWidth).data("natHeight",a(this)[0].naturalHeight),f.css({"background-image":"url("+c.attr("href")+")"}),j(c,["delayedreposdone"])}).error(function(){c.trigger("imageloadfail"),k()})):a("<img />",{src:c.attr("href")}).load(function(){c.trigger("imageloaddone").removeClass("fluidbox-loading").addClass("fluidbox-loaded").data("natWidth",a(this)[0].naturalWidth).data("natHeight",a(this)[0].naturalHeight),f.css({"background-image":"url("+c.attr("href")+")"}),i(),j(c,["openend"])}).error(function(){c.trigger("imageloadfail"),k()})),b.preventDefault()}},m=function(b){b?k(b):f.each(function(){k(a(this))});var c=a("a.fluidbox.fluidbox-opened");c.length>0&&j(c,["resizeend"])};return d.debounceResize?a(window).smartresize(function(){m()}):a(window).resize(function(){m()}),f.each(function(){if(a(this).is("a")&&1===a(this).children().length&&a(this).children().is("img")&&"none"!==a(this).css("display")&&"none"!==a(this).parents().css("display")){var f=a("<div />",{"class":"fluidbox-wrap",css:{"z-index":d.stackIndex-d.stackIndexDelta}});b+=1;var h=a(this);h.addClass("fluidbox fluidbox-closed").attr("id","fluidbox-"+b).wrapInner(f).find("img").css({opacity:1}).after('<div class="fluidbox-ghost" />').each(function(){var b=a(this);b.width()>0&&b.height()>0?(k(h),h.click(l)):b.load(function(){k(h),h.click(l),h.trigger("thumbloaddone")}).error(function(){h.trigger("thumbloadfail")})}),a(this).on("recompute",function(){m(a(this)),a(this).trigger("recomputeend")});var j="#fluidbox-"+b;d.closeTrigger&&a.each(d.closeTrigger,function(b){var c=d.closeTrigger[b];"window"!=c.selector?"document"==c.selector&&(c.keyCode&&e.indexOf(c.event)>-1?a(document).on(c.event,function(a){a.keyCode==c.keyCode&&i(j)}):a(document).on(c.event,j,function(){i(j)})):g.on(c.event,function(){i(j)})})}}),f}}(jQuery);