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

        allow sidebysideifying individual files in the code review tool
        https://bugs.webkit.org/show_bug.cgi?id=52226

        * code-review.js:

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

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

index 76d0a83a8edeff14ab1c1124e21a6df9a666497b..8e3b1dc654428078fedff6add1a146ff8cb384ea 100644 (file)
@@ -1,3 +1,12 @@
+2011-01-11  Ojan Vafai  <ojan@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        allow sidebysideifying individual files in the code review tool
+        https://bugs.webkit.org/show_bug.cgi?id=52226
+
+        * code-review.js:
+
 2011-01-11  Ojan Vafai  <ojan@chromium.org>
 
         Reviewed by Mihai Parparita.
index 8774e852afb14313518e8d208a8d545057a103d8..1cc150fc91417ecfe20fca296378adf54604c1f4 100644 (file)
@@ -136,6 +136,23 @@ h1 :hover {
     float: right;
 }
 
+.DiffLinks a {
+    border: 0;
+    font-family: sans-serif;
+    font-size: small;
+    font-style: normal;
+}
+
+.FileDiff .DiffLinks {
+    float: none;
+    width: 100%;
+    height: 0;
+}
+
+.FileDiffLinkContainer {
+    text-align: center;
+}
+
 .DiffSection {
     background-color: white;
     border: solid #ddd;
@@ -305,7 +322,6 @@ body {
 
 .LinkContainer a {
   border: 0;
-  font-style: normal;
 }
 
 .LinkContainer a:after {
@@ -372,7 +388,7 @@ body {
 }
 </style>
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
-<script src="code-review.js?version=20"></script>
+<script src="code-review.js?version=21"></script>
 EOF
 
     def self.revisionOrDescription(string)
index 26dc13a798cebae5b85c2bc9efab53f061fe08ec..09727d9b6f636c077d69486f5b11b0173cce9401 100644 (file)
       var file_name = $(this).children('h1').text();
       files[file_name] = this;
       addExpandLinks(file_name);
+      $('h1', this).before('<div class="FileDiffLinkContainer">' + diffLinksHtml() + '</div>');
+      updateDiffLinkVisibility(this);
     });
   }
 
   }
 
   function handleSideBySideLinkClick() {
-    $('.FileDiff').each(function() {
-      convertFileDiff('sidebyside', this);
-    });
+    convertDiff('sidebyside', this);
   }
 
   function handleUnifyLinkClick() {
-    $('.FileDiff').each(function() {
-      convertFileDiff('unified', this);
+    convertDiff('unified', this);
+  }
+
+  function convertDiff(difftype, convert_link) {
+    var file_diffs = $(convert_link).parents('.FileDiff');
+    if (!file_diffs.size())
+      file_diffs = $('.FileDiff');
+
+    file_diffs.each(function() {
+      convertFileDiff(difftype, this);
     });
   }
 
     $('#toolbar').toggleClass('anchored', has_scrollbar);
   }
 
+  function diffLinksHtml(opt_containerClassName) {
+    var containerClassName = opt_containerClassName || '';
+    return '<div class="DiffLinks ' + containerClassName + '">' +
+      '<a href="javascript:" class="unify-link">unified</a>' +
+      '<a href="javascript:" class="side-by-side-link">side-by-side</a>' +
+    '</div>';
+  }
+
   $(document).ready(function() {
     crawlDiff();
     fetchHistory();
     $(document.body).prepend('<div id="message">' +
         '<div class="help">Select line numbers to add a comment.' +
-          '<div class="DiffLinks LinkContainer">' +
-            '<a href="javascript:" class="unify-link">unified</a>' +
-            '<a href="javascript:" class="side-by-side-link">side-by-side</a>' +
-          '</div>' +
+          diffLinksHtml('LinkContainer') +
         '</div>' +
         '<div class="commentStatus"></div>' +
         '</div>');
     old_line.replaceWith(new_line);
   }
 
+  function updateDiffLinkVisibility(file_diff) {
+    if (diffState(file_diff) == 'unified') {
+      $('.side-by-side-link', file_diff).show();
+      $('.unify-link', file_diff).hide();
+    } else {
+      $('.side-by-side-link', file_diff).hide();
+      $('.unify-link', file_diff).show();
+    }
+  }
+
   function convertFileDiff(diff_type, file_diff) {
     if (diffState(file_diff) == diff_type)
       return;
 
     $(file_diff).attr('data-diffstate', diff_type);
+    updateDiffLinkVisibility(file_diff);
 
     $('.Line', file_diff).each(function() {
       convertLine(diff_type, this);
   }
 
   // FIXME: Put removed lines to the left of their corresponding added lines.
-  // FIXME: Allow for converting an individual file to side-by-side.
   function sideBySideifyLine(line, from, to, contents, classNames, attributes, id) {
     var from_class = '';
     var to_class = '';