-
Notifications
You must be signed in to change notification settings - Fork 8
/
jquery.flowgallery.min.js
9 lines (9 loc) · 5.88 KB
/
jquery.flowgallery.min.js
1
2
3
4
5
6
7
8
9
/*!
* jQuery flowgallery plugin: Cover Flow Image Gallery
* Examples and documentation at: http://flowgallery.org
* Version: 0.7.0 (08-JAN-2013)
* Author: Boris Searles ([email protected])
* Requires jQuery v1.4 or later
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/(function(e,t,n,r){"use strict";var i=function(o,u){function S(){var r;f=e(o),r=f.data("plugin-options"),l=e.extend({},i.defaults,u,r),p=f.parent(),a.length=f.children().length,a.options=l,x(),C(),f.css("visibility","visible"),e(t).resize(e.proxy(H,a)),l.enableKeyNavigation===!0&&e(n).keydown(F),M(!1)}function x(){f.css({listStyle:"none",overflow:"hidden",marginLeft:"0",paddingLeft:"0",position:"relative",width:"100%"}),T(),N()}function T(){var t=n.createElement("p");d=e(t).addClass("fg-caption").css({backgroundColor:l.backgroundColor,display:"none",marginTop:"0",padding:"8px "+(l.imagePadding+10)+"px 15px",position:"absolute"})}function N(){var t=n.createElement("div");e(t).addClass("fg-wrapper").css({position:"relative"}).append(f.get(0)).append(d.get(0)),p.append(t)}function C(){a.enabled=!1,f.children().each(function(e){var t=new s(this,e,l);if(!t.$el)return;t.$el.on("loaded",k),t.$el.on("click",L),!v&&l.activeIndex===e&&(t.$el.addClass("active"),v=t,m=e),b.push(t)}),a.enabled=!0,g=p.width(),c=g*.5}function k(){var t=e(this).data("flowItem");j(t.h),t.index===l.activeIndex?(a.activeLoaded=!0,M(!0)):a.activeLoaded&&(t.th!==l.loadingHeight||t.tw!==l.loadingWidth)&&M(!0)}function L(t){var n=e(this).data("flowItem");if(n!==v){var r=m;_(n.index-r)}else l.forwardOnActiveClick===!0&&_(1)}function A(){B(),p.width()!==g&&(g=p.width(),c=g*.5,M(),B())}function O(e){return function(){var t=b[e];t.oldActive=!1}}function M(e){if(!a.isEnabled())return!1;var t={},n=!0,r=null,i=!1,s=!1,o=b.length,u;h=l.thumbTopOffset==="auto"?v.h*.5:l.thumbTopOffset;for(u=0;u<o;u++)i=b[u],s=i.$el,s.hasClass("active")?(t={left:c-l.imagePadding-i.w*.5+"px",top:"0",width:i.w+"px",height:i.h+"px",padding:l.imagePadding+"px"},n=!1,r=A,y!==i.h&&(y=i.h,y+=l.imagePadding*2,e?f.stop().animate({height:y},{duration:l.duration,easing:l.easing}):f.height(y))):(t={left:P(u,n),top:h-i.th*.5+"px"},r=null,t.width=i.tw+"px",t.height=i.th+"px",t.padding=l.thumbPadding+"px",r=O(u)),e?s.stop().animate(t,{duration:l.duration,easing:l.easing,complete:r}):(s.css(t),r&&r())}function _(e,t){if(!a.isEnabled())return!1;var n=m+e;t=t!==r?t:l.animate;if(n>b.length-1||n<0)return!1;v.oldActive=!0;if(e<0&&m>0)b[m].oldActive=!0,m+=e;else{if(!(e>0&&m<b.length-1))return!1;m+=e}v=b[m],D(),M(t)}function D(){d.hide(),f.find(".active").removeClass("active"),e(v.$el).addClass("active"),g=p.width(),c=g*.5}function P(e,t){var n=c,r=0;if(t){n-=b[m].w*.5,n-=l.imagePadding,n-=(m-e)*10,n-=(m-e)*2*l.thumbPadding;for(r=e;r<m;r++)n-=b[r].tw}else{n+=b[m].w*.5,n+=l.imagePadding,n+=(e-m)*10,n+=(e-m)*2*l.thumbPadding;for(r=m+1;r<e;r++)n+=b[r].tw}return n+"px"}function H(){if(!a.isEnabled())return E=!0,!1;g=p.width(),c=g*.5,M(),B()}function B(){if(!v.isLoaded)return!1;var e,t=v.captionText;t&&t.length>0?(d.text(t),d.css({left:c-l.imagePadding-v.w*.5,top:v.h+l.imagePadding*2,width:v.w-20}),e=v.h+d.height()+40,d.fadeIn("fast")):e=v.h+40}function j(e){e>y&&(y=e,y+=l.imagePadding*2,f.height(y))}function F(e){e.keyCode===37?_(-1):e.keyCode===39&&_(1)}var a=this,o,f,l={},c=0,h=0,p=!1,d=!1,v=!1,m=0,g=0,y=0,b=[],w=0,E=!1;this.length=0,this.enabled=!0,this.options={},this.getActiveIndex=function(){return m},this.next=function(e){return _(1,e),this},this.prev=function(e){return _(-1,e),this},this.jump=function(e,t){return _(e-m,t),this},this.isEnabled=function(){return this.enabled===!0},this.disable=function(){return this.enabled=!1,this},this.enable=function(){return this.enabled=!0,E&&(e.proxy(this.windowResizeHandler,this)(),E=!1),this},S()};i.defaults={activeIndex:0,animate:!0,backgroundColor:"black",circular:!1,duration:900,easing:"linear",enableKeyNavigation:!0,forceHeight:!1,forceWidth:!1,forwardOnActiveClick:!0,imagePadding:0,loadingClass:"loading",loadingHeight:60,loadingWidth:100,thumbHeight:"auto",thumbPadding:0,thumbTopOffset:"auto",thumbWidth:"auto"};var s=function(t,n,r){function o(){i.h=r.loadingHeight,i.th=r.loadingHeight,i.w=r.loadingWidth,i.tw=r.loadingWidth,s=i.$el.find("img");if(s.length===0){i.$el=!1;return}i.$el.data("flowItem",i),i.captionText=s.attr("title"),r.forceWidth&&s.width(r.forceWidth),s.hide().parent().addClass(r.loadingClass).css({height:i.th,width:i.tw}),u(),i.$el.css({backgroundColor:r.backgroundColor,padding:r.thumbPadding,position:"absolute",textAlign:"center"}),s.css({cursor:"pointer",height:"100%",imageRendering:"optimizeQuality",width:"100%"})}function u(){var e=s.get(0);e.complete?f():s.bind("load readystatechange",a).bind("error",function(){s.css("visibility","visible").parent().removeClass(r.loadingClass)})}function a(e){var t=s.get(0);(t.complete||t.readyState==="complete"&&e.type==="readystatechange")&&f()}function f(){s.css("visibility","visible").parent().removeClass(r.loadingClass),s.fadeIn(),i.isLoaded=!0,l(),i.$el.trigger("loaded",i)}function l(){var e=s.get(0);if(typeof e.naturalWidth!="undefined")i.w=r.forceWidth||e.naturalWidth||e.width,i.h=r.forceHeight||e.naturalHeight||e.height;else{var t=new Image;t.src=s.attr("src"),i.w=t.width,i.h=t.height}r.thumbWidth==="auto"&&r.thumbHeight==="auto"?(i.tw=r.loadingWidth,i.th=Math.round(i.h*r.loadingWidth/i.w)):r.thumbHeight==="auto"?(i.tw=r.thumbWidth,i.th=Math.round(i.h*Number(r.thumbWidth)/i.w)):r.thumbWidth==="auto"?(i.tw=Math.round(i.w*Number(r.thumbHeight)/i.h),i.th=r.thumbHeight):(i.tw=r.thumbWidth,i.th=r.thumbHeight)}var i=this,s=!1;this.$el=e(t),this.index=n,this.h=0,this.th=0,this.w=0,this.tw=0,this.active=!1,this.isLoaded=!1,this.captionText=!1,this.oldActive=!1,o()};e.fn.flowgallery=function(t){return this.each(function(){var n=e(this);if(n.data("flowgallery"))return;var r=new i(this,t);n.data("flowgallery",r)})},e.fn.flowgallery.defaults=i.defaults})(jQuery,window,document);