Browse Source

fixed sorting algo for multiple sorting support

pull/379/head
Jason Edelman 12 years ago
parent
commit
68a015bfe4
  1. 39
      jquery.isotope.js

39
jquery.isotope.js

@ -565,22 +565,35 @@
// used on all the filtered atoms // used on all the filtered atoms
_sort : function() { _sort : function() {
var sortBy = $.map(this.options.sortBy.split(','), $.trim)
var sortBy = this.options.sortBy, , getSorter = this._getSorter
getSorter = this._getSorter, , sortDir = this.options.sortAscending ? 1 : -1
sortDir = this.options.sortAscending ? 1 : -1, , len = sortBy.length
sortFn = function( alpha, beta ) { , sortFunc = function (a, b){
var a = getSorter( alpha, sortBy ), isNaN(a) && (a = a.toLowerCase());
b = getSorter( beta, sortBy ); isNaN(b) && (b = b.toLowerCase());
// fall back to original order if data matches return ( a > b ) ? 1 : ( a < b ) ? -1 : 0;
if ( a === b && sortBy !== 'original-order') { }
;
this.$filteredAtoms.sort(function(alpha, beta){
var sort, comparison = 0, i = 0
, a , b
;
if (sortBy[0] === 'original-order') {
a = getSorter(alpha, 'original-order' ); a = getSorter(alpha, 'original-order' );
b = getSorter(beta, 'original-order' ); b = getSorter(beta, 'original-order' );
return sortFunc(a, b) * sortDir;
} else {
while(comparison == 0 && i < len){
sort = sortBy[i],
a = getSorter(alpha, sort),
b = getSorter(beta, sort);
comparison = sortFunc(a, b);
i+=1;
} }
return ( ( a > b ) ? 1 : ( a < b ) ? -1 : 0 ) * sortDir; return comparison * sortDir;
}; }
});
this.$filteredAtoms.sort( sortFn );
}, },
_getSorter : function( elem, sortBy ) { _getSorter : function( elem, sortBy ) {

Loading…
Cancel
Save