2011-01-05 Ojan Vafai <ojan@chromium.org>
authorojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 02:50:16 +0000 (02:50 +0000)
committerojan@chromium.org <ojan@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 6 Jan 2011 02:50:16 +0000 (02:50 +0000)
        Reviewed by Adam Barth.

        assorted cleanups to prepare for side-by-side diffing
        https://bugs.webkit.org/show_bug.cgi?id=51961

        Mostly, use selector queries instead of assuming comments are next siblings.

        * code-review.js:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75130 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/bugs.webkit.org/ChangeLog
Websites/bugs.webkit.org/code-review.js

index e37dd889bc81f8b24147d5dc680c1c2056332a25..d91322eb4df3572940c1cc0b8b27fe4e3176b41b 100644 (file)
@@ -1,3 +1,14 @@
+2011-01-05  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        assorted cleanups to prepare for side-by-side diffing
+        https://bugs.webkit.org/show_bug.cgi?id=51961
+
+        Mostly, use selector queries instead of assuming comments are next siblings.
+
+        * code-review.js:
+
 2011-01-05  Ojan Vafai  <ojan@chromium.org>
 
         Reviewed by Adam Barth.
index 49cad008aa51d75788b2e6de185d0282a8a965d9..9163cf0499cf520530ae7dac55aa8edcb0f63b1d 100644 (file)
     });
   }
 
+  function diffSectionFrom(line) {
+    return line.parents('.FileDiff');
+  }
+
   function previousCommentsFor(line) {
-    var comments = [];
-    var position = line;
-    while (position.next() && position.next().hasClass('previousComment')) {
-      position = position.next();
-      comments.push(position.get());
-    }
-    return $(comments);
+    // Scope to the diffSection as a performance improvement.
+    return $('div[data-comment-for~="' + line[0].id + '"].previousComment', diffSectionFrom(line));
   }
 
   function findCommentPositionFor(line) {
-    var position = line;
-    while (position.next() && position.next().hasClass('previousComment'))
-      position = position.next();
-    return position;
+    var previous_comments = previousCommentsFor(line);
+    var num_previous_comments = previous_comments.size();
+    if (num_previous_comments)
+      return $(previous_comments[num_previous_comments - 1])
+    return line;
   }
 
   function findCommentBlockFor(line) {
         continue;
       var quote_markers = parts[1];
       var file_name = parts[2];
+      // FIXME: Store multiple lines for multiline comments and correctly import them here.
       var line_number = parts[3];
       if (!file_name in files)
         continue;
         (amount ? amount + " " : "") + direction + "</a>";
   }
 
-  $(window).bind('click', function (e) {
-    var target = e.target;
-    if (target.className != 'ExpandLink')
-      return;
-
-    // Can't use $ here because something in the window's scope sets $ to something other than jQuery.
-    var expand_bar = jQuery(target).parents('.ExpandBar');
+  function handleExpandLinkClick(target) {
+    var expand_bar = $(target).parents('.ExpandBar');
     var file_name = expand_bar.parents('.FileDiff').children('h1')[0].textContent;
     var expand_function = partial(expand, expand_bar[0], file_name, target.getAttribute('data-direction'), Number(target.getAttribute('data-amount')));
     if (file_name in original_file_contents)
       expand_function();
     else
       getWebKitSourceFile(file_name, expand_function, expand_bar);
+  };
+
+  $(window).bind('click', function (e) {
+    var target = e.target;
+
+    switch(target.className) {
+    case 'ExpandLink':
+      handleExpandLinkClick(target);
+      break;
+    }
   });
 
   function getWebKitSourceFile(file_name, onLoad, expand_bar) {