diff options
author | Johan Sørensen <johan@johansorensen.com> | 2009-10-29 13:15:21 +0100 |
---|---|---|
committer | Johan Sørensen <johan@johansorensen.com> | 2009-11-04 15:23:44 +0100 |
commit | ddd8531a039db5d1b8efd9078ada80d93ce7d4ba (patch) | |
tree | 9cfb393316c3638c717e7d8bc849560565cb7482 /public/javascripts/diff_browser.js | |
parent | 28de6ca4d67ea07a7f597f72132533fbecc2bcdb (diff) | |
download | gitorious-mainline-outdated-ddd8531a039db5d1b8efd9078ada80d93ce7d4ba.zip gitorious-mainline-outdated-ddd8531a039db5d1b8efd9078ada80d93ce7d4ba.tar.gz gitorious-mainline-outdated-ddd8531a039db5d1b8efd9078ada80d93ce7d4ba.tar.bz2 |
Extract the inline-diff comment diff context when the comment is created
instead of extracting it on the client side each time the page is
loaded, we load it into Comment#context when saving the comment. This
both saves us from some heavy DOM traversing and makes the diff
context stick when viewing comments from another merge request version
Diffstat (limited to 'public/javascripts/diff_browser.js')
-rw-r--r-- | public/javascripts/diff_browser.js | 58 |
1 files changed, 22 insertions, 36 deletions
diff --git a/public/javascripts/diff_browser.js b/public/javascripts/diff_browser.js index aded1d0..ae94130 100644 --- a/public/javascripts/diff_browser.js +++ b/public/javascripts/diff_browser.js @@ -592,39 +592,6 @@ NotificationCenter.addObserver("DiffBrowserDidReloadDiffs", Gitorious, NotificationCenter.addObserver("DiffBrowserWillReloadDiffs", Gitorious, Gitorious.disableCommenting); - -Gitorious.DiffBrowser.insertDiffContextsIntoComments = function() { - // Extract the affected diffs and insert them above the comment it - // belongs to - var idiffRegexp = /(<span class="idiff">|<\/span>)/gmi; - var comments = $("#merge_request_comments .comment.inline .inline_comment_link a"); - for (var i=0; i < comments.length; i++) { - var commentElement = $( $(comments[i]).attr("href") ); - if (commentElement.length === 0) - continue; - var selectors = $.map(commentElement.attr("gts:lines").split(","), function(e) { - return "table.codediff.inline tr.line-" + e; - }); - // extract the raw diff data from each row - var plainDiff = []; - $(selectors.join(",")).each(function() { - var cell = $(this).find("td.code"); - var op = "> " + (cell.hasClass("ins") ? "+ " : "- "); - plainDiff.push(op + cell.find(".diff-content").html().replace(idiffRegexp, '')); - }); - if ($(comments[i]).parents(".comment.inline").find(".diff-comment-context").length > 0) { - // We have already added this context, move on - continue; - } - $(comments[i]).parents(".comment.inline") - .prepend('<pre class="diff-comment-context"><code>' + - plainDiff.join("\n") + '</code></pre'); - }; -}; - -NotificationCenter.addObserver("DiffBrowserDidReloadDiffs", Gitorious.DiffBrowser, - Gitorious.DiffBrowser.insertDiffContextsIntoComments); - Gitorious.CommentForm = function(path){ this.path = path; this.numbers = []; @@ -657,6 +624,7 @@ Gitorious.CommentForm = function(path){ var shas = $("#current_shas").attr("data-merge-request-current-shas"); commentContainer.find("#comment_sha1").val(shas); commentContainer.find("#comment_path").val(this.path); + commentContainer.find("#comment_context").val(this._getRawDiffContext()); commentContainer.find(".cancel_button").click(Gitorious.CommentForm.destroyAll); commentContainer.find("#comment_lines").val(this.linesAsString()); this._positionAndShowContainer(commentContainer, options.trigger); @@ -701,12 +669,30 @@ Gitorious.CommentForm = function(path){ }; container.css(cssData); container.slideDown(); - } -} + }; + + this._getRawDiffContext = function() { + // Extract the affected diffs (as raw quoted diffs) and return them + var idiffRegexp = /(<span class="idiff">|<\/span>)/gmi; + var comments = $("#merge_request_comments .comment.inline .inline_comment_link a"); + var plainDiff = []; + var selectors = $.map(this.numbers, function(e) { + return "table.codediff.inline tr.line-" + e; + }); + // extract the raw diff data from each row + $(selectors.join(",")).each(function() { + var cell = $(this).find("td.code"); + var op = "> " + (cell.hasClass("ins") ? "+ " : "- "); + plainDiff.push(op + cell.find(".diff-content").html().replace(idiffRegexp, '') + .replace('>', '>').replace('<', '<')); + }); + return (plainDiff.length > 0 ? plainDiff.join("\n") : ""); + }; +}; Gitorious.CommentForm.destroyAll = function() { $(".comment_container").html("").unbind("keypress").slideUp("fast"); $(".selected-for-commenting").removeClass("selected-for-commenting"); $(".ui-selected").removeClass("ui-selected"); Gitorious.DiffBrowser.KeyNavigation.enable(); -} +}; |