Skip to content

Commit

Permalink
src : layout mode API : add _checkIfSegmentsChanged method; remove na…
Browse files Browse the repository at this point in the history
…mespace arg from _getSegments; layoutModeResize -> layoutModeResizeChanged, which returns boolean;
  • Loading branch information
desandro committed May 23, 2011
1 parent 8a03c40 commit a7cc0be
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 53 deletions.
92 changes: 41 additions & 51 deletions jquery.isotope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Isotope v1.2.110523
* Isotope v1.3.110523
* An exquisite jQuery plugin for magical layouts
* http://isotope.metafizzy.co
*
Expand Down Expand Up @@ -636,7 +636,9 @@


resize : function() {
this[ '_' + this.options.layoutMode + 'Resize' ]();
if ( this[ '_' + this.options.layoutMode + 'ResizeChanged' ]() ) {
this.reLayout();
}
},


Expand Down Expand Up @@ -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',
Expand All @@ -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 ) {
Expand Down Expand Up @@ -858,22 +872,16 @@
// 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--) {
this.masonry.colYs.push( this.posTop );
}
},

_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() {
Expand Down Expand Up @@ -923,16 +931,16 @@
return { height : this.fitRows.height };
},

_fitRowsResize : function() {
this.reLayout();
_fitRowsResizeChanged : function() {
return true;
},


// ====================== cellsByRow ======================

_cellsByRowReset : function() {
this.cellsByRow = {};
this._getSegments('cellsByRow');
this._getSegments();
this.cellsByRow.rowHeight = this.options.cellsByRow.rowHeight || this.$allAtoms.outerHeight(true);
},

Expand All @@ -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();
},


Expand All @@ -987,8 +989,8 @@
return { height : this.straightDown.y + this.posTop };
},

_straightDownResize : function() {
this.reLayout();
_straightDownResizeChanged : function() {
return true;
},


Expand Down Expand Up @@ -1057,22 +1059,16 @@
// 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--) {
this.masonryHorizontal.rowXs.push( this.posLeft );
}
},

_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() {
Expand Down Expand Up @@ -1121,8 +1117,8 @@
return { width : this.fitColumns.width };
},

_fitColumnsResize : function() {
this.reLayout();
_fitColumnsResizeChanged : function() {
return true;
},


Expand All @@ -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);
},

Expand All @@ -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 ======================
Expand All @@ -1185,8 +1175,8 @@
return { width : this.straightAcross.x + this.posLeft };
},

_straightAcrossResize : function() {
this.reLayout();
_straightAcrossResizeChanged : function() {
return true;
}

};
Expand Down
Loading

0 comments on commit a7cc0be

Please sign in to comment.