From 5724739328ed3f73c27074cf3c0d4ac4822149f9 Mon Sep 17 00:00:00 2001 From: Glen Cheney Date: Fri, 5 Jul 2013 21:54:18 -0700 Subject: [PATCH] Mostly IE fixes --- _includes/usage.html | 2 +- _scss/_buttons.scss | 12 +++--- _scss/_type.scss | 2 +- _scss/gallery.scss | 18 +++++++++ _scss/shuffle-styles.scss | 1 + css/gallery.css | 15 ++++++++ css/shuffle-styles.css | 1 + css/style.css | 12 +++--- jquery.shuffle.js | 3 +- jquery.shuffle.min.js | 77 +++++++++++++++++++++++++++++---------- js/demos/homepage.js | 40 +++++++++++++------- 11 files changed, 134 insertions(+), 49 deletions(-) diff --git a/_includes/usage.html b/_includes/usage.html index 667f857..7777ebf 100644 --- a/_includes/usage.html +++ b/_includes/usage.html @@ -41,7 +41,7 @@

How column widths work

The columnWidth option is used to calculate the column width. You have several options:

    -
  1. Use a sizer element. This is the easest way to specify column and gutter widths. You can use an element or an element wrapped in jQuery. The column and gutter widths will be measured using this element. The sizer option is an alias for columnWidth. See a demo using a sizer element or look at js file for the sizer demo.
  2. +
  3. Use a sizer element. This is the easest way to specify column and gutter widths. You can use an element or an element wrapped in jQuery. The column and gutter widths will be measured using this element. The sizer option is an alias for columnWidth. See a demo using a sizer element or look at the js file for the sizer demo.
  4. Use a function. When a function is used, its first parameter will be the width of the shuffle element. You need to return the column width for shuffle to use (in pixels).
  5. A number. This will explicitly set the column width to your number (in pixels).
  6. By default, shuffle will use jQuery's outerWidth(true) to calculate the column width of the first item and use that value.
  7. diff --git a/_scss/_buttons.scss b/_scss/_buttons.scss index e79ef8d..2c86f13 100644 --- a/_scss/_buttons.scss +++ b/_scss/_buttons.scss @@ -107,8 +107,8 @@ button { $size: 20px; // Circle and check - &.active::before, - &.active::after { + &.active:before, + &.active:after { content: ''; position: absolute; top: 50%; @@ -122,21 +122,21 @@ button { } // Circle - &::before { + &:before { background-color: $gray10; border-radius: 50%; } // Check - &::after { + &:after { background-size: 60%; background-position: center center; background-repeat: no-repeat; background-image: url(../img/check.svg); } - &.active::before, - &.active::after { + &.active:before, + &.active:after { opacity: 1; } } diff --git a/_scss/_type.scss b/_scss/_type.scss index 4624b14..bb1f128 100644 --- a/_scss/_type.scss +++ b/_scss/_type.scss @@ -5,11 +5,11 @@ body { // Links a { + text-decoration: none; &, &:visited { color: $river; - text-decoration: none; } &:hover { diff --git a/_scss/gallery.scss b/_scss/gallery.scss index 7471130..6b55e7e 100644 --- a/_scss/gallery.scss +++ b/_scss/gallery.scss @@ -25,9 +25,11 @@ .shape-up { position: relative; + overflow: hidden; } .shape { + position: relative; margin-left: 0; margin-top: 10px; @@ -97,6 +99,22 @@ $leftOver: $triangleSize - $fullSideWidth; } +// IE8 filter alpha wasn't working with the positioning stuff +.lt-ie9 .shape { + .keep-ratio { + position: static; + width: 100%; + height: 250px; + overflow: visible; + padding-bottom: 0; + } + + .shape__inner { + position: static; + width: 100%; + height: 100%; + } +} @media (min-width: 1200px) { diff --git a/_scss/shuffle-styles.scss b/_scss/shuffle-styles.scss index 12fd04d..6e5fae9 100644 --- a/_scss/shuffle-styles.scss +++ b/_scss/shuffle-styles.scss @@ -70,6 +70,7 @@ $itemHeight: 220px; */ .shuffle--container { position: relative; + overflow: hidden; } .shuffle--fluid .shuffle__sizer { diff --git a/css/gallery.css b/css/gallery.css index f46b04b..1cdd5b7 100644 --- a/css/gallery.css +++ b/css/gallery.css @@ -17,9 +17,11 @@ .shape-up { position: relative; + overflow: hidden; } .shape { + position: relative; margin-left: 0; margin-top: 10px; } @@ -76,6 +78,19 @@ background-color: transparent; } +.lt-ie9 .shape .keep-ratio { + position: static; + width: 100%; + height: 250px; + overflow: visible; + padding-bottom: 0; +} +.lt-ie9 .shape .shape__inner { + position: static; + width: 100%; + height: 100%; +} + @media (min-width: 1200px) { .shape--triangle .shape__space { padding-top: 18px; diff --git a/css/shuffle-styles.css b/css/shuffle-styles.css index 4b10467..ac9bc49 100644 --- a/css/shuffle-styles.css +++ b/css/shuffle-styles.css @@ -52,6 +52,7 @@ */ .shuffle--container { position: relative; + overflow: hidden; } .shuffle--fluid .shuffle__sizer { diff --git a/css/style.css b/css/style.css index 118d6e3..d772d71 100644 --- a/css/style.css +++ b/css/style.css @@ -363,9 +363,11 @@ body { color: #5d6d77; } +a { + text-decoration: none; +} a, a:visited { color: #3498db; - text-decoration: none; } a:hover { text-decoration: underline; @@ -2121,7 +2123,7 @@ button:active { .filter-group .btn { position: relative; } -.filter-group .btn.active::before, .filter-group .btn.active::after { +.filter-group .btn.active:before, .filter-group .btn.active:after { content: ''; position: absolute; top: 50%; @@ -2133,17 +2135,17 @@ button:active { opacity: 0; transition: .2s; } -.filter-group .btn::before { +.filter-group .btn:before { background-color: #2c3e50; border-radius: 50%; } -.filter-group .btn::after { +.filter-group .btn:after { background-size: 60%; background-position: center center; background-repeat: no-repeat; background-image: url(../img/check.svg); } -.filter-group .btn.active::before, .filter-group .btn.active::after { +.filter-group .btn.active:before, .filter-group .btn.active:after { opacity: 1; } diff --git a/jquery.shuffle.js b/jquery.shuffle.js index 8409550..85d7a02 100644 --- a/jquery.shuffle.js +++ b/jquery.shuffle.js @@ -138,8 +138,6 @@ var Shuffle = function( $container, options ) { Shuffle.prototype = { - constructor: Shuffle, - _init : function() { var self = this, containerCSS, @@ -1066,6 +1064,7 @@ Shuffle.settings = { top: 0, left: 0 }, + offset: { top: 0, left: 0 }, revealAppendedDelay: 300, keepSorted : true, // Keep sorted when shuffling/layout enabled: true, diff --git a/jquery.shuffle.min.js b/jquery.shuffle.min.js index 6db7cfb..d095cdc 100644 --- a/jquery.shuffle.min.js +++ b/jquery.shuffle.min.js @@ -29,23 +29,60 @@ * @version 2.0 * @date 07/05/13 */ -(function(e,p,h){e.fn.sorted=function(a){var b=e.extend({},e.fn.sorted.defaults,a);a=this.get();var c=!1;if(!a.length)return[];if(b.randomize)return e.fn.sorted.randomize(a);b.by!==e.noop&&(null!==b.by&&b.by!==h)&&a.sort(function(a,f){if(c)return 0;var g=b.by(e(a)),k=b.by(e(f));return g===h&&k===h?(c=!0,0):"sortFirst"===g||"sortLast"===k?-1:"sortLast"===g||"sortFirst"===k?1:gk?1:0});if(c)return this.get();b.reverse&&a.reverse();return a};e.fn.sorted.defaults={reverse:!1,by:null,randomize:!1}; -e.fn.sorted.randomize=function(a){var b=a.length,c,d;if(!b)return a;for(;--b;)d=Math.floor(Math.random()*(b+1)),c=a[d],a[d]=a[b],a[b]=c;return a};var q=0,l=function(a,b){e.extend(this,l.options,b,l.settings);this.$container=a;this.$window=e(window);this.unique="shuffle_"+q++;this._fire("loading");this._init();this._fire("done")};l.prototype={constructor:l,_init:function(){var a=this,b,c=e.proxy(a._onResize,a);b=a.throttle?a.throttle(a.throttleTime,c):c;c=a.initialSort?a.initialSort:null;a._setVars(); -a._resetCols();a._addClasses();a._initItems();a.$window.on("resize.shuffle."+a.unique,b);b=a.$container.css(["paddingLeft","paddingRight","position","width"]);"static"===b.position&&a.$container.css("position","relative");a.offset={left:parseInt(b.paddingLeft,10)||0,top:parseInt(b.paddingTop,10)||0};a._setColumns(parseInt(b.width,10));a.shuffle(a.group,c);a.supported&&setTimeout(function(){a._setTransitions();a.$container[0].style[a.transitionName]="height "+a.speed+"ms "+a.easing},0)},_addClasses:function(){this.$container.addClass("shuffle"); -this.$items.addClass("shuffle-item filtered");return this},_setVars:function(){this.$items=this._getItems();this.transitionName=this.prefixed("transition");this.transitionDelayName=this.prefixed("transitionDelay");this.transitionDuration=this.prefixed("transitionDuration");this.transform=this.getPrefixed("transform");this.transitionend={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd",transition:"transitionend"}[this.transitionName]; -this.isFluid=this.columnWidth&&"function"===typeof this.columnWidth;0===this.columnWidth&&null!==this.sizer&&(this.columnWidth=this.sizer);"string"===typeof this.columnWidth?this.$sizer=this.$container.find(this.columnWidth):this.columnWidth&&this.columnWidth.nodeType&&1===this.columnWidth.nodeType?this.$sizer=e(this.columnWidth):this.columnWidth&&this.columnWidth.jquery&&(this.$sizer=this.columnWidth);this.$sizer&&this.$sizer.length&&(this.useSizer=!0,this.sizer=this.$sizer[0]);return this},_filter:function(a, -b){var c=this,d=b!==h?b:c.$items,f=e();a=a||c.lastFilter;c._fire("filter");e.isFunction(a)?d.each(function(){var b=e(this);a.call(b[0],b,c)&&(f=f.add(b))}):(c.group=a,"all"!==a?d.each(function(){var b=e(this),d=b.data("groups"),d=c.delimeter&&!e.isArray(d)?d.split(c.delimeter):d;-1Math.ceil(b)-b&&(b=Math.ceil(b));this.cols=Math.floor(b);this.cols=Math.max(this.cols, -1);this.containerWidth=a},_setContainerSize:function(){var a=Math.max.apply(Math,this.colYs);this.$container.css("height",a+"px")},_fire:function(a,b){this.$container.trigger(a+".shuffle",b&&b.length?b:[this])},_layout:function(a,b,c,d){var f=this;b=b||f.filterEnd;f.layoutTransitionEnded=!1;e.each(a,function(g){g=e(a[g]);var k=Math.ceil(g.outerWidth(!0)/f.colWidth),k=Math.min(k,f.cols);if(1===k)f._placeItem(g,f.colYs,b,c,d);else{var m=f.cols+1-k,h=[],l,n;for(n=0;n=g-this.buffer&&b[m]<=g+this.buffer){k=m;break}b=this.colWidth* -k;var l=g;b=Math.round(b+this.offset.left);l=Math.round(l+this.offset.top);a.data({x:b,y:l});g+=a.outerHeight(!0);h=this.cols+1-h;for(m=0;mo?-1:o>a?1:0}),r?this.get():(n.reverse&&s.reverse(),s)):[]},t.fn.sorted.defaults={reverse:!1,by:null,randomize:!1},t.fn.sorted.randomize=function(t){var e,i,n=t.length +if(!n)return t +for(;--n;)i=Math.floor(Math.random()*(n+1)),e=t[i],t[i]=t[n],t[n]=e +return t} +var n=0,s=function(e,i){var r=this +t.extend(r,s.options,i,s.settings),r.$container=e,r.$window=t(window),r.unique="shuffle_"+n++,r._fire("loading"),r._init(),r._fire("done")} +s.prototype={_init:function(){var e,i=this,n=t.proxy(i._onResize,i),s=i.throttle?i.throttle(i.throttleTime,n):n,r=i.initialSort?i.initialSort:null +i._setVars(),i._resetCols(),i._addClasses(),i._initItems(),i.$window.on("resize.shuffle."+i.unique,s),e=i.$container.css(["paddingLeft","paddingRight","position","width"]),"static"===e.position&&i.$container.css("position","relative"),i.offset={left:parseInt(e.paddingLeft,10)||0,top:parseInt(e.paddingTop,10)||0},i._setColumns(parseInt(e.width,10)),i.shuffle(i.group,r),i.supported&&setTimeout(function(){i._setTransitions(),i.$container[0].style[i.transitionName]="height "+i.speed+"ms "+i.easing},0)},_addClasses:function(){var t=this +return t.$container.addClass("shuffle"),t.$items.addClass("shuffle-item filtered"),t},_setVars:function(){var e=this +return e.$items=e._getItems(),e.transitionName=e.prefixed("transition"),e.transitionDelayName=e.prefixed("transitionDelay"),e.transitionDuration=e.prefixed("transitionDuration"),e.transform=e.getPrefixed("transform"),e.transitionend={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd",msTransition:"MSTransitionEnd",transition:"transitionend"}[e.transitionName],e.isFluid=e.columnWidth&&"function"==typeof e.columnWidth,0===e.columnWidth&&null!==e.sizer&&(e.columnWidth=e.sizer),"string"==typeof e.columnWidth?e.$sizer=e.$container.find(e.columnWidth):e.columnWidth&&e.columnWidth.nodeType&&1===e.columnWidth.nodeType?e.$sizer=t(e.columnWidth):e.columnWidth&&e.columnWidth.jquery&&(e.$sizer=e.columnWidth),e.$sizer&&e.$sizer.length&&(e.useSizer=!0,e.sizer=e.$sizer[0]),e},_filter:function(e,n){var s=this,r=n!==i,o=r?n:s.$items,a=t() +return e=e||s.lastFilter,s._fire("filter"),t.isFunction(e)?o.each(function(){var i=t(this),n=e.call(i[0],i,s) +n&&(a=a.add(i))}):(s.group=e,"all"!==e?o.each(function(){var i=t(this),n=i.data("groups"),r=s.delimeter&&!t.isArray(n)?n.split(s.delimeter):n,o=t.inArray(e,r)>-1 +o&&(a=a.add(i))}):a=o),s._toggleFilterClasses(o,a),o=null,n=null,a},_toggleFilterClasses:function(e,i){var n="concealed",s="filtered" +e.filter(i).each(function(){var e=t(this) +e.hasClass(n)&&e.removeClass(n),e.hasClass(s)||e.addClass(s)}),e.not(i).each(function(){var e=t(this) +e.hasClass(n)||e.addClass(n),e.hasClass(s)&&e.removeClass(s)})},_initItems:function(t){return t=t||this.$items,t.css(this.itemCss)},_updateItemCount:function(){return this.visibleItems=this.$items.filter(".filtered").length,this},_setTransition:function(t){var e=this +return t.style[e.transitionName]=e.transform+" "+e.speed+"ms "+e.easing+", opacity "+e.speed+"ms "+e.easing,t},_setTransitions:function(t){var e=this +return t=t||e.$items,t.each(function(){e._setTransition(this)}),e},_setSequentialDelay:function(e){var i=this +i.supported&&t.each(e,function(e){this.style[i.transitionDelayName]="0ms,"+(e+1)*i.sequentialFadeDelay+"ms",t(this).one(i.transitionend,function(){this.style[i.transitionDelayName]="0ms"})})},_getItems:function(){return this.$container.children(this.itemSelector)},_getPreciseDimension:function(e,i){var n +return n=window.getComputedStyle?window.getComputedStyle(e,null)[i]:t(e).css(i),parseFloat(n)},_setColumns:function(t){var e,i=this,n=t||i.$container.width(),s="function"==typeof i.gutterWidth?i.gutterWidth(n):i.useSizer?i._getPreciseDimension(i.sizer,"marginLeft"):i.gutterWidth +i.colWidth=i.isFluid?i.columnWidth(n):i.useSizer?i._getPreciseDimension(i.sizer,"width"):i.columnWidth||i.$items.outerWidth(!0)||n,i.colWidth=i.colWidth||n,i.colWidth+=s,e=(n+s)/i.colWidth,Math.ceil(e)-e<.01&&(e=Math.ceil(e)),i.cols=Math.floor(e),i.cols=Math.max(i.cols,1),i.containerWidth=n},_setContainerSize:function(){var t=this,e=Math.max.apply(Math,t.colYs) +t.$container.css("height",e+"px")},_fire:function(t,e){this.$container.trigger(t+".shuffle",e&&e.length?e:[this])},_layout:function(e,i,n,s){var r=this +i=i||r.filterEnd,r.layoutTransitionEnded=!1,t.each(e,function(o){var a=t(e[o]),l=Math.ceil(a.outerWidth(!0)/r.colWidth) +if(l=Math.min(l,r.cols),1===l)r._placeItem(a,r.colYs,i,n,s) +else{var u,d,c=r.cols+1-l,f=[] +for(d=0;c>d;d++)u=r.colYs.slice(d,d+l),f[d]=Math.max.apply(Math,u) +r._placeItem(a,f,i,n,s)}}),r._processStyleQueue(),r._setContainerSize()},_resetCols:function(){var t=this.cols +for(this.colYs=[];t--;)this.colYs.push(0)},_reLayout:function(t,e){var i=this +t=t||i.filterEnd,i._resetCols(),i.keepSorted&&i.lastSort?i.sort(i.lastSort,!0,e):i._layout(i.$items.filter(".filtered").get(),i.filterEnd,e)},_placeItem:function(t,e,i,n,s){for(var r=this,o=Math.min.apply(Math,e),a=0,l=0,u=e.length;u>l;l++)if(e[l]>=o-r.buffer&&e[l]<=o+r.buffer){a=l +break}var d=r.colWidth*a,c=o +d=Math.round(d+r.offset.left),c=Math.round(c+r.offset.top),t.data({x:d,y:c}) +var f=o+t.outerHeight(!0),h=r.cols+1-u +for(l=0;h>l;l++)r.colYs[a+l]=f +var p={from:"layout",$this:t,x:d,y:c,scale:1} +n?p.skipTransition=!0:(p.opacity=1,p.callback=i),s&&(p.opacity=0),r.styleQueue.push(p)},_shrink:function(e,i){var n=this,s=e||n.$items.filter(".concealed"),r={},o=i||n.shrinkEnd +s.length&&(n._fire("shrink"),n.shrinkTransitionEnded=!1,s.each(function(){var e=t(this),i=e.data() +r={from:"shrink",$this:e,x:i.x,y:i.y,scale:.001,opacity:0,callback:o},n.styleQueue.push(r)}))},_onResize:function(){var t,e=this +e.enabled&&!e.destroyed&&(t=e.$container.width(),t!==e.containerWidth&&e.resized())},setPrefixedCss:function(t,e,i){t.css(this.prefixed(e),i)},getPrefixed:function(t){var e=this.prefixed(t) +return e?e.replace(/([A-Z])/g,function(t,e){return"-"+e.toLowerCase()}).replace(/^ms-/,"-ms-"):e},transition:function(e){var n,s=this,r=function(){s.layoutTransitionEnded||"layout"!==e.from?s.shrinkTransitionEnded||"shrink"!==e.from||(e.callback.call(s),s.shrinkTransitionEnded=!0):(s._fire("layout"),e.callback.call(s),s.layoutTransitionEnded=!0)} +if(e.callback=e.callback||t.noop,s.supported)e.scale===i&&(e.scale=1),n=s.threeD?"translate3d("+e.x+"px, "+e.y+"px, 0) scale3d("+e.scale+", "+e.scale+", 1)":"translate("+e.x+"px, "+e.y+"px) scale("+e.scale+", "+e.scale+")",e.x!==i&&s.setPrefixedCss(e.$this,"transform",n),e.opacity!==i&&e.$this.css("opacity",e.opacity),e.$this.one(s.transitionend,r) +else{var o={left:e.x,top:e.y,opacity:e.opacity} +e.$this.stop(!0).animate(o,s.speed,"swing",r)}},_processStyleQueue:function(){var e=this,i=e.styleQueue +t.each(i,function(t,i){i.skipTransition?e._skipTransition(i.$this[0],function(){e.transition(i)}):e.transition(i)}),e.styleQueue.length=0},shrinkEnd:function(){this._fire("shrunk")},filterEnd:function(){this._fire("filtered")},sortEnd:function(){this._fire("sorted")},_skipTransition:function(e,i,n){var s,r=this,o=r.transitionDuration,a=e.style[o] +e.style[o]="0ms",t.isFunction(i)?i():e.style[i]=n,s=e.offsetWidth,e.style[o]=a},_addItems:function(t,e,n){var s,r,o=this +o.supported||(e=!1),t.addClass("shuffle-item"),o._initItems(t),o._setTransitions(t),o.$items=o._getItems(),t.css("opacity",0),s=o._filter(i,t),r=s.get(),o._updateItemCount(),e?(o._layout(r,null,!0,!0),n&&o._setSequentialDelay(s),o._revealAppended(s)):o._layout(r)},_revealAppended:function(e){var i=this +setTimeout(function(){e.each(function(e,n){i.transition({from:"reveal",$this:t(n),opacity:1})})},i.revealAppendedDelay)},shuffle:function(t,e){var i=this +i.enabled&&(t||(t="all"),i._filter(t),i.lastFilter=t,i._updateItemCount(),i._resetCols(),i._shrink(),e&&(i.lastSort=e),i._reLayout())},sort:function(t,e,i){var n=this,s=n.$items.filter(".filtered").sorted(t) +e||n._resetCols(),n._layout(s,function(){e&&n.filterEnd(),n.sortEnd()},i),n.lastSort=t},resized:function(t){this.enabled&&(t||this._setColumns(),this._reLayout())},layout:function(){this.update(!0)},update:function(t){this.resized(t)},appended:function(t,e,i){e=e===!1?!1:!0,i=i===!1?!1:!0,this._addItems(t,e,i)},disable:function(){this.enabled=!1},enable:function(t){this.enabled=!0,t!==!1&&this.update()},remove:function(t){if(t.length&&t.jquery){var e=this +return e._shrink(t,function(){var e=this +t.remove(),setTimeout(function(){e.$items=e._getItems(),e.layout(),e._updateItemCount(),e._fire("removed",[t,e]),t=null},0)}),e._processStyleQueue(),e}},destroy:function(){var t=this +t.$window.off("."+t.unique),t.$container.removeClass("shuffle").removeAttr("style").removeData("shuffle"),t.$items.removeAttr("style").removeClass("concealed filtered shuffle-item"),t.destroyed=!0}},s.options={group:"all",speed:250,easing:"ease-out",itemSelector:"",sizer:null,gutterWidth:0,columnWidth:0,delimeter:null,buffer:0,initialSort:null,throttle:t.throttle||null,throttleTime:300,sequentialFadeDelay:150,supported:e.csstransforms&&e.csstransitions},s.settings={$sizer:null,useSizer:!1,itemCss:{position:"absolute",top:0,left:0},offset:{top:0,left:0},revealAppendedDelay:300,keepSorted:!0,enabled:!0,destroyed:!1,styleQueue:[],prefixed:e.prefixed,threeD:e.csstransforms3d},t.fn.shuffle=function(e){var i=Array.prototype.slice.call(arguments,1) +return this.each(function(){var n=t(this),r=n.data("shuffle") +r||(r=new s(n,e),n.data("shuffle",r)),"string"==typeof e&&r[e]&&r[e].apply(r,i)})}}(jQuery,Modernizr) diff --git a/js/demos/homepage.js b/js/demos/homepage.js index 06b2f51..6857845 100644 --- a/js/demos/homepage.js +++ b/js/demos/homepage.js @@ -6,10 +6,14 @@ var DEMO = (function( $ ) { $sizer = $grid.find('.shuffle__sizer'), init = function() { - listen(); - setupFilters(); - setupSorting(); - setupSearching(); + + // None of these need to be executed synchronously + setTimeout(function() { + listen(); + setupFilters(); + setupSorting(); + setupSearching(); + }, 100); // instantiate the plugin $grid.shuffle({ @@ -95,25 +99,33 @@ var DEMO = (function( $ ) { }); }, + // Re layout shuffle when images load. This is only needed + // below 768 pixels because the .picture-item height is auto and therefore + // the height of the picture-item is dependent on the image + // I recommend using imagesloaded to determine when an image is loaded + // but that doesn't support IE7 listen = function() { - var debouncedLayout = $.throttle( 100, function() { - $grid.shuffle('layout'); + var debouncedLayout = $.throttle( 300, function() { + $grid.shuffle('update'); }); - // Re layout shuffle when images load. This is only needed - // below 768 pixels because the .picture-item height is auto and therefore - // the height of the picture-item is dependent on the image - // I recommend using imagesloaded to determine when an image is loaded - // but that doesn't support IE7 + // Get all images inside shuffle $grid.find('img').each(function() { - var $img = $( this ); + var proxyImage; // Image already loaded - if ( this.complete && this.naturalWidth > 0 ) { + if ( this.complete && this.naturalWidth !== undefined ) { return; } - $img.on('load', debouncedLayout); + // If none of the checks above matched, simulate loading on detached element. + proxyImage = new Image(); + $( proxyImage ).on('load', function() { + $(this).off('load'); + debouncedLayout(); + }); + + proxyImage.src = this.src; }); };