From a7cc0be2a0038c13a2955a889a873f63a39eb6c2 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 23 May 2011 16:53:33 -0400 Subject: [PATCH] src : layout mode API : add _checkIfSegmentsChanged method; remove namespace arg from _getSegments; layoutModeResize -> layoutModeResizeChanged, which returns boolean; --- jquery.isotope.js | 92 +++++++++++++++++++------------------------ jquery.isotope.min.js | 4 +- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/jquery.isotope.js b/jquery.isotope.js index 838f6647..c8f8dda4 100644 --- a/jquery.isotope.js +++ b/jquery.isotope.js @@ -1,5 +1,5 @@ /** - * Isotope v1.2.110523 + * Isotope v1.3.110523 * An exquisite jQuery plugin for magical layouts * http://isotope.metafizzy.co * @@ -636,7 +636,9 @@ resize : function() { - this[ '_' + this.options.layoutMode + 'Resize' ](); + if ( this[ '_' + this.options.layoutMode + 'ResizeChanged' ]() ) { + this.reLayout(); + } }, @@ -757,11 +759,15 @@ }, + + // ====================== LAYOUTS ====================== + // calculates number of rows or columns // requires columnWidth or rowHeight to be set on namespaced object // i.e. this.masonry.columnWidth = 200 - _getSegments : function( namespace, isRows ) { - var measure = isRows ? 'rowHeight' : 'columnWidth', + _getSegments : function( isRows ) { + var namespace = this.layoutMode, + measure = isRows ? 'rowHeight' : 'columnWidth', size = isRows ? 'height' : 'width', UCSize = isRows ? 'Height' : 'Width', segmentsName = isRows ? 'rows' : 'cols', @@ -786,10 +792,18 @@ this[ namespace ][ measure ] = segmentSize; }, + + _checkIfSegmentsChanged : function( isRows ) { + var segmentsName = isRows ? 'rows' : 'cols', + prevSegments = this[ this.layoutMode ][ segmentsName ]; + // update cols/rows + this._getSegments( isRows ); + // return if updated cols/rows is not equal to previous + var changed = ( this[ this.layoutMode ][ segmentsName ] !== prevSegments ); + console.log( changed ); + return changed; + }, - // ====================== LAYOUTS ====================== - - // ====================== Masonry ====================== _masonryPlaceBrick : function( $brick, setCount, setY ) { @@ -858,7 +872,7 @@ // layout-specific props this.masonry = {}; // FIXME shouldn't have to call this again - this._getSegments('masonry'); + this._getSegments(); var i = this.masonry.cols; this.masonry.colYs = []; while (i--) { @@ -866,14 +880,8 @@ } }, - _masonryResize : function() { - var prevColCount = this.masonry.cols; - // get updated colCount - this._getSegments('masonry'); - if ( this.masonry.cols !== prevColCount ) { - // if column count has changed, do a new column cound - this.reLayout(); - } + _masonryResizeChanged : function() { + return this._checkIfSegmentsChanged(); }, _masonryGetContainerSize : function() { @@ -923,8 +931,8 @@ return { height : this.fitRows.height }; }, - _fitRowsResize : function() { - this.reLayout(); + _fitRowsResizeChanged : function() { + return true; }, @@ -932,7 +940,7 @@ _cellsByRowReset : function() { this.cellsByRow = {}; - this._getSegments('cellsByRow'); + this._getSegments(); this.cellsByRow.rowHeight = this.options.cellsByRow.rowHeight || this.$allAtoms.outerHeight(true); }, @@ -954,14 +962,8 @@ return { height : Math.ceil( this.cellsByRow.atomsLen / this.cellsByRow.cols ) * this.cellsByRow.rowHeight + this.posTop }; }, - _cellsByRowResize : function() { - var prevCols = this.cellsByRow.cols; - this._getSegments('cellsByRow'); - - // if column count has changed, do a new column cound - if ( this.cellsByRow.cols !== prevCols ) { - this.reLayout(); - } + _cellsByRowResizeChanged : function() { + return this._getIfSegmentsChanged(); }, @@ -987,8 +989,8 @@ return { height : this.straightDown.y + this.posTop }; }, - _straightDownResize : function() { - this.reLayout(); + _straightDownResizeChanged : function() { + return true; }, @@ -1057,7 +1059,7 @@ // layout-specific props this.masonryHorizontal = {}; // FIXME shouldn't have to call this again - this._getSegments( 'masonryHorizontal', true ); + this._getSegments( true ); var i = this.masonryHorizontal.rows; this.masonryHorizontal.rowXs = []; while (i--) { @@ -1065,14 +1067,8 @@ } }, - _masonryHorizontalResize : function() { - var prevRows = this.masonryHorizontal.rows; - // get updated colCount - this._getSegments( 'masonryHorizontal', true ); - if ( this.masonryHorizontal.rows !== prevRows ) { - // if column count has changed, do a new column cound - this.reLayout(); - } + _masonryHorizontalResizeChanged : function() { + return this._getIfSegmentsChanged(); }, _masonryHorizontalGetContainerSize : function() { @@ -1121,8 +1117,8 @@ return { width : this.fitColumns.width }; }, - _fitColumnsResize : function() { - this.reLayout(); + _fitColumnsResizeChanged : function() { + return true; }, @@ -1131,7 +1127,7 @@ _cellsByColumnReset : function() { this.cellsByColumn = {}; - this._getSegments( 'cellsByColumn', true ); + this._getSegments( true ); this.cellsByColumn.columnWidth = this.options.cellsByColumn.columnWidth || this.$allAtoms.outerHeight(true); }, @@ -1153,14 +1149,8 @@ return { width : Math.ceil( this.cellsByColumn.atomsLen / this.cellsByColumn.rows ) * this.cellsByColumn.columnWidth + this.posLeft }; }, - _cellsByColumnResize : function() { - var prevRows = this.cellsByColumn.rows; - this._getSegments( 'cellsByColumn', true ); - - // if column count has changed, do a new column cound - if ( this.cellsByColumn.rows !== prevRows ) { - this.reLayout(); - } + _cellsByColumnResizeChanged : function() { + return this._getIfSegmentsChanged(); }, // ====================== straightAcross ====================== @@ -1185,8 +1175,8 @@ return { width : this.straightAcross.x + this.posLeft }; }, - _straightAcrossResize : function() { - this.reLayout(); + _straightAcrossResizeChanged : function() { + return true; } }; diff --git a/jquery.isotope.min.js b/jquery.isotope.min.js index 7155d778..da04be39 100644 --- a/jquery.isotope.min.js +++ b/jquery.isotope.min.js @@ -1,5 +1,5 @@ /** - * Isotope v1.2.110523 + * Isotope v1.3.110523 * An exquisite jQuery plugin for magical layouts * http://isotope.metafizzy.co * @@ -8,4 +8,4 @@ * * Copyright 2011 David DeSandro / Metafizzy */ -(function(a,b,c){var d=function(){function b(b,c){c=c||document.documentElement;var d=c.style,e;if(typeof d[b]=="string")return b;b=b.charAt(0).toUpperCase()+b.slice(1);for(var f=0,g=a.length;fg?1:fc.width&&(c.fitRows.x=0,c.fitRows.y=c.fitRows.height),f=c.fitRows.x+c.posLeft,g=c.fitRows.y+c.posTop,c._pushPosition(a,f,g),c.fitRows.height=Math.max(c.fitRows.y+e,c.fitRows.height),c.fitRows.x+=d})},_fitRowsReset:function(){this.fitRows={x:0,y:0,height:0}},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResize:function(){this.reLayout()},_cellsByRowReset:function(){this.cellsByRow={},this._getSegments("cellsByRow"),this.cellsByRow.rowHeight=this.options.cellsByRow.rowHeight||this.$allAtoms.outerHeight(!0)},_cellsByRowLayout:function(a){var c=this,d=this.cellsByRow.cols;this.cellsByRow.atomsLen=a.length,a.each(function(a){var e=b(this),f=(a%d+.5)*c.cellsByRow.columnWidth-e.outerWidth(!0)/2+c.posLeft,g=(~~(a/d)+.5)*c.cellsByRow.rowHeight-e.outerHeight(!0)/2+c.posTop;c._pushPosition(e,f,g)})},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.cellsByRow.atomsLen/this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.posTop}},_cellsByRowResize:function(){var a=this.cellsByRow.cols;this._getSegments("cellsByRow"),this.cellsByRow.cols!==a&&this.reLayout()},_straightDownReset:function(){this.straightDown={y:0}},_straightDownLayout:function(a){var c=this;a.each(function(a){var d=b(this),e=c.straightDown.y+c.posTop;c._pushPosition(d,c.posLeft,e),c.straightDown.y+=d.outerHeight(!0)})},_straightDownGetContainerSize:function(){return{height:this.straightDown.y+this.posTop}},_straightDownResize:function(){this.reLayout()},_masonryHorizontalPlaceBrick:function(a,b,c){var d=Math.min.apply(Math,c),e=d+a.outerWidth(!0),f=c.length,g=f,h=this.masonryHorizontal.rows+1-f,i,j;while(f--)c[f]===d&&(g=f);i=d,j=this.masonryHorizontal.rowHeight*g+this.posTop,this._pushPosition(a,i,j);for(f=0;fc.height&&(c.fitColumns.x=c.fitColumns.width,c.fitColumns.y=0),f=c.fitColumns.x+c.posLeft,g=c.fitColumns.y+c.posTop,c._pushPosition(a,f,g),c.fitColumns.width=Math.max(c.fitColumns.x+d,c.fitColumns.width),c.fitColumns.y+=e})},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResize:function(){this.reLayout()},_cellsByColumnReset:function(){this.cellsByColumn={},this._getSegments("cellsByColumn",!0),this.cellsByColumn.columnWidth=this.options.cellsByColumn.columnWidth||this.$allAtoms.outerHeight(!0)},_cellsByColumnLayout:function(a){var c=this,d=this.cellsByColumn.rows;this.cellsByColumn.atomsLen=a.length,a.each(function(a){var e=b(this),f=(~~(a/d)+.5)*c.cellsByColumn.columnWidth-e.outerWidth(!0)/2+c.posLeft,g=(a%d+.5)*c.cellsByColumn.rowHeight-e.outerHeight(!0)/2+c.posTop;c._pushPosition(e,f,g)})},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.cellsByColumn.atomsLen/this.cellsByColumn.rows)*this.cellsByColumn.columnWidth+this.posLeft}},_cellsByColumnResize:function(){var a=this.cellsByColumn.rows;this._getSegments("cellsByColumn",!0),this.cellsByColumn.rows!==a&&this.reLayout()},_straightAcrossReset:function(){this.straightAcross={x:0}},_straightAcrossLayout:function(a){var c=this;a.each(function(a){var d=b(this),e=c.straightAcross.x+c.posLeft;c._pushPosition(d,e,c.posTop),c.straightAcross.x+=d.outerWidth(!0)})},_straightAcrossGetContainerSize:function(){return{width:this.straightAcross.x+this.posLeft}},_straightAcrossResize:function(){this.reLayout()}},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},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)return b.error("cannot call methods on isotope prior to initialization; attempted to call method '"+a+"'");if(!b.isFunction(d[a])||a.charAt(0)==="_")return b.error("no such method '"+a+"' for isotope instance");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){var d=function(){function b(b,c){c=c||document.documentElement;var d=c.style,e;if(typeof d[b]=="string")return b;b=b.charAt(0).toUpperCase()+b.slice(1);for(var f=0,g=a.length;fg?1:fc.width&&(c.fitRows.x=0,c.fitRows.y=c.fitRows.height),f=c.fitRows.x+c.posLeft,g=c.fitRows.y+c.posTop,c._pushPosition(a,f,g),c.fitRows.height=Math.max(c.fitRows.y+e,c.fitRows.height),c.fitRows.x+=d})},_fitRowsReset:function(){this.fitRows={x:0,y:0,height:0}},_fitRowsGetContainerSize:function(){return{height:this.fitRows.height}},_fitRowsResizeChanged:function(){return!0},_cellsByRowReset:function(){this.cellsByRow={},this._getSegments(),this.cellsByRow.rowHeight=this.options.cellsByRow.rowHeight||this.$allAtoms.outerHeight(!0)},_cellsByRowLayout:function(a){var c=this,d=this.cellsByRow.cols;this.cellsByRow.atomsLen=a.length,a.each(function(a){var e=b(this),f=(a%d+.5)*c.cellsByRow.columnWidth-e.outerWidth(!0)/2+c.posLeft,g=(~~(a/d)+.5)*c.cellsByRow.rowHeight-e.outerHeight(!0)/2+c.posTop;c._pushPosition(e,f,g)})},_cellsByRowGetContainerSize:function(){return{height:Math.ceil(this.cellsByRow.atomsLen/this.cellsByRow.cols)*this.cellsByRow.rowHeight+this.posTop}},_cellsByRowResizeChanged:function(){return this._getIfSegmentsChanged()},_straightDownReset:function(){this.straightDown={y:0}},_straightDownLayout:function(a){var c=this;a.each(function(a){var d=b(this),e=c.straightDown.y+c.posTop;c._pushPosition(d,c.posLeft,e),c.straightDown.y+=d.outerHeight(!0)})},_straightDownGetContainerSize:function(){return{height:this.straightDown.y+this.posTop}},_straightDownResizeChanged:function(){return!0},_masonryHorizontalPlaceBrick:function(a,b,c){var d=Math.min.apply(Math,c),e=d+a.outerWidth(!0),f=c.length,g=f,h=this.masonryHorizontal.rows+1-f,i,j;while(f--)c[f]===d&&(g=f);i=d,j=this.masonryHorizontal.rowHeight*g+this.posTop,this._pushPosition(a,i,j);for(f=0;fc.height&&(c.fitColumns.x=c.fitColumns.width,c.fitColumns.y=0),f=c.fitColumns.x+c.posLeft,g=c.fitColumns.y+c.posTop,c._pushPosition(a,f,g),c.fitColumns.width=Math.max(c.fitColumns.x+d,c.fitColumns.width),c.fitColumns.y+=e})},_fitColumnsGetContainerSize:function(){return{width:this.fitColumns.width}},_fitColumnsResizeChanged:function(){return!0},_cellsByColumnReset:function(){this.cellsByColumn={},this._getSegments(!0),this.cellsByColumn.columnWidth=this.options.cellsByColumn.columnWidth||this.$allAtoms.outerHeight(!0)},_cellsByColumnLayout:function(a){var c=this,d=this.cellsByColumn.rows;this.cellsByColumn.atomsLen=a.length,a.each(function(a){var e=b(this),f=(~~(a/d)+.5)*c.cellsByColumn.columnWidth-e.outerWidth(!0)/2+c.posLeft,g=(a%d+.5)*c.cellsByColumn.rowHeight-e.outerHeight(!0)/2+c.posTop;c._pushPosition(e,f,g)})},_cellsByColumnGetContainerSize:function(){return{width:Math.ceil(this.cellsByColumn.atomsLen/this.cellsByColumn.rows)*this.cellsByColumn.columnWidth+this.posLeft}},_cellsByColumnResizeChanged:function(){return this._getIfSegmentsChanged()},_straightAcrossReset:function(){this.straightAcross={x:0}},_straightAcrossLayout:function(a){var c=this;a.each(function(a){var d=b(this),e=c.straightAcross.x+c.posLeft;c._pushPosition(d,e,c.posTop),c.straightAcross.x+=d.outerWidth(!0)})},_straightAcrossGetContainerSize:function(){return{width:this.straightAcross.x+this.posLeft}},_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},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)return b.error("cannot call methods on isotope prior to initialization; attempted to call method '"+a+"'");if(!b.isFunction(d[a])||a.charAt(0)==="_")return b.error("no such method '"+a+"' for isotope instance");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);