summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2016-10-25 01:27:21 -0500
committerMike Greiling <mike@pixelcog.com>2016-12-02 17:32:37 -0600
commit6c978994e1daf25da87d8b2cb6d8f1954022241f (patch)
treed8a6043add1a2ebb293bdabecb7a07e322c49c83
parent2de245c7bad211cd85a4a23f9110aac82f2bb0a2 (diff)
downloadgitlab-ce-6c978994e1daf25da87d8b2cb6d8f1954022241f.tar.gz
fix diff line highlighting by moving method from the MergeRequestTabs class to the Diff class.
-rw-r--r--app/assets/javascripts/diff.js44
-rw-r--r--app/assets/javascripts/merge_request_tabs.js46
2 files changed, 48 insertions, 42 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;
})();
diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js
index 907f8f924d2..d34fc4bc87c 100644
--- a/app/assets/javascripts/merge_request_tabs.js
+++ b/app/assets/javascripts/merge_request_tabs.js
@@ -76,14 +76,16 @@
}
MergeRequestTabs.prototype.bindEvents = function() {
- $(document).on('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown);
- $(document).on('click', '.js-show-tab', this.showTab);
- };
+ $(document)
+ .on('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown)
+ .on('click', '.js-show-tab', this.showTab);
+ }
MergeRequestTabs.prototype.unbindEvents = function() {
- $(document).off('shown.bs.tab', '.merge-request-tabs a[data-toggle="tab"]', this.tabShown);
- $(document).off('click', '.js-show-tab', this.showTab);
- };
+ $(document)
+ .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) {
event.preventDefault();
@@ -235,45 +237,19 @@
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'));
$('#diffs .js-syntax-highlight').syntaxHighlight();
- $('#diffs .diff-file').singleFileDiff();
+
if (_this.diffViewType() === 'parallel' && (_this.isDiffAction(_this.currentAction)) ) {
_this.expandViewContainer();
}
_this.diffsLoaded = true;
_this.scrollToElement("#diffs");
- _this.highlighSelectedLine();
- _this.filesCommentButton = $('.files .diff-file').filesCommentButton();
- 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");
- });
+
+ new Diff();
};
})(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) {
if (this.buildsLoaded) {
return;