From f2d605cc32247fd904d0ff9ba3fd10c94ef7ef77 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 14 Oct 2013 23:24:29 -0400 Subject: [PATCH] LayoutMode.getSegmentSize --- layout-mode.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/layout-mode.js b/layout-mode.js index 9765612..a9d1a8e 100644 --- a/layout-mode.js +++ b/layout-mode.js @@ -65,29 +65,32 @@ function layoutModeDefinition( getSize, Outlayer ) { // ----- measurements ----- // LayoutMode.prototype.getColumnWidth = function() { - this._getMeasurement( 'columnWidth', 'outerWidth' ); - if ( this.columnWidth ) { - // got column width, we can chill - return; - } - // columnWidth fall back to item of first element - var firstItemSize = this.getFirstItemSize(); - this.columnWidth = firstItemSize && firstItemSize.outerWidth || - // or size of container - this.isotope.size.innerWidth; + this.getSegmentSize( 'column', 'Width' ); }; LayoutMode.prototype.getRowHeight = function() { - this._getMeasurement( 'rowHeight', 'outerHeight' ); - if ( this.rowHeight ) { - // got rowHeight, we can chill + this.getSegmentSize( 'row', 'Height' ); + }; + + /** + * get columnWidth or rowHeight + * segment: 'column' or 'row' + * size 'Width' or 'Height' + **/ + LayoutMode.prototype.getSegmentSize = function( segment, size ) { + var segmentName = segment + size; + var outerSize = 'outer' + size; + // columnWidth / outerWidth // rowHeight / outerHeight + this._getMeasurement( segmentName, outerSize ); + // got rowHeight or columnWidth, we can chill + if ( this[ segmentName ] ) { return; } - // columnWidth fall back to item of first element + // fall back to item of first element var firstItemSize = this.getFirstItemSize(); - this.rowHeight = firstItemSize && firstItemSize.outerHeight || + this.rowHeight = firstItemSize && firstItemSize[ outerSize ] || // or size of container - this.isotope.size.innerHeight; + this.isotope.size[ 'inner' + size ]; }; LayoutMode.prototype.getFirstItemSize = function() {