1 // Copyright (C) 2010 Adam Barth. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
6 // 1. Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright notice,
10 // this list of conditions and the following disclaimer in the documentation
11 // and/or other materials provided with the distribution.
13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS "AS IS" AND ANY
14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 // ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 * Create a new function with some of its arguements
29 * Taken from goog.partial in the Closure library.
30 * @param {Function} fn A function to partially apply.
31 * @param {...*} var_args Additional arguments that are partially
33 * @return {!Function} A partially-applied form of the function.
35 function partial(fn, var_args) {
36 var args = Array.prototype.slice.call(arguments, 1);
38 // Prepend the bound arguments to the current arguments.
39 var newArgs = Array.prototype.slice.call(arguments);
40 newArgs.unshift.apply(newArgs, args);
41 return fn.apply(this, newArgs);
45 function determineAttachmentID() {
47 return /id=(\d+)/.exec(window.location.search)[1]
53 // Attempt to activate only in the "Review Patch" context.
54 if (window.top != window)
56 if (!window.location.search.match(/action=review/))
58 var attachment_id = determineAttachmentID();
64 var original_file_contents = {};
65 var patched_file_contents = {};
66 var WEBKIT_BASE_DIR = "http://svn.webkit.org/repository/webkit/trunk/";
68 function idForLine(number) {
69 return 'line' + number;
72 function nextLineID() {
73 return idForLine(next_line_id++);
76 function forEachLine(callback) {
77 for (var i = 0; i < next_line_id; ++i) {
78 callback($('#' + idForLine(i)));
83 this.id = nextLineID();
87 $(this).hover(function() {
88 $(this).addClass('hot');
91 $(this).removeClass('hot');
95 function previousCommentsFor(line) {
98 while (position.next() && position.next().hasClass('previousComment')) {
99 position = position.next();
100 comments.push(position.get());
105 function findCommentPositionFor(line) {
107 while (position.next() && position.next().hasClass('previousComment'))
108 position = position.next();
112 function findCommentBlockFor(line) {
113 var comment_block = findCommentPositionFor(line).next();
114 if (!comment_block.hasClass('comment'))
116 return comment_block;
119 function insertCommentFor(line, block) {
120 findCommentPositionFor(line).after(block);
123 function addCommentFor(line) {
124 if (line.attr('data-has-comment')) {
125 // FIXME: This query is overly complex because we place comment blocks
126 // after Lines. Instead, comment blocks should be children of Lines.
127 findCommentPositionFor(line).next().next().filter('.frozenComment').each(unfreezeComment);
130 line.attr('data-has-comment', 'true');
131 line.addClass('commentContext');
133 var comment_block = $('<div class="comment"><textarea data-comment-for="' + line.attr('id') + '"></textarea><div class="actions"><button class="ok">OK</button><button class="discard">Discard</button></div></div>');
134 insertCommentFor(line, comment_block);
135 comment_block.hide().slideDown('fast', function() {
136 $(this).children('textarea').focus();
140 function addCommentField() {
141 var id = $(this).attr('data-comment-for');
144 addCommentFor($('#' + id));
147 function addPreviousComment(line, author, comment_text) {
148 var comment_block = $('<div data-comment-for="' + line.attr('id') + '" class="previousComment"></div>');
149 var author_block = $('<div class="author"></div>').text(author + ':');
150 var text_block = $('<div class="content"></div>').text(comment_text);
151 comment_block.append(author_block).append(text_block).each(hoverify).click(addCommentField);
152 insertCommentFor(line, comment_block);
155 function displayPreviousComments(comments) {
156 for (var i = 0; i < comments.length; ++i) {
157 var author = comments[i].author;
158 var file_name = comments[i].file_name;
159 var line_number = comments[i].line_number;
160 var comment_text = comments[i].comment_text;
162 var file = files[file_name];
164 var query = '.Line .to';
165 if (line_number[0] == '-') {
166 // The line_number represent a removal. We need to adjust the query to
167 // look at the "from" lines.
168 query = '.Line .from';
169 // Trim off the '-' control character.
170 line_number = line_number.substr(1);
173 $(file).find(query).each(function() {
174 if ($(this).text() != line_number)
176 var line = $(this).parent();
177 addPreviousComment(line, author, comment_text);
180 if (comments.length == 0)
182 descriptor = comments.length + ' comment';
183 if (comments.length > 1)
185 $('.message .commentStatus').text('This patch has ' + descriptor + '. Scroll through them with the "n" and "p" keys.');
188 function scanForComments(author, text) {
190 var lines = text.split('\n');
191 for (var i = 0; i < lines.length; ++i) {
192 var parts = lines[i].match(/^([> ]+)([^:]+):(-?\d+)$/);
195 var quote_markers = parts[1];
196 var file_name = parts[2];
197 var line_number = parts[3];
198 if (!file_name in files)
200 while (i < lines.length && lines[i].length > 0 && lines[i][0] == '>')
202 var comment_lines = [];
203 while (i < lines.length && (lines[i].length == 0 || lines[i][0] != '>')) {
204 comment_lines.push(lines[i]);
207 --i; // Decrement i because the for loop will increment it again in a second.
208 var comment_text = comment_lines.join('\n').trim();
211 'file_name': file_name,
212 'line_number': line_number,
213 'comment_text': comment_text
219 function isReviewFlag(select) {
220 return $(select).attr('title') == 'Request for patch review.';
223 function isCommitQueueFlag(select) {
224 return $(select).attr('title').match(/commit-queue/);
227 function findControlForFlag(select) {
228 if (isReviewFlag(select))
229 return $('#toolbar .review select');
230 else if (isCommitQueueFlag(select))
231 return $('#toolbar .commitQueue select');
235 function addFlagsForAttachment(details) {
236 var flag_control = "<select><option></option><option>?</option><option>+</option><option>-</option></select>";
237 $('#flagContainer').append(
238 $('<span class="review"> r: ' + flag_control + '</span>')).append(
239 $('<span class="commitQueue"> cq: ' + flag_control + '</span>'));
241 details.find('#flags select').each(function() {
242 var requestee = $(this).parent().siblings('td:first-child').text().trim();
243 if (requestee.length) {
244 // Remove trailing ':'.
245 requestee = requestee.substr(0, requestee.length - 1);
246 requestee = ' (' + requestee + ')';
248 var control = findControlForFlag(this)
249 control.attr('selectedIndex', $(this).attr('selectedIndex'));
250 control.parent().prepend(requestee);
254 window.addEventListener('message', function(e) {
255 if (e.origin != 'https://webkit-commit-queue.appspot.com')
259 $('.statusBubble')[0].style.height = e.data.height;
260 $('.statusBubble')[0].style.width = e.data.width;
264 function handleStatusBubbleLoad(e) {
265 e.target.contentWindow.postMessage('containerMetrics', 'https://webkit-commit-queue.appspot.com');
268 function fetchHistory() {
269 $.get('attachment.cgi?id=' + attachment_id + '&action=edit', function(data) {
270 var bug_id = /Attachment \d+ Details for Bug (\d+)/.exec(data)[1];
271 $.get('show_bug.cgi?id=' + bug_id, function(data) {
273 $(data).find('.bz_comment').each(function() {
274 var author = $(this).find('.email').text();
275 var text = $(this).find('.bz_comment_text').text();
276 var comment_marker = '(From update of attachment ' + attachment_id + ' .details.)';
277 if (text.match(comment_marker))
278 $.merge(comments, scanForComments(author, text));
280 displayPreviousComments(comments);
283 var details = $(data);
284 addFlagsForAttachment(details);
286 var statusBubble = document.createElement('iframe');
287 statusBubble.className = 'statusBubble';
288 statusBubble.src = 'https://webkit-commit-queue.appspot.com/status-bubble/' + attachment_id;
289 statusBubble.scrolling = 'no';
290 // Can't append the HTML because we need to set the onload handler before appending the iframe to the DOM.
291 statusBubble.onload = handleStatusBubbleLoad;
292 $('#statusBubbleContainer').append(statusBubble);
294 $('#toolbar .bugLink').html('<a href="/show_bug.cgi?id=' + bug_id + '" target="_blank">Bug ' + bug_id + '</a>');
298 function crawlDiff() {
299 $('.Line').each(idify).each(hoverify);
300 $('.FileDiff').each(function() {
301 var file_name = $(this).children('h1').text();
302 files[file_name] = this;
303 addExpandLinks(file_name);
307 function addExpandLinks(file_name) {
308 if (file_name.indexOf('ChangeLog') != -1)
311 var file_diff = files[file_name];
313 // Don't show the links to expand upwards/downwards if the patch starts/ends without context
314 // lines, i.e. starts/ends with add/remove lines.
315 var first_line = file_diff.querySelector('.Line');
317 // If there is no element with a "Line" class, then this is an image diff.
321 $('.context', file_diff).detach();
323 var expand_bar_index = 0;
324 if (!$(first_line).hasClass('add') && !$(first_line).hasClass('remove'))
325 $('h1', file_diff).after(expandBarHtml(file_name, BELOW))
327 $('br').replaceWith(expandBarHtml(file_name));
329 var last_line = file_diff.querySelector('.Line:last-of-type');
330 // Some patches for new files somehow end up with an empty context line at the end
331 // with a from line number of 0. Don't show expand links in that case either.
332 if (!$(last_line).hasClass('add') && !$(last_line).hasClass('remove') && fromLineNumber(last_line) != 0)
333 $(file_diff).append(expandBarHtml(file_name, ABOVE));
336 function expandBarHtml(file_name, opt_direction) {
337 var html = '<div class="ExpandBar">' +
338 '<pre class="ExpandArea Expand' + ABOVE + '"></pre>' +
339 '<div class="ExpandLinkContainer"><span class="ExpandText">expand: </span>';
341 // FIXME: If there are <100 line to expand, don't show the expand-100 link.
342 // If there are <20 lines to expand, don't show the expand-20 link.
343 if (!opt_direction || opt_direction == ABOVE) {
344 html += expandLinkHtml(ABOVE, 100) +
345 expandLinkHtml(ABOVE, 20);
348 html += expandLinkHtml(ALL);
350 if (!opt_direction || opt_direction == BELOW) {
351 html += expandLinkHtml(BELOW, 20) +
352 expandLinkHtml(BELOW, 100);
355 html += '</div><pre class="ExpandArea Expand' + BELOW + '"></pre></div>';
359 function expandLinkHtml(direction, amount) {
360 return "<a class='ExpandLink' href='javascript:' data-direction='" + direction + "' data-amount='" + amount + "'>" +
361 (amount ? amount + " " : "") + direction + "</a>";
364 $(window).bind('click', function (e) {
365 var target = e.target;
366 if (target.className != 'ExpandLink')
369 // Can't use $ here because something in the window's scope sets $ to something other than jQuery.
370 var expand_bar = jQuery(target).parents('.ExpandBar');
371 var file_name = expand_bar.parents('.FileDiff').children('h1')[0].textContent;
372 var expand_function = partial(expand, expand_bar[0], file_name, target.getAttribute('data-direction'), Number(target.getAttribute('data-amount')));
373 if (file_name in original_file_contents)
376 getWebKitSourceFile(file_name, expand_function, expand_bar);
379 function getWebKitSourceFile(file_name, onLoad, expand_bar) {
380 function handleLoad(contents) {
381 original_file_contents[file_name] = contents.split('\n');
382 patched_file_contents[file_name] = applyDiff(original_file_contents[file_name], file_name);
387 url: WEBKIT_BASE_DIR + file_name,
388 context: document.body,
389 complete: function(xhr, data) {
391 handleLoadError(expand_bar);
393 handleLoad(xhr.responseText);
398 function replaceExpandLinkContainers(expand_bar, text) {
399 $('.ExpandLinkContainer', $(expand_bar).parents('.FileDiff')).replaceWith('<span class="ExpandText">' + text + '</span>');
402 function handleLoadError(expand_bar) {
403 // FIXME: In this case, try fetching the source file at the revision the patch was created at,
404 // in case the file has bee deleted.
405 // Might need to modify webkit-patch to include that data in the diff.
406 replaceExpandLinkContainers(expand_bar, "Can't expand. Is this a new or deleted file?");
413 function expand(expand_bar, file_name, direction, amount) {
414 if (file_name in original_file_contents && !patched_file_contents[file_name]) {
415 // FIXME: In this case, try fetching the source file at the revision the patch was created at.
416 // Might need to modify webkit-patch to include that data in the diff.
417 replaceExpandLinkContainers(expand_bar, "Can't expand. Unable to apply patch to tip of tree.");
421 var above_expansion = expand_bar.querySelector('.Expand' + ABOVE)
422 var below_expansion = expand_bar.querySelector('.Expand' + BELOW)
424 var above_last_line = above_expansion.querySelector('.ExpansionLine:last-of-type');
425 if (!above_last_line) {
426 var diff_section = expand_bar.previousElementSibling;
427 above_last_line = diff_section.querySelector('.Line:last-of-type');
430 var above_last_line_num, above_last_from_line_num;
431 if (above_last_line) {
432 above_last_line_num = toLineNumber(above_last_line);
433 above_last_from_line_num = fromLineNumber(above_last_line);
435 above_last_from_line_num = above_last_line_num = 0;
437 var below_first_line = below_expansion.querySelector('.ExpansionLine');
438 if (!below_first_line) {
439 var diff_section = expand_bar.nextElementSibling;
441 below_first_line = diff_section.querySelector('.Line');
444 var below_first_line_num, below_first_from_line_num;
445 if (below_first_line) {
446 below_first_line_num = toLineNumber(below_first_line) - 1;
447 below_first_from_line_num = fromLineNumber(below_first_line) - 1;
449 below_first_from_line_num = below_first_line_num = patched_file_contents[file_name].length - 1;
451 var start_line_num, start_from_line_num;
454 if (direction == ABOVE) {
455 start_from_line_num = above_last_from_line_num;
456 start_line_num = above_last_line_num;
457 end_line_num = Math.min(start_line_num + amount, below_first_line_num);
458 } else if (direction == BELOW) {
459 end_line_num = below_first_line_num;
460 start_line_num = Math.max(end_line_num - amount, above_last_line_num)
461 start_from_line_num = Math.max(below_first_from_line_num - amount, above_last_from_line_num)
462 } else { // direction == ALL
463 start_line_num = above_last_line_num;
464 start_from_line_num = above_last_from_line_num;
465 end_line_num = below_first_line_num;
469 // Filling in all the remaining lines. Overwrite the expand links.
470 if (start_line_num == above_last_line_num && end_line_num == below_first_line_num) {
471 expansion_area = expand_bar.querySelector('.ExpandLinkContainer');
472 expansion_area.innerHTML = '';
474 expansion_area = direction == ABOVE ? above_expansion : below_expansion;
477 insertLines(file_name, expansion_area, direction, start_line_num, end_line_num, start_from_line_num);
480 function insertLines(file_name, expansion_area, direction, start_line_num, end_line_num, start_from_line_num) {
481 var fragment = document.createDocumentFragment();
482 for (var i = 0; i < end_line_num - start_line_num; i++) {
483 var line = document.createElement('div');
484 line.className = 'ExpansionLine';
485 // FIXME: from line numbers are wrong
486 line.innerHTML = '<span class="from expansionlineNumber">' + (start_from_line_num + i + 1) +
487 '</span><span class="to expansionlineNumber">' + (start_line_num + i + 1) +
488 '</span> <span class="text"></span>';
489 line.querySelector('.text').textContent = patched_file_contents[file_name][start_line_num + i];
490 fragment.appendChild(line);
493 if (direction == BELOW)
494 expansion_area.insertBefore(fragment, expansion_area.firstChild);
496 expansion_area.appendChild(fragment);
499 function hunkStartingLine(patched_file, context, prev_line, hunk_num) {
501 var current_line = -1;
502 var last_context_line = context[context.length - 1];
503 if (patched_file[prev_line] == last_context_line)
504 current_line = prev_line + 1;
506 for (var i = prev_line - PATCH_FUZZ; i < prev_line + PATCH_FUZZ; i++) {
507 if (patched_file[i] == last_context_line)
508 current_line = i + 1;
511 if (current_line == -1) {
512 console.log('Hunk #' + hunk_num + ' FAILED.');
517 // For paranoia sake, confirm the rest of the context matches;
518 for (var i = 0; i < context.length - 1; i++) {
519 if (patched_file[current_line - context.length + i] != context[i]) {
520 console.log('Hunk #' + hunk_num + ' FAILED. Did not match preceding context.');
528 function fromLineNumber(line) {
529 return Number(line.querySelector('.from').textContent);
532 function toLineNumber(line) {
533 return Number(line.querySelector('.to').textContent);
536 function lineNumberForFirstNonContextLine(patched_file, line, prev_line, context, hunk_num) {
537 if (context.length) {
538 var prev_line_num = fromLineNumber(prev_line) - 1;
539 return hunkStartingLine(patched_file, context, prev_line_num, hunk_num);
542 if (toLineNumber(line) == 1 || fromLineNumber(line) == 1)
545 console.log('Failed to apply patch. Adds or removes lines before any context lines.');
549 function applyDiff(original_file, file_name) {
550 var diff_sections = files[file_name].getElementsByClassName('DiffSection');
551 var patched_file = original_file.concat([]);
553 // Apply diffs in reverse order to avoid needing to keep track of changing line numbers.
554 for (var i = diff_sections.length - 1; i >= 0; i--) {
555 var section = diff_sections[i];
556 var lines = section.getElementsByClassName('Line');
557 var current_line = -1;
559 var hunk_num = i + 1;
561 for (var j = 0, lines_len = lines.length; j < lines_len; j++) {
563 var line_contents = line.querySelector('.text').textContent;
564 if ($(line).hasClass('add')) {
565 if (current_line == -1) {
566 current_line = lineNumberForFirstNonContextLine(patched_file, line, lines[j-1], context, hunk_num);
567 if (current_line == -1)
571 patched_file.splice(current_line, 0, line_contents);
573 } else if ($(line).hasClass('remove')) {
574 if (current_line == -1) {
575 current_line = lineNumberForFirstNonContextLine(patched_file, line, lines[j-1], context, hunk_num);
576 if (current_line == -1)
580 if (patched_file[current_line] != line_contents) {
581 console.log('Hunk #' + hunk_num + ' FAILED.');
585 patched_file.splice(current_line, 1);
586 } else if (current_line == -1) {
587 context.push(line_contents);
588 } else if (line_contents != patched_file[current_line]) {
589 console.log('Hunk #' + hunk_num + ' FAILED. Context at end did not match');
600 function openOverallComments(e) {
601 $('.overallComments textarea').addClass('open');
602 $('#statusBubbleContainer').addClass('wrap');
605 $(document).ready(function() {
608 $(document.body).prepend('<div id="message"><div class="help">Select line numbers to add a comment.</div><div class="commentStatus"></div></div>');
609 $(document.body).prepend('<div id="toolbar">' +
610 '<div class="overallComments">' +
611 '<textarea placeholder="Overall comments"></textarea>' +
614 '<span id="statusBubbleContainer"></span>' +
615 '<span class="actions">' +
616 '<span class="links"><span class="bugLink"></span></span>' +
617 '<span id="flagContainer"></span>' +
618 '<button id="preview_comments">Preview</button>' +
619 '<button id="post_comments">Publish</button> ' +
624 $('.overallComments textarea').bind('click', openOverallComments);
626 $(document.body).prepend('<div id="comment_form" class="inactive"><div class="winter"></div><div class="lightbox"><iframe id="reviewform" src="attachment.cgi?id=' + attachment_id + '&action=reviewform"></iframe></div></div>');
629 function discardComment() {
630 var line_id = $(this).parentsUntil('.comment').parent().find('textarea').attr('data-comment-for');
631 var line = $('#' + line_id)
632 findCommentBlockFor(line).slideUp('fast', function() {
634 line.removeAttr('data-has-comment');
635 trimCommentContextToBefore(line);
639 function unfreezeComment() {
640 $(this).prev().show();
644 $('.comment .discard').live('click', discardComment);
646 $('.comment .ok').live('click', function() {
647 var comment_textarea = $(this).parentsUntil('.comment').parent().find('textarea');
648 if (comment_textarea.val().trim() == '') {
649 discardComment.call(this);
652 var line_id = comment_textarea.attr('data-comment-for');
653 var line = $('#' + line_id)
654 findCommentBlockFor(line).hide().after($('<div class="frozenComment"></div>').text(comment_textarea.val()));
657 $('.frozenComment').live('click', unfreezeComment);
659 function focusOn(comment) {
660 $('.focused').removeClass('focused');
661 if (comment.length == 0)
663 $(document).scrollTop(comment.addClass('focused').position().top - window.innerHeight/2);
666 function focusNextComment() {
667 var comments = $('.previousComment');
668 if (comments.length == 0)
670 var index = comments.index($('.focused'));
671 // Notice that -1 gets mapped to 0.
672 focusOn($(comments.get(index + 1)));
675 function focusPreviousComment() {
676 var comments = $('.previousComment');
677 if (comments.length == 0)
679 var index = comments.index($('.focused'));
681 index = comments.length;
686 focusOn($(comments.get(index - 1)));
689 var kCharCodeForN = 'n'.charCodeAt(0);
690 var kCharCodeForP = 'p'.charCodeAt(0);
692 $('body').live('keypress', function() {
693 // FIXME: There's got to be a better way to avoid seeing these keypress
695 if (event.target.nodeName == 'TEXTAREA')
697 if (event.charCode == kCharCodeForN)
699 else if (event.charCode == kCharCodeForP)
700 focusPreviousComment();
703 function contextLinesFor(line) {
705 while (line.hasClass('commentContext')) {
706 $.merge(context, line);
709 return $(context.reverse());
712 function trimCommentContextToBefore(line) {
713 while (line.hasClass('commentContext') && line.attr('data-has-comment') != 'true') {
714 line.removeClass('commentContext');
719 var in_drag_select = false;
721 function stopDragSelect() {
722 $('.selected').removeClass('selected');
723 in_drag_select = false;
726 $('.lineNumber').live('click', function() {
727 var line = $(this).parent();
728 if (line.hasClass('commentContext'))
729 trimCommentContextToBefore(line.prev());
730 }).live('mousedown', function() {
731 in_drag_select = true;
732 $(this).parent().addClass('selected');
733 event.preventDefault();
736 $('.Line').live('mouseenter', function() {
740 var before = $(this).prevUntil('.selected')
741 if (before.prev().hasClass('selected'))
742 before.addClass('selected');
744 var after = $(this).nextUntil('.selected')
745 if (after.next().hasClass('selected'))
746 after.addClass('selected');
748 $(this).addClass('selected');
749 }).live('mouseup', function() {
752 var selected = $('.selected');
753 var should_add_comment = !selected.last().next().hasClass('commentContext');
754 selected.addClass('commentContext');
755 if (should_add_comment)
756 addCommentFor(selected.last());
759 $('.DiffSection').live('mouseleave', stopDragSelect).live('mouseup', stopDragSelect);
761 function contextSnippetFor(line, indent) {
763 contextLinesFor(line).each(function() {
765 if ($(this).hasClass('add'))
767 else if ($(this).hasClass('remove'))
769 var text = $(this).children('.text').text();
770 snippets.push(indent + action + text);
772 return snippets.join('\n');
775 function fileNameFor(line) {
776 return line.parentsUntil('.FileDiff').parent().find('h1').text();
779 function indentFor(depth) {
780 return (new Array(depth + 1)).join('>') + ' ';
783 function snippetFor(line, indent) {
784 var file_name = fileNameFor(line);
785 var line_number = line.hasClass('remove') ? '-' + line.children('.from').text() : line.children('.to').text();
786 return indent + file_name + ':' + line_number + '\n' + contextSnippetFor(line, indent);
789 function quotePreviousComments(comments) {
790 var quoted_comments = [];
791 var depth = comments.size();
792 comments.each(function() {
793 var indent = indentFor(depth--);
794 var text = $(this).children('.content').text();
795 quoted_comments.push(indent + '\n' + indent + text.split('\n').join('\n' + indent));
797 return quoted_comments.join('\n');
800 $('#comment_form .winter').live('click', function() {
801 $('#comment_form').addClass('inactive');
804 function fillInReviewForm() {
805 var comments_in_context = []
806 forEachLine(function(line) {
807 if (line.attr('data-has-comment') != 'true')
809 var comment = findCommentBlockFor(line).children('textarea').val().trim();
812 var previous_comments = previousCommentsFor(line);
813 var snippet = snippetFor(line, indentFor(previous_comments.size() + 1));
814 var quoted_comments = quotePreviousComments(previous_comments);
815 var comment_with_context = [];
816 comment_with_context.push(snippet);
817 if (quoted_comments != '')
818 comment_with_context.push(quoted_comments);
819 comment_with_context.push('\n' + comment);
820 comments_in_context.push(comment_with_context.join('\n'));
822 var comment = $('.overallComments textarea').val().trim();
825 comment += comments_in_context.join('\n\n');
826 if (comments_in_context.length > 0)
827 comment = 'View in context: ' + window.location + '\n\n' + comment;
828 var review_form = $('#reviewform').contents();
829 review_form.find('#comment').val(comment);
830 review_form.find('#flags select').each(function() {
831 var control = findControlForFlag(this);
834 $(this).attr('selectedIndex', control.attr('selectedIndex'));
838 $('#preview_comments').live('click', function() {
840 $('#comment_form').removeClass('inactive');
843 $('#post_comments').live('click', function() {
845 $('#reviewform').contents().find('form').submit();