diff --git a/bower.json b/bower.json index 12c17d1..5bbaa92 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "main": "js/isotope.js", "dependencies": { "desandro-matches-selector": "^2.0.0", - "fizzy-ui-utils": "^2.0.0", + "fizzy-ui-utils": "^2.0.4", "get-size": "^2.0.0", "masonry": "^4.1.0", "outlayer": "^2.1.0" diff --git a/js/isotope.js b/js/isotope.js index e6dce52..b914a89 100644 --- a/js/isotope.js +++ b/js/isotope.js @@ -402,20 +402,28 @@ var trim = String.prototype.trim ? // sort filteredItem order proto._sort = function() { - var sortByOpt = this.options.sortBy; - if ( !sortByOpt ) { + if ( !this.options.sortBy ) { return; } - // concat all sortBy and sortHistory - var sortBys = [].concat.apply( sortByOpt, this.sortHistory ); + // keep track of sortBy History + var sortBys = utils.makeArray( this.options.sortBy ); + if ( !this._getIsSameSortBy( sortBys ) ) { + // concat all sortBy and sortHistory, add to front, oldest goes in last + this.sortHistory = sortBys.concat( this.sortHistory ); + } // sort magic - var itemSorter = getItemSorter( sortBys, this.options.sortAscending ); + var itemSorter = getItemSorter( this.sortHistory, this.options.sortAscending ); this.filteredItems.sort( itemSorter ); - // keep track of sortBy History - if ( sortByOpt != this.sortHistory[0] ) { - // add to front, oldest goes in last - this.sortHistory.unshift( sortByOpt ); + }; + + // check if sortBys is same as start of sortHistory + proto._getIsSameSortBy = function( sortBys ) { + for ( var i=0; i < sortBys.length; i++ ) { + if ( sortBys[i] != this.sortHistory[i] ) { + return false; + } } + return true; }; // returns a function used for sorting diff --git a/package.json b/package.json index 0949a6d..2f61702 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "js/isotope.js", "dependencies": { "desandro-matches-selector": "^2.0.0", - "fizzy-ui-utils": "^2.0.0", + "fizzy-ui-utils": "^2.0.4", "get-size": "^2.0.0", "masonry-layout": "^4.0.0", "outlayer": "^2.1.0" diff --git a/test/index.html b/test/index.html index cce4eea..f6509ae 100644 --- a/test/index.html +++ b/test/index.html @@ -56,6 +56,17 @@
A2
+
+
B2Y
+
B1Y
+
B2X
+
B1X
+
A2Y
+
A1Y
+
A2X
+
A1X
+
+

getSortData

diff --git a/test/unit/sorting.js b/test/unit/sorting.js index 6884ff0..3924138 100644 --- a/test/unit/sorting.js +++ b/test/unit/sorting.js @@ -53,6 +53,28 @@ QUnit.test( 'sorting', function( assert ) { iso.destroy(); })(); + ( function() { + var iso = new Isotope( '#sorting2', { + layoutMode: 'fitRows', + transitionDuration: 0, + getSortData: { + letter: 'b', + number: 'i', + axis: 'span', + }, + sortBy: [ 'axis' ] + }); + + iso.arrange({ sortBy: 'number' }) + assert.equal( getItemsText( iso ), 'B1X,A1X,B1Y,A1Y,B2X,A2X,B2Y,A2Y', + 'sort history 1' ); + + iso.arrange({ sortBy: 'letter' }) + assert.equal( getItemsText( iso ), 'A1X,A1Y,A2X,A2Y,B1X,B1Y,B2X,B2Y', + 'sort history 2' ); + + })(); + function getItemsText( iso ) { var texts = iso.filteredItems.map( function( item ) { return item.element.textContent;