Commit 6c978994 authored by Mike Greiling's avatar Mike Greiling

fix diff line highlighting by moving method from the MergeRequestTabs class to the Diff class.

parent 2de245c7
...@@ -11,21 +11,21 @@ ...@@ -11,21 +11,21 @@
if (this.diffViewType() === 'parallel') { if (this.diffViewType() === 'parallel') {
$('.content-wrapper .container-fluid').removeClass('container-limited'); $('.content-wrapper .container-fluid').removeClass('container-limited');
} }
$(document).off('click', '.js-unfold'); $(document)
$(document).on('click', '.js-unfold', (function(_this) { .off('click', '.js-unfold')
return function(event) { .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; 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); target = $(event.target);
unfoldBottom = target.hasClass('js-unfold-bottom'); unfoldBottom = target.hasClass('js-unfold-bottom');
unfold = true; 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; offset = line_number - old_line;
if (unfoldBottom) { if (unfoldBottom) {
line_number += 1; line_number += 1;
since = line_number; since = line_number;
to = line_number + UNFOLD_COUNT; to = line_number + UNFOLD_COUNT;
} else { } 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; line_number -= 1;
to = line_number; to = line_number;
if (line_number - UNFOLD_COUNT > prev_new_line + 1) { if (line_number - UNFOLD_COUNT > prev_new_line + 1) {
...@@ -48,8 +48,22 @@ ...@@ -48,8 +48,22 @@
return $.get(link, params, function(response) { return $.get(link, params, function(response) {
return target.parent().replaceWith(response); return target.parent().replaceWith(response);
}); });
}; }).bind(this));
})(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() { Diff.prototype.diffViewType = function() {
...@@ -66,6 +80,22 @@ ...@@ -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; return Diff;
})(); })();
......
...@@ -76,14 +76,16 @@ ...@@ -76,14 +76,16 @@
} }
MergeRequestTabs.prototype.bindEvents = function() { MergeRequestTabs.prototype.bindEvents = function() {
$(document).on('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown); $(document)
$(document).on('click', '.js-show-tab', this.showTab); .on('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown)
}; .on('click', '.js-show-tab', this.showTab);
}
MergeRequestTabs.prototype.unbindEvents = function() { MergeRequestTabs.prototype.unbindEvents = function() {
$(document).off('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown); $(document)
$(document).off('click', '.js-show-tab', this.showTab); .off('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown)
}; .off('click', '.js-show-tab', this.showTab);
}
MergeRequestTabs.prototype.showTab = function(event) { MergeRequestTabs.prototype.showTab = function(event) {
event.preventDefault(); event.preventDefault();
...@@ -235,45 +237,19 @@ ...@@ -235,45 +237,19 @@
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs')); gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'));
$('#diffs .js-syntax-highlight').syntaxHighlight(); $('#diffs .js-syntax-highlight').syntaxHighlight();
$('#diffs .diff-file').singleFileDiff();
if (_this.diffViewType() === 'parallel' && (_this.isDiffAction(_this.currentAction)) ) { if (_this.diffViewType() === 'parallel' && (_this.isDiffAction(_this.currentAction)) ) {
_this.expandViewContainer(); _this.expandViewContainer();
} }
_this.diffsLoaded = true; _this.diffsLoaded = true;
_this.scrollToElement("#diffs"); _this.scrollToElement("#diffs");
_this.highlighSelectedLine();
_this.filesCommentButton = $('.files .diff-file').filesCommentButton(); new Diff();
return $(document).off('click', '.diff-line-num a').on('click', '.diff-line-num a', function(e) {
e.preventDefault();
window.location.hash = $(e.currentTarget).attr('href');
_this.highlighSelectedLine();
return _this.scrollToElement("#diffs");
});
}; };
})(this) })(this)
}); });
}; };
MergeRequestTabs.prototype.highlighSelectedLine = function() {
var $diffLine, diffLineTop, hashClassString, locationHash, navBarHeight;
$('.hll').removeClass('hll');
locationHash = window.location.hash;
if (locationHash !== '') {
dataLineString = '[data-line-code="' + locationHash.replace('#', '') + '"]';
$diffLine = $(locationHash + ":not(.match)", $('#diffs'));
if (!$diffLine.is('tr')) {
$diffLine = $('#diffs').find("td" + locationHash + ", td" + dataLineString);
} else {
$diffLine = $diffLine.find('td');
}
if ($diffLine.length) {
$diffLine.addClass('hll');
diffLineTop = $diffLine.offset().top;
return navBarHeight = $('.navbar-gitlab').outerHeight();
}
}
};
MergeRequestTabs.prototype.loadBuilds = function(source) { MergeRequestTabs.prototype.loadBuilds = function(source) {
if (this.buildsLoaded) { if (this.buildsLoaded) {
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment