diff --git a/templates/repo_view_file.html b/templates/repo_view_file.html
index 8cc1449f2c..662e12f0b6 100644
--- a/templates/repo_view_file.html
+++ b/templates/repo_view_file.html
@@ -279,6 +279,12 @@ $('#comment').click(function() {
$('#file-comment, #comment-caret').addClass('hide');
}
});
+$(document).click(function(e) {
+ var target = e.target || event.srcElement;
+ if (target != $('#comment')[0] && target != $('#file-comment')[0] && target != $('#comment-caret')[0] && !($('#file-comment, #comment-caret').find('*').is(target))) {
+ $('#file-comment, #comment-caret').addClass('hide');
+ }
+});
var comment_input_pre_text = $('#comment-input').val();
$('#comment-input').css('color', '#999').click(function() {