Commit 1d3b7768 authored by Mike Greiling's avatar Mike Greiling

refactor Diff class event bindings

parent 4f107f3f
...@@ -11,58 +11,58 @@ ...@@ -11,58 +11,58 @@
if (this.diffViewType() === 'parallel') { if (this.diffViewType() === 'parallel') {
$('.content-wrapper .container-fluid').removeClass('container-limited'); $('.content-wrapper .container-fluid').removeClass('container-limited');
} }
$(document) $(document)
.off('click', '.js-unfold') .off('click', '.js-unfold, .diff-line-num a')
.on('click', '.js-unfold', (event) => { .on('click', '.js-unfold', this.handleClickUnfold.bind(this))
var line_number, link, file, offset, old_line, params, prev_new_line, prev_old_line, ref, ref1, since, target, to, unfold, unfoldBottom; .on('click', '.diff-line-num a', this.handleClickLineNum.bind(this));
target = $(event.target);
unfoldBottom = target.hasClass('js-unfold-bottom'); this.highlighSelectedLine();
unfold = true; }
ref = this.lineNumbers(target.parent()), old_line = ref[0], line_number = ref[1];
offset = line_number - old_line; handleClickUnfold(event) {
if (unfoldBottom) { const $target = $(event.target);
line_number += 1; const [oldLineNumber, newLineNumber] = this.lineNumbers($target.parent());
since = line_number; const offset = newLineNumber - oldLineNumber;
to = line_number + UNFOLD_COUNT; const bottom = $target.hasClass('js-unfold-bottom');
} else { let since, to;
ref1 = this.lineNumbers(target.parent().prev()), prev_old_line = ref1[0], prev_new_line = ref1[1]; let unfold = true;
line_number -= 1;
to = line_number; if (bottom) {
if (line_number - UNFOLD_COUNT > prev_new_line + 1) { const lineNumber = newLineNumber + 1;
since = line_number - UNFOLD_COUNT; since = lineNumber;
to = lineNumber + UNFOLD_COUNT;
} else { } else {
since = prev_new_line + 1; const lineNumber = newLineNumber - 1;
since = lineNumber - UNFOLD_COUNT;
to = lineNumber;
// make sure we aren't loading more than we need
const [prevOldLine, prevNewLine] = this.lineNumbers($target.parent().prev());
if (since <= prevNewLine + 1) {
since = prevNewLine + 1;
unfold = false; unfold = false;
} }
} }
file = target.parents('.diff-file');
link = file.data('blob-diff-path'); const file = $target.parents('.diff-file');
params = { const link = file.data('blob-diff-path');
since: since, const view = file.data('view');
to: to,
bottom: unfoldBottom, const params = { since, to, bottom, offset, unfold, view };
offset: offset, $.get(link, params, (response) => $target.parent().replaceWith(response));
unfold: unfold, }
view: file.data('view')
}; handleClickLineNum(event) {
return $.get(link, params, function(response) { const hash = $(event.currentTarget).attr('href');
return target.parent().replaceWith(response);
});
})
.off('click', '.diff-line-num a')
.on('click', '.diff-line-num a', (event) => {
var hash = $(event.currentTarget).attr('href');
event.preventDefault(); event.preventDefault();
if ( history.pushState ) { if (history.pushState) {
history.pushState(null, null, hash); history.pushState(null, null, hash);
} else { } else {
window.location.hash = hash; window.location.hash = hash;
} }
this.highlighSelectedLine(); this.highlighSelectedLine();
}); };
this.highlighSelectedLine();
}
diffViewType() { diffViewType() {
return $('.inline-parallel-buttons a.active').data('view-type'); return $('.inline-parallel-buttons a.active').data('view-type');
......
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