Permalink
Browse files

some cleanup and loading tweaks

  • Loading branch information...
1 parent 79c983f commit 418430167f48991e19c136bdf21c5f45c5172a90 @bozz committed Nov 27, 2012
Showing with 7 additions and 14 deletions.
  1. +6 −13 jquery.flowgallery.js
  2. +1 −1 jquery.flowgallery.min.js
View
19 jquery.flowgallery.js
@@ -8,6 +8,7 @@
* http://www.opensource.org/licenses/mit-license.php
*/
;(function( $, window, document, undefined ){
+ "use strict";
/**
* helper function to get current plugin version
@@ -29,7 +30,6 @@
$caption = false, // caption element
activeItem = false, // reference to active FlowItem
activeIndex = 0,
- activeLoaded = false, // has active image been loaded?
listWidth = 0, // list width (default: screen width)
listHeight = 0, // list height (height of highest image)
flowItems = [], // array of FlowItems
@@ -139,20 +139,13 @@
function onItemLoaded() {
var item = $(this).data('flowItem');
+ updateListHeight(item.h);
if(item.index===options.activeIndex) {
- activeLoaded = true;
- // } else {
- // var animateParams = { height: item.th, width: item.tw };
- // if(activeLoaded) {
- // animateParams.top = (centerY - item.th*0.5) + 'px';
- // }
- // item.$el.animate(animateParams);
+ self.activeLoaded = true;
+ updateFlow(true);
+ } else if(self.activeLoaded && (item.th !== options.loadingHeight || item.tw !== options.loadingWidth)) {
+ updateFlow(true);
}
-
- updateListHeight(item.h);
-
- // redraw in order to update thumbnail positions
- updateFlow(false);
};
View
2 jquery.flowgallery.min.js
@@ -6,4 +6,4 @@
* Requires jQuery v1.4 or later
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
- */(function(e,t,n,r){var i=function(){return"0.7.0pre"},s=function(i,u){function x(){var r;f=e(i),r=f.data("plugin-options"),l=e.extend({},s.defaults,u,r),p=f.parent(),a.length=f.children().length,a.options=l,T(),k(),f.css("visibility","visible"),e(t).resize(e.proxy(B,a)),l.enableKeyNavigation===!0&&e(n).keydown(I),_(!1)}function T(){f.css({listStyle:"none",overflow:"hidden",marginLeft:"0",paddingLeft:"0",position:"relative",width:"100%"}),N(),C()}function N(){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 C(){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 k(){a.enabled=!1,f.children().each(function(e){var t=new o(this,e,l);if(!t.$el)return;t.$el.on("loaded",L),t.$el.on("click",A),!v&&l.activeIndex===e&&(t.$el.addClass("active"),v=t,m=e),w.push(t)}),a.enabled=!0,y=p.width(),c=y*.5}function L(){var t=e(this).data("flowItem");t.index===l.activeIndex&&(g=!0),F(t.h),_(!1)}function A(t){var n=e(this).data("flowItem");if(n!==v){var r=m;D(n.index-r)}else l.forwardOnActiveClick===!0&&D(1)}function O(){j(),p.width()!==y&&(y=p.width(),c=y*.5,_(),j())}function M(e){return function(){var t=w[e];t.oldActive=!1}}function _(e){if(!a.isEnabled())return!1;var t={},n=!0,r=null,i=!1,s=!1,o=w.length,u;h=l.thumbTopOffset==="auto"?v.h*.5:l.thumbTopOffset;for(u=0;u<o;u++)i=w[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=O,b!==i.h&&(b=i.h,b+=l.imagePadding*2,e?f.stop().animate({height:b},{duration:l.duration,easing:l.easing}):f.height(b))):(t={left:H(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=M(u)),e?s.stop().animate(t,{duration:l.duration,easing:l.easing,complete:r}):(s.css(t),r&&r())}function D(e,t){if(!a.isEnabled())return!1;var n=m+e;t=t!==r?t:l.animate;if(n>w.length-1||n<0)return!1;v.oldActive=!0;if(e<0&&m>0)w[m].oldActive=!0,m+=e;else{if(!(e>0&&m<w.length-1))return!1;m+=e}v=w[m],P(),_(t)}function P(){d.hide(),f.find(".active").removeClass("active"),e(v.$el).addClass("active"),y=p.width(),c=y*.5}function H(e,t){var n=c,r=0;if(t){n-=w[m].w*.5,n-=l.imagePadding,n-=(m-e)*10,n-=(m-e)*2*l.thumbPadding;for(r=e;r<m;r++)n-=w[r].tw}else{n+=w[m].w*.5,n+=l.imagePadding,n+=(e-m)*10,n+=(e-m)*2*l.thumbPadding;for(r=m+1;r<e;r++)n+=w[r].tw}return n+"px"}function B(){if(!a.isEnabled())return S=!0,!1;y=p.width(),c=y*.5,_(),j()}function j(){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 F(e){e>b&&(b=e,b+=l.imagePadding*2,f.height(b))}function I(e){e.keyCode===37?D(-1):e.keyCode===39&&D(1)}var a=this,i,f,l={},c=0,h=0,p=!1,d=!1,v=!1,m=0,g=!1,y=0,b=0,w=[],E=0,S=!1;this.length=0,this.enabled=!0,this.options={},this.getActiveIndex=function(){return m},this.next=function(e){return D(1,e),this},this.prev=function(e){return D(-1,e),this},this.jump=function(e,t){return D(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,S&&(e.proxy(this.windowResizeHandler,this)(),S=!1),this},x()};s.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 o=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 s(this,t);n.data("flowgallery",r)})},e.fn.flowgallery.defaults=s.defaults})(jQuery,window,document);
+ */(function(e,t,n,r){"use strict";var i=function(){return"0.7.0pre"},s=function(i,u){function S(){var r;f=e(i),r=f.data("plugin-options"),l=e.extend({},s.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 o(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,i,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()};s.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 o=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 s(this,t);n.data("flowgallery",r)})},e.fn.flowgallery.defaults=s.defaults})(jQuery,window,document);

0 comments on commit 4184301

Please sign in to comment.