Browse Source

use boolean sortAscending instead of sortDir string

pull/14/head
David DeSandro 15 years ago
parent
commit
fe904f3eb2
  1. 44
      src/jquery.molequul.js

44
src/jquery.molequul.js

@ -32,7 +32,7 @@
queue: false queue: false
}, },
sortBy : 'original-order', sortBy : 'original-order',
sortDir : 'asc' sortAscending : true
}, },
@ -127,7 +127,7 @@
// check if watched properties are new // check if watched properties are new
var instance = this; var instance = this;
$.each( [ 'filter', 'sortBy', 'sortDir' ], function( i, propName ){ $.each( [ 'filter', 'sortBy', 'sortAscending' ], function( i, propName ){
instance.isNew[ propName ] = instance._isNewProp( propName ); instance.isNew[ propName ] = instance._isNewProp( propName );
}); });
@ -137,7 +137,7 @@
this.$filteredAtoms = this.$allAtoms; this.$filteredAtoms = this.$allAtoms;
} }
if ( this.isNew.filter || this.isNew.sortBy || this.isNew.sortDir ) { if ( this.isNew.filter || this.isNew.sortBy || this.isNew.sortAscending ) {
this._sort(); this._sort();
} }
@ -234,41 +234,19 @@
// ====================== Sorting ====================== // ====================== Sorting ======================
// used on all the filtered atoms, $atoms.filtered
_sort : function() {
_getSortFn : function( sortBy, sortDir ) { var instance = this,
getSorter = function( elem ) {
switch ( sortDir.toLowerCase() ) { return $(elem).data('molequul-sort-data')[ instance.options.sortBy ];
case 'd' : },
case 'des' : sortDir = this.options.sortAscending ? 1 : -1;
case 'desc' : sortFn = function( alpha, beta ) {
case 'desend' :
case 'decend' :
case 'descend' :
case 'descending' :
sortDir = -1;
break;
default :
sortDir = 1;
}
var getSorter = function( elem ) {
return $(elem).data('molequul-sort-data')[ sortBy ];
};
return function( alpha, beta ) {
var a = getSorter( alpha ), var a = getSorter( alpha ),
b = getSorter( beta ); b = getSorter( beta );
return ( ( a > b ) ? 1 : ( a < b ) ? -1 : 0 ) * sortDir; return ( ( a > b ) ? 1 : ( a < b ) ? -1 : 0 ) * sortDir;
}; };
},
randomSortFn : function() {
return Math.random() > 5 ? 1 : -1;
},
// used on all the filtered atoms, $atoms.filtered
_sort : function() {
var sortFn = this._getSortFn( this.options.sortBy, this.options.sortDir );
this.$filteredAtoms.sort( sortFn ); this.$filteredAtoms.sort( sortFn );

Loading…
Cancel
Save