Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #19 from alexandernst/master
Browse files Browse the repository at this point in the history
Incorrect sorting
  • Loading branch information
addyosmani committed May 9, 2012
2 parents e2c4c30 + ce39952 commit c86747b
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 25 deletions.
60 changes: 48 additions & 12 deletions dist/backbone.paginator.js
@@ -1,4 +1,4 @@
/*! backbone.paginator - v0.1.54 - 5/7/2012
/*! backbone.paginator - v0.1.54 - 5/9/2012
* http://github.com/addyosmani/backbone.paginator
* Copyright (c) 2012 Addy Osmani; Licensed MIT */

Expand Down Expand Up @@ -102,23 +102,59 @@ Backbone.Paginator = (function ( Backbone, _, $ ) {
models = models.sort(function (a, b) {
var ac = a.get(sort),
bc = b.get(sort);


if ( !ac || !bc ) {
return 0;
} else {
/* Make sure that both ac and bc are lowercase strings.
* .toString() first so we don't have to worry if ac or bc
* have other String-only methods.
*/
ac = ac.toString().toLowerCase();
bc = bc.toString().toLowerCase();
}

if (direction === 'desc') {
if (ac > bc) {
return -1;
}

if (ac < bc) {
return 1;
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) &&
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/))
){

if( (ac - 0) < (bc - 0) ) {
return 1;
}
if( (ac - 0) > (bc - 0) ) {
return -1;
}
} else {
if (ac < bc) {
return 1;
}
if (ac > bc) {
return -1;
}
}

} else {
if (ac < bc) {
return -1;
}

if (ac > bc) {
return 1;
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) &&
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/))
){
if( (ac - 0) < (bc - 0) ) {
return -1;
}
if( (ac - 0) > (bc - 0) ) {
return 1;
}
} else {
if (ac < bc) {
return -1;
}
if (ac > bc) {
return 1;
}
}

}

return 0;
Expand Down
4 changes: 2 additions & 2 deletions dist/backbone.paginator.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 47 additions & 11 deletions lib/backbone.paginator.js
Expand Up @@ -99,23 +99,59 @@ Backbone.Paginator = (function ( Backbone, _, $ ) {
models = models.sort(function (a, b) {
var ac = a.get(sort),
bc = b.get(sort);


if ( !ac || !bc ) {
return 0;
} else {
/* Make sure that both ac and bc are lowercase strings.
* .toString() first so we don't have to worry if ac or bc
* have other String-only methods.
*/
ac = ac.toString().toLowerCase();
bc = bc.toString().toLowerCase();
}

if (direction === 'desc') {
if (ac > bc) {
return -1;
}

if (ac < bc) {
return 1;
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) &&
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/))
){

if( (ac - 0) < (bc - 0) ) {
return 1;
}
if( (ac - 0) > (bc - 0) ) {
return -1;
}
} else {
if (ac < bc) {
return 1;
}
if (ac > bc) {
return -1;
}
}

} else {
if (ac < bc) {
return -1;
}

if (ac > bc) {
return 1;
if((!ac.match(/[^\d\.]/) && ac.match(/[\d\.]*/)) &&
(!bc.match(/[^\d\.]/) && bc.match(/[\d\.]*/))
){
if( (ac - 0) < (bc - 0) ) {
return -1;
}
if( (ac - 0) > (bc - 0) ) {
return 1;
}
} else {
if (ac < bc) {
return -1;
}
if (ac > bc) {
return 1;
}
}

}

return 0;
Expand Down

0 comments on commit c86747b

Please sign in to comment.