diff --git a/web/index.html b/web/index.html
index 45f82bbd6..7252a17c0 100755
--- a/web/index.html
+++ b/web/index.html
@@ -525,6 +525,7 @@
Age
Name
Progress
+ Ratio
Queue Order
State
diff --git a/web/javascript/common.js b/web/javascript/common.js
index 1626ab778..66a342268 100644
--- a/web/javascript/common.js
+++ b/web/javascript/common.js
@@ -235,6 +235,7 @@ Prefs._SortByActivity = 'activity';
Prefs._SortByQueue = 'queue_order';
Prefs._SortByName = 'name';
Prefs._SortByProgress = 'percent_completed';
+Prefs._SortByRatio = 'ratio';
Prefs._SortByState = 'state';
Prefs._SortByTracker = 'tracker';
diff --git a/web/javascript/torrent.js b/web/javascript/torrent.js
index 965231ede..95df0142f 100644
--- a/web/javascript/torrent.js
+++ b/web/javascript/torrent.js
@@ -760,14 +760,19 @@ Torrent.compareByActivity = function( a, b ) {
};
/** Helper function for sortTorrents(). */
-Torrent.compareByProgress = function( a, b ) {
- if( a.getPercentDone() !== b.getPercentDone() )
- return a.getPercentDone() - b.getPercentDone();
+Torrent.compareByRatio = function( a, b ) {
var a_ratio = Math.ratio( a._upload_total, a._download_total );
var b_ratio = Math.ratio( b._upload_total, b._download_total );
return a_ratio - b_ratio;
};
+/** Helper function for sortTorrents(). */
+Torrent.compareByProgress = function( a, b ) {
+ if( a.getPercentDone() !== b.getPercentDone() )
+ return a.getPercentDone() - b.getPercentDone();
+ return this.compareByRatio( a, b );
+};
+
/**
* @param torrents an array of Torrent objects
* @param sortMethod one of Prefs._SortBy*
@@ -795,6 +800,9 @@ Torrent.sortTorrents = function( torrents, sortMethod, sortDirection )
case Prefs._SortByName:
torrents.sort( this.compareByName );
break;
+ case Prefs._SortByRatio:
+ torrents.sort( this.compareByRatio );
+ break;
default:
console.warn( "unknown sort method: " + sortMethod );
break;