summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarius Mathiesen <marius@shortcut.no>2009-10-29 14:58:50 +0100
committerJohan Sørensen <johan@johansorensen.com>2009-11-04 15:23:44 +0100
commitdacffe1f46eff3c0ad478a3b648125105eda1ee6 (patch)
tree311e0b0ce5599b9c160bc9ad8610ff8b0682a91e
parent1a7b3a0ba79414fc91a3ca117f1c0e1ebbe80a6d (diff)
downloadgitorious-mainline-outdated-dacffe1f46eff3c0ad478a3b648125105eda1ee6.zip
gitorious-mainline-outdated-dacffe1f46eff3c0ad478a3b648125105eda1ee6.tar.gz
gitorious-mainline-outdated-dacffe1f46eff3c0ad478a3b648125105eda1ee6.tar.bz2
Selecting line numbers without text now works, line numbers are sorted correctly
- Fetch line number from parent instead of text - Extended Array.prototype with min() and max() methods, use these to extract first and last line numbers
-rw-r--r--public/javascripts/core_extensions.js13
-rw-r--r--public/javascripts/diff_browser.js6
-rw-r--r--test/javascripts/application_test.js7
3 files changed, 23 insertions, 3 deletions
diff --git a/public/javascripts/core_extensions.js b/public/javascripts/core_extensions.js
index 9b2842d..b9e3ed4 100644
--- a/public/javascripts/core_extensions.js
+++ b/public/javascripts/core_extensions.js
@@ -58,3 +58,16 @@ if (!String.prototype.isBlank) {
return this == "";
}
}
+
+// http://ejohn.org/blog/fast-javascript-maxmin/
+if (!Array.prototype.max) {
+ Array.prototype.max = function() {
+ return Math.max.apply(Math, this);
+ }
+}
+
+if (!Array.prototype.min) {
+ Array.prototype.min = function() {
+ return Math.min.apply(Math, this);
+ }
+} \ No newline at end of file
diff --git a/public/javascripts/diff_browser.js b/public/javascripts/diff_browser.js
index 3b78ad1..9e38e2d 100644
--- a/public/javascripts/diff_browser.js
+++ b/public/javascripts/diff_browser.js
@@ -548,7 +548,8 @@ Gitorious.enableCommenting = function() {
$(this).parent().addClass("selected-for-commenting");
})
var allLineNumbers = $(diffTable).find("td.ui-selected").map(function(){
- return $(this).text();
+ var lineNo = $(this).parent().attr("class").replace(/[\sa-z\-]*/g,"");
+ return lineNo;
});
var path = $(diffTable).parent().prev(".header").children(".title").text();
var commentForm = new Gitorious.CommentForm(path);
@@ -605,8 +606,7 @@ Gitorious.CommentForm = function(path){
this.numbers = result;
}
this.linesAsString = function() {
- var sortedLines = this.numbers.sort();
- return sortedLines[0] + ".." + sortedLines[sortedLines.length - 1];
+ return this.numbers.min() + ".." + this.numbers.max();
}
this.hasLines = function() {
return this.numbers.length > 0;
diff --git a/test/javascripts/application_test.js b/test/javascripts/application_test.js
index 8302149..c7c029d 100644
--- a/test/javascripts/application_test.js
+++ b/test/javascripts/application_test.js
@@ -13,6 +13,13 @@ ArrayTest.prototype.testFilter = function() {
assertEquals(["foo"], result);
}
+ArrayTest.prototype.testMinAndMax = function() {
+ var arr = [1,2,3];
+ assertEquals(1, arr.min());
+ assertEquals(3, arr.max());
+ assertEquals(100, [1,"100","99",99].max());
+}
+
StringTest = TestCase("String test");