Browse Source

🐞 fix sortHistory bug. Fixes #1235

fix bug with 'string' being added as string, not array
pull/427/merge
David DeSandro 8 years ago
parent
commit
8b46d49225
  1. 2
      bower.json
  2. 26
      js/isotope.js
  3. 2
      package.json
  4. 11
      test/index.html
  5. 22
      test/unit/sorting.js

2
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"

26
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

2
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"

11
test/index.html

@ -56,6 +56,17 @@
<div class="item"><b>A</b><i>2</i></div>
</div>
<div id="sorting2" class="container">
<div class="item"><b>B</b><i>2</i><span>Y</span></div>
<div class="item"><b>B</b><i>1</i><span>Y</span></div>
<div class="item"><b>B</b><i>2</i><span>X</span></div>
<div class="item"><b>B</b><i>1</i><span>X</span></div>
<div class="item"><b>A</b><i>2</i><span>Y</span></div>
<div class="item"><b>A</b><i>1</i><span>Y</span></div>
<div class="item"><b>A</b><i>2</i><span>X</span></div>
<div class="item"><b>A</b><i>1</i><span>X</span></div>
</div>
<h2>getSortData</h2>
<div id="get-sort-data" class="container">

22
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;

Loading…
Cancel
Save