Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-10-25 09:27:21 +0300
committerMike Greiling <mike@pixelcog.com>2016-12-03 02:32:37 +0300
commit6c978994e1daf25da87d8b2cb6d8f1954022241f (patch)
treed8a6043add1a2ebb293bdabecb7a07e322c49c83 /app/assets/javascripts/diff.js
parent2de245c7bad211cd85a4a23f9110aac82f2bb0a2 (diff)
fix diff line highlighting by moving method from the MergeRequestTabs class to the Diff class.
Diffstat (limited to 'app/assets/javascripts/diff.js')
-rw-r--r--app/assets/javascripts/diff.js44
1 files changed, 37 insertions, 7 deletions
diff --git a/app/assets/javascripts/diff.js b/app/assets/javascripts/diff.js
index 00da5f17f9f..66580587629 100644
--- a/app/assets/javascripts/diff.js
+++ b/app/assets/javascripts/diff.js
@@ -11,21 +11,21 @@
if (this.diffViewType() === 'parallel') {
$('.content-wrapper .container-fluid').removeClass('container-limited');
}
- $(document).off('click', '.js-unfold');
- $(document).on('click', '.js-unfold', (function(_this) {
- return function(event) {
+ $(document)
+ .off('click', '.js-unfold')
+ .on('click', '.js-unfold', (function(event) {
var line_number, link, file, offset, old_line, params, prev_new_line, prev_old_line, ref, ref1, since, target, to, unfold, unfoldBottom;
target = $(event.target);
unfoldBottom = target.hasClass('js-unfold-bottom');
unfold = true;
- ref = _this.lineNumbers(target.parent()), old_line = ref[0], line_number = ref[1];
+ ref = this.lineNumbers(target.parent()), old_line = ref[0], line_number = ref[1];
offset = line_number - old_line;
if (unfoldBottom) {
line_number += 1;
since = line_number;
to = line_number + UNFOLD_COUNT;
} else {
- ref1 = _this.lineNumbers(target.parent().prev()), prev_old_line = ref1[0], prev_new_line = ref1[1];
+ ref1 = this.lineNumbers(target.parent().prev()), prev_old_line = ref1[0], prev_new_line = ref1[1];
line_number -= 1;
to = line_number;
if (line_number - UNFOLD_COUNT > prev_new_line + 1) {
@@ -48,8 +48,22 @@
return $.get(link, params, function(response) {
return target.parent().replaceWith(response);
});
- };
- })(this));
+ }).bind(this));
+
+ $(document)
+ .off('click', '.diff-line-num a')
+ .on('click', '.diff-line-num a', (function(e) {
+ var hash = $(e.currentTarget).attr('href');
+ e.preventDefault();
+ if ( history.pushState ) {
+ history.pushState(null, null, hash);
+ } else {
+ window.location.hash = hash;
+ }
+ this.highlighSelectedLine();
+ }).bind(this));
+
+ this.highlighSelectedLine();
}
Diff.prototype.diffViewType = function() {
@@ -66,6 +80,22 @@
});
};
+ Diff.prototype.highlighSelectedLine = function() {
+ var $diffLine, dataLineString, locationHash;
+ $('.hll').removeClass('hll');
+ locationHash = window.location.hash;
+ if (locationHash !== '') {
+ dataLineString = '[data-line-code="' + locationHash.replace('#', '') + '"]';
+ $diffLine = $(".diff-file " + locationHash + ":not(.match)");
+ if (!$diffLine.is('tr')) {
+ $diffLine = $(".diff-file td" + locationHash + ", .diff-file td" + dataLineString);
+ } else {
+ $diffLine = $diffLine.find('td');
+ }
+ $diffLine.addClass('hll');
+ }
+ };
+
return Diff;
})();