|
|
|
@ -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
|
|
|
|
|