Skip to content

Commit a7cc0be

Browse files
committed
src : layout mode API : add _checkIfSegmentsChanged method; remove namespace arg from _getSegments; layoutModeResize -> layoutModeResizeChanged, which returns boolean;
1 parent 8a03c40 commit a7cc0be

File tree

2 files changed

+43
-53
lines changed

2 files changed

+43
-53
lines changed

jquery.isotope.js

+41-51
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Isotope v1.2.110523
2+
* Isotope v1.3.110523
33
* An exquisite jQuery plugin for magical layouts
44
* http://isotope.metafizzy.co
55
*
@@ -636,7 +636,9 @@
636636

637637

638638
resize : function() {
639-
this[ '_' + this.options.layoutMode + 'Resize' ]();
639+
if ( this[ '_' + this.options.layoutMode + 'ResizeChanged' ]() ) {
640+
this.reLayout();
641+
}
640642
},
641643

642644

@@ -757,11 +759,15 @@
757759

758760
},
759761

762+
763+
// ====================== LAYOUTS ======================
764+
760765
// calculates number of rows or columns
761766
// requires columnWidth or rowHeight to be set on namespaced object
762767
// i.e. this.masonry.columnWidth = 200
763-
_getSegments : function( namespace, isRows ) {
764-
var measure = isRows ? 'rowHeight' : 'columnWidth',
768+
_getSegments : function( isRows ) {
769+
var namespace = this.layoutMode,
770+
measure = isRows ? 'rowHeight' : 'columnWidth',
765771
size = isRows ? 'height' : 'width',
766772
UCSize = isRows ? 'Height' : 'Width',
767773
segmentsName = isRows ? 'rows' : 'cols',
@@ -786,10 +792,18 @@
786792
this[ namespace ][ measure ] = segmentSize;
787793

788794
},
795+
796+
_checkIfSegmentsChanged : function( isRows ) {
797+
var segmentsName = isRows ? 'rows' : 'cols',
798+
prevSegments = this[ this.layoutMode ][ segmentsName ];
799+
// update cols/rows
800+
this._getSegments( isRows );
801+
// return if updated cols/rows is not equal to previous
802+
var changed = ( this[ this.layoutMode ][ segmentsName ] !== prevSegments );
803+
console.log( changed );
804+
return changed;
805+
},
789806

790-
// ====================== LAYOUTS ======================
791-
792-
793807
// ====================== Masonry ======================
794808

795809
_masonryPlaceBrick : function( $brick, setCount, setY ) {
@@ -858,22 +872,16 @@
858872
// layout-specific props
859873
this.masonry = {};
860874
// FIXME shouldn't have to call this again
861-
this._getSegments('masonry');
875+
this._getSegments();
862876
var i = this.masonry.cols;
863877
this.masonry.colYs = [];
864878
while (i--) {
865879
this.masonry.colYs.push( this.posTop );
866880
}
867881
},
868882

869-
_masonryResize : function() {
870-
var prevColCount = this.masonry.cols;
871-
// get updated colCount
872-
this._getSegments('masonry');
873-
if ( this.masonry.cols !== prevColCount ) {
874-
// if column count has changed, do a new column cound
875-
this.reLayout();
876-
}
883+
_masonryResizeChanged : function() {
884+
return this._checkIfSegmentsChanged();
877885
},
878886

879887
_masonryGetContainerSize : function() {
@@ -923,16 +931,16 @@
923931
return { height : this.fitRows.height };
924932
},
925933

926-
_fitRowsResize : function() {
927-
this.reLayout();
934+
_fitRowsResizeChanged : function() {
935+
return true;
928936
},
929937

930938

931939
// ====================== cellsByRow ======================
932940

933941
_cellsByRowReset : function() {
934942
this.cellsByRow = {};
935-
this._getSegments('cellsByRow');
943+
this._getSegments();
936944
this.cellsByRow.rowHeight = this.options.cellsByRow.rowHeight || this.$allAtoms.outerHeight(true);
937945
},
938946

@@ -954,14 +962,8 @@
954962
return { height : Math.ceil( this.cellsByRow.atomsLen / this.cellsByRow.cols ) * this.cellsByRow.rowHeight + this.posTop };
955963
},
956964

957-
_cellsByRowResize : function() {
958-
var prevCols = this.cellsByRow.cols;
959-
this._getSegments('cellsByRow');
960-
961-
// if column count has changed, do a new column cound
962-
if ( this.cellsByRow.cols !== prevCols ) {
963-
this.reLayout();
964-
}
965+
_cellsByRowResizeChanged : function() {
966+
return this._getIfSegmentsChanged();
965967
},
966968

967969

@@ -987,8 +989,8 @@
987989
return { height : this.straightDown.y + this.posTop };
988990
},
989991

990-
_straightDownResize : function() {
991-
this.reLayout();
992+
_straightDownResizeChanged : function() {
993+
return true;
992994
},
993995

994996

@@ -1057,22 +1059,16 @@
10571059
// layout-specific props
10581060
this.masonryHorizontal = {};
10591061
// FIXME shouldn't have to call this again
1060-
this._getSegments( 'masonryHorizontal', true );
1062+
this._getSegments( true );
10611063
var i = this.masonryHorizontal.rows;
10621064
this.masonryHorizontal.rowXs = [];
10631065
while (i--) {
10641066
this.masonryHorizontal.rowXs.push( this.posLeft );
10651067
}
10661068
},
10671069

1068-
_masonryHorizontalResize : function() {
1069-
var prevRows = this.masonryHorizontal.rows;
1070-
// get updated colCount
1071-
this._getSegments( 'masonryHorizontal', true );
1072-
if ( this.masonryHorizontal.rows !== prevRows ) {
1073-
// if column count has changed, do a new column cound
1074-
this.reLayout();
1075-
}
1070+
_masonryHorizontalResizeChanged : function() {
1071+
return this._getIfSegmentsChanged();
10761072
},
10771073

10781074
_masonryHorizontalGetContainerSize : function() {
@@ -1121,8 +1117,8 @@
11211117
return { width : this.fitColumns.width };
11221118
},
11231119

1124-
_fitColumnsResize : function() {
1125-
this.reLayout();
1120+
_fitColumnsResizeChanged : function() {
1121+
return true;
11261122
},
11271123

11281124

@@ -1131,7 +1127,7 @@
11311127

11321128
_cellsByColumnReset : function() {
11331129
this.cellsByColumn = {};
1134-
this._getSegments( 'cellsByColumn', true );
1130+
this._getSegments( true );
11351131
this.cellsByColumn.columnWidth = this.options.cellsByColumn.columnWidth || this.$allAtoms.outerHeight(true);
11361132
},
11371133

@@ -1153,14 +1149,8 @@
11531149
return { width : Math.ceil( this.cellsByColumn.atomsLen / this.cellsByColumn.rows ) * this.cellsByColumn.columnWidth + this.posLeft };
11541150
},
11551151

1156-
_cellsByColumnResize : function() {
1157-
var prevRows = this.cellsByColumn.rows;
1158-
this._getSegments( 'cellsByColumn', true );
1159-
1160-
// if column count has changed, do a new column cound
1161-
if ( this.cellsByColumn.rows !== prevRows ) {
1162-
this.reLayout();
1163-
}
1152+
_cellsByColumnResizeChanged : function() {
1153+
return this._getIfSegmentsChanged();
11641154
},
11651155

11661156
// ====================== straightAcross ======================
@@ -1185,8 +1175,8 @@
11851175
return { width : this.straightAcross.x + this.posLeft };
11861176
},
11871177

1188-
_straightAcrossResize : function() {
1189-
this.reLayout();
1178+
_straightAcrossResizeChanged : function() {
1179+
return true;
11901180
}
11911181

11921182
};

0 commit comments

Comments
 (0)