mirror of https://github.com/metafizzy/isotope
Filter & sort magical layouts
http://isotope.metafizzy.co
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
9 years ago
|
QUnit.test( 'sorting', function( assert ) {
|
||
12 years ago
|
|
||
9 years ago
|
'use strict';
|
||
|
|
||
12 years ago
|
// sorting with history
|
||
|
( function() {
|
||
|
var iso = new Isotope( '#sorting1', {
|
||
|
layoutMode: 'fitRows',
|
||
|
transitionDuration: 0,
|
||
|
getSortData: {
|
||
|
letter: 'b',
|
||
|
number: 'i'
|
||
|
},
|
||
|
sortBy: 'number'
|
||
|
});
|
||
|
|
||
11 years ago
|
iso.arrange({ sortBy: 'letter' });
|
||
12 years ago
|
|
||
|
var texts = getItemsText( iso );
|
||
|
|
||
9 years ago
|
assert.equal( texts, 'A1,A2,A3,A4,B1,B2,B4', 'items sorted by letter, then number, via history' );
|
||
12 years ago
|
|
||
|
iso.destroy();
|
||
|
})();
|
||
|
|
||
|
// sorting with array
|
||
|
( function() {
|
||
|
var iso = new Isotope( '#sorting1', {
|
||
|
layoutMode: 'fitRows',
|
||
|
transitionDuration: 0,
|
||
|
getSortData: {
|
||
|
letter: 'b',
|
||
|
number: 'i'
|
||
|
},
|
||
|
sortBy: [ 'letter', 'number' ]
|
||
|
});
|
||
|
|
||
9 years ago
|
assert.equal( getItemsText( iso ), 'A1,A2,A3,A4,B1,B2,B4', 'sortBy array' );
|
||
12 years ago
|
|
||
11 years ago
|
iso.arrange({
|
||
12 years ago
|
sortAscending: false
|
||
|
});
|
||
9 years ago
|
assert.equal( getItemsText( iso ), 'B4,B2,B1,A4,A3,A2,A1', 'sortAscending false' );
|
||
12 years ago
|
|
||
11 years ago
|
iso.arrange({
|
||
12 years ago
|
sortAscending: {
|
||
|
letter: true,
|
||
|
number: false
|
||
|
}
|
||
|
});
|
||
9 years ago
|
assert.equal( getItemsText( iso ), 'A4,A3,A2,A1,B4,B2,B1', 'sortAscending with object' );
|
||
12 years ago
|
|
||
|
iso.destroy();
|
||
|
})();
|
||
|
|
||
9 years ago
|
function getItemsText( iso ) {
|
||
|
var texts = iso.filteredItems.map( function( item ) {
|
||
|
return item.element.textContent;
|
||
|
});
|
||
|
return texts.join(',');
|
||
|
}
|
||
12 years ago
|
|
||
9 years ago
|
});
|