From 8e2f51612eaf20e3031b81b8c5ff5e322cbb7b4f Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Wed, 29 Jun 2011 22:28:13 -0400 Subject: [PATCH] src : inserting & appending items get hidden, then revealed --- jquery.isotope.js | 76 +++++++++++++++++++++++++++++++++---------- jquery.isotope.min.js | 2 +- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index e804de72..9ba7ba50 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -607,27 +607,34 @@ this.styleQueue.push({ $el: this.element, style: containerStyle }); } + this._processStyleQueue(); + + // provide $elems as context for the callback + if ( callback ) { + callback.call( $elems ); + } + + this.isLaidOut = true; + }, + + _processStyleQueue : function() { // are we animating the layout arrangement? // use plugin-ish syntax for css or animate var styleFn = !this.isLaidOut ? 'css' : ( this.isUsingJQueryAnimation ? 'animate' : 'css' ), - animOpts = this.options.animationOptions; - + animOpts = this.options.animationOptions, + _isInsertingAnimated = this._isInserting && this.isUsingJQueryAnimation, + objStyleFn; + // process styleQueue $.each( this.styleQueue, function( i, obj ) { - obj.$el[ styleFn ]( obj.style, animOpts ); + objStyleFn = _isInsertingAnimated && obj.$el.hasClass('no-transition') ? 'css' : styleFn; + obj.$el[ objStyleFn ]( obj.style, animOpts ); }); // clear out queue for next time this.styleQueue = []; - - // provide $elems as context for the callback - if ( callback ) { - callback.call( $elems ); - } - - this.isLaidOut = true; }, @@ -647,6 +654,8 @@ // ====================== Convenience methods ====================== + // ====================== Adding items ====================== + // adds a jQuery object of items to a isotope container addItems : function( $content, callback ) { var $newAtoms = this._getAtoms( $content ); @@ -660,29 +669,60 @@ }, // convienence method for adding elements properly to any layout + // positions items, hides them, then animates them back in <--- very sezzy insert : function( $content, callback ) { + // position items this.element.append( $content ); var instance = this; this.addItems( $content, function( $newAtoms ) { - var $filteredAtoms = instance._filter( $newAtoms ); - instance.$filteredAtoms = instance.$filteredAtoms.add( $filteredAtoms ); + var $newFilteredAtoms = instance._filter( $newAtoms, true ); + instance._addHideAppended( $newFilteredAtoms ); + instance._sort(); + instance.reLayout(); + instance._revealAppended( $newFilteredAtoms, callback ); }); - this._sort(); - this.reLayout( callback ); - }, // convienence method for working with Infinite Scroll appended : function( $content, callback ) { var instance = this; - this.addItems( $content, function( $newAtoms ){ - instance.$filteredAtoms = instance.$filteredAtoms.add( $newAtoms ); - instance.layout( $newAtoms, callback ); + this.addItems( $content, function( $newAtoms ) { + instance._addHideAppended( $newAtoms ); + instance.layout( $newAtoms ); + instance._revealAppended( $newAtoms, callback ); }); }, + // adds new atoms, then hides them before positioning + _addHideAppended : function( $newAtoms ) { + this.$filteredAtoms = this.$filteredAtoms.add( $newAtoms ); + $newAtoms.addClass('no-transition'); + + this._isInserting = true; + + // apply hidden styles + this.styleQueue.push({ $el: $newAtoms, style: this.options.hiddenStyle }); + }, + + // sets visible style on new atoms + _revealAppended : function( $newAtoms, callback ) { + var instance = this; + // apply visible style after a sec + setTimeout( function() { + // enable animation + $newAtoms.removeClass('no-transition'); + // reveal newly inserted filtered elements + instance.styleQueue.push({ $el: $newAtoms, style: instance.options.visibleStyle }); + instance._processStyleQueue(); + delete instance._isInserting; + if ( callback ) { + callback( $newAtoms ); + } + }, 10 ); + }, + // gathers all atoms reloadItems : function() { this.$allAtoms = this._getAtoms( this.element.children() ); diff --git a/jquery.isotope.min.js b/jquery.isotope.min.js index 94cf5e5d..a7f93e05 100644 --- a/jquery.isotope.min.js +++ b/jquery.isotope.min.js @@ -9,4 +9,4 @@ * Copyright 2011 David DeSandro / Metafizzy */ /*global Modernizr: true */ -(function(a,b,c){function f(a,b){b=b||document.documentElement;var c=b.style,f;if(typeof c[a]=="string")return a;a=d(a);for(var g=0,h=e.length;gg?1:fd&&(e.x=0,e.y=e.height),c._pushPosition(a,e.x,e.y),e.height=Math.max(e.y+g,e.height),e.x+=f})},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResizeChanged:function(){return!0},_cellsByRowReset:function(){this.cellsByRow={index:0},this._getSegments(),this._getSegments(!0)},_cellsByRowLayout:function(a){var c=this,d=this.cellsByRow;a.each(function(){var a=b(this),e=d.index%d.cols,f=~~(d.index/d.cols),g=(e+.5)*d.columnWidth-a.outerWidth(!0)/2,h=(f+.5)*d.rowHeight-a.outerHeight(!0)/2;c._pushPosition(a,g,h),d.index++})},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.$filteredAtoms.length/this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.offset.top}},_cellsByRowResizeChanged:function(){return this._checkIfSegmentsChanged()},_straightDownReset:function(){this.straightDown={y:0}},_straightDownLayout:function(a){var c=this;a.each(function(a){var d=b(this);c._pushPosition(d,0,c.straightDown.y),c.straightDown.y+=d.outerHeight(!0)})},_straightDownGetContainerSize:function(){return{height:this.straightDown.y}},_straightDownResizeChanged:function(){return!0},_masonryHorizontalReset:function(){this.masonryHorizontal={},this._getSegments(!0);var a=this.masonryHorizontal.rows;this.masonryHorizontal.rowXs=[];while(a--)this.masonryHorizontal.rowXs.push(0)},_masonryHorizontalLayout:function(a){var c=this,d=c.masonryHorizontal;a.each(function(){var a=b(this),e=Math.ceil(a.outerHeight(!0)/d.rowHeight);e=Math.min(e,d.rows);if(e===1)c._masonryHorizontalPlaceBrick(a,d.rowXs);else{var f=d.rows+1-e,g=[],h,i;for(i=0;id&&(e.x=e.width,e.y=0),c._pushPosition(a,e.x,e.y),e.width=Math.max(e.x+f,e.width),e.y+=g})},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResizeChanged:function(){return!0},_cellsByColumnReset:function(){this.cellsByColumn={index:0},this._getSegments(),this._getSegments(!0)},_cellsByColumnLayout:function(a){var c=this,d=this.cellsByColumn;a.each(function(){var a=b(this),e=~~(d.index/d.rows),f=d.index%d.rows,g=(e+.5)*d.columnWidth-a.outerWidth(!0)/2,h=(f+.5)*d.rowHeight-a.outerHeight(!0)/2;c._pushPosition(a,g,h),d.index++})},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.$filteredAtoms.length/this.cellsByColumn.rows)*this.cellsByColumn.columnWidth}},_cellsByColumnResizeChanged:function(){return this._checkIfSegmentsChanged(!0)},_straightAcrossReset:function(){this.straightAcross={x:0}},_straightAcrossLayout:function(a){var c=this;a.each(function(a){var d=b(this);c._pushPosition(d,c.straightAcross.x,0),c.straightAcross.x+=d.outerWidth(!0)})},_straightAcrossGetContainerSize:function(){return{width:this.straightAcross.x}},_straightAcrossResizeChanged:function(){return!0}},b.fn.imagesLoaded=function(a){var b=this.find("img"),d=b.length,e=this;b.length||a.call(this),b.bind("load",function(){--d<=0&&a.call(e)}).each(function(){if(this.complete||this.complete===c){var a=this.src;this.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",this.src=a}});return this};var r=function(a){this.console&&console.error(a)};b.fn.isotope=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"isotope");if(!d)r("cannot call methods on isotope prior to initialization; attempted to call method '"+a+"'");else{if(!b.isFunction(d[a])||a.charAt(0)==="_"){r("no such method '"+a+"' for isotope instance");return}d[a].apply(d,c)}})}else this.each(function(){var c=b.data(this,"isotope");c?(c.option(a),c._init()):b.data(this,"isotope",new b.Isotope(a,this))});return this}})(window,jQuery); +(function(a,b,c){function f(a,b){b=b||document.documentElement;var c=b.style,f;if(typeof c[a]=="string")return a;a=d(a);for(var g=0,h=e.length;gg?1:fd&&(e.x=0,e.y=e.height),c._pushPosition(a,e.x,e.y),e.height=Math.max(e.y+g,e.height),e.x+=f})},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResizeChanged:function(){return!0},_cellsByRowReset:function(){this.cellsByRow={index:0},this._getSegments(),this._getSegments(!0)},_cellsByRowLayout:function(a){var c=this,d=this.cellsByRow;a.each(function(){var a=b(this),e=d.index%d.cols,f=~~(d.index/d.cols),g=(e+.5)*d.columnWidth-a.outerWidth(!0)/2,h=(f+.5)*d.rowHeight-a.outerHeight(!0)/2;c._pushPosition(a,g,h),d.index++})},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.$filteredAtoms.length/this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.offset.top}},_cellsByRowResizeChanged:function(){return this._checkIfSegmentsChanged()},_straightDownReset:function(){this.straightDown={y:0}},_straightDownLayout:function(a){var c=this;a.each(function(a){var d=b(this);c._pushPosition(d,0,c.straightDown.y),c.straightDown.y+=d.outerHeight(!0)})},_straightDownGetContainerSize:function(){return{height:this.straightDown.y}},_straightDownResizeChanged:function(){return!0},_masonryHorizontalReset:function(){this.masonryHorizontal={},this._getSegments(!0);var a=this.masonryHorizontal.rows;this.masonryHorizontal.rowXs=[];while(a--)this.masonryHorizontal.rowXs.push(0)},_masonryHorizontalLayout:function(a){var c=this,d=c.masonryHorizontal;a.each(function(){var a=b(this),e=Math.ceil(a.outerHeight(!0)/d.rowHeight);e=Math.min(e,d.rows);if(e===1)c._masonryHorizontalPlaceBrick(a,d.rowXs);else{var f=d.rows+1-e,g=[],h,i;for(i=0;id&&(e.x=e.width,e.y=0),c._pushPosition(a,e.x,e.y),e.width=Math.max(e.x+f,e.width),e.y+=g})},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResizeChanged:function(){return!0},_cellsByColumnReset:function(){this.cellsByColumn={index:0},this._getSegments(),this._getSegments(!0)},_cellsByColumnLayout:function(a){var c=this,d=this.cellsByColumn;a.each(function(){var a=b(this),e=~~(d.index/d.rows),f=d.index%d.rows,g=(e+.5)*d.columnWidth-a.outerWidth(!0)/2,h=(f+.5)*d.rowHeight-a.outerHeight(!0)/2;c._pushPosition(a,g,h),d.index++})},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.$filteredAtoms.length/this.cellsByColumn.rows)*this.cellsByColumn.columnWidth}},_cellsByColumnResizeChanged:function(){return this._checkIfSegmentsChanged(!0)},_straightAcrossReset:function(){this.straightAcross={x:0}},_straightAcrossLayout:function(a){var c=this;a.each(function(a){var d=b(this);c._pushPosition(d,c.straightAcross.x,0),c.straightAcross.x+=d.outerWidth(!0)})},_straightAcrossGetContainerSize:function(){return{width:this.straightAcross.x}},_straightAcrossResizeChanged:function(){return!0}},b.fn.imagesLoaded=function(a){var b=this.find("img"),d=b.length,e=this;b.length||a.call(this),b.bind("load",function(){--d<=0&&a.call(e)}).each(function(){if(this.complete||this.complete===c){var a=this.src;this.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==",this.src=a}});return this};var r=function(a){this.console&&console.error(a)};b.fn.isotope=function(a){if(typeof a=="string"){var c=Array.prototype.slice.call(arguments,1);this.each(function(){var d=b.data(this,"isotope");if(!d)r("cannot call methods on isotope prior to initialization; attempted to call method '"+a+"'");else{if(!b.isFunction(d[a])||a.charAt(0)==="_"){r("no such method '"+a+"' for isotope instance");return}d[a].apply(d,c)}})}else this.each(function(){var c=b.data(this,"isotope");c?(c.option(a),c._init()):b.data(this,"isotope",new b.Isotope(a,this))});return this}})(window,jQuery);