gitlab-org--gitlab-foss/app/assets/javascripts/diff.js

74 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-11-15 14:08:06 +00:00
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, max-len, one-var, camelcase, one-var-declaration-per-line, no-unused-vars, no-unused-expressions, no-sequences, object-shorthand, comma-dangle, prefer-arrow-callback, semi, radix, padded-blocks, max-len */
2016-07-24 20:45:11 +00:00
(function() {
this.Diff = (function() {
var UNFOLD_COUNT;
UNFOLD_COUNT = 20;
function Diff() {
$('.files .diff-file').singleFileDiff();
this.filesCommentButton = $('.files .diff-file').filesCommentButton();
if (this.diffViewType() === 'parallel') {
$('.content-wrapper .container-fluid').removeClass('container-limited');
}
2016-07-24 20:45:11 +00:00
$(document).off('click', '.js-unfold');
$(document).on('click', '.js-unfold', (function(_this) {
return function(event) {
2016-07-21 18:44:12 +00:00
var line_number, link, file, offset, old_line, params, prev_new_line, prev_old_line, ref, ref1, since, target, to, unfold, unfoldBottom;
2016-07-24 20:45:11 +00:00
target = $(event.target);
unfoldBottom = target.hasClass('js-unfold-bottom');
unfold = true;
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];
line_number -= 1;
to = line_number;
if (line_number - UNFOLD_COUNT > prev_new_line + 1) {
since = line_number - UNFOLD_COUNT;
} else {
since = prev_new_line + 1;
unfold = false;
}
}
2016-07-21 18:44:12 +00:00
file = target.parents('.diff-file');
link = file.data('blob-diff-path');
2016-07-24 20:45:11 +00:00
params = {
since: since,
to: to,
bottom: unfoldBottom,
offset: offset,
unfold: unfold,
2016-07-21 18:44:12 +00:00
view: file.data('view')
2016-07-24 20:45:11 +00:00
};
return $.get(link, params, function(response) {
return target.parent().replaceWith(response);
});
};
})(this));
}
Diff.prototype.diffViewType = function() {
return $('.inline-parallel-buttons a.active').data('view-type');
}
2016-07-24 20:45:11 +00:00
Diff.prototype.lineNumbers = function(line) {
if (!line.children().length) {
return [0, 0];
}
2016-07-21 18:44:12 +00:00
return line.find('.diff-line-num').map(function() {
return parseInt($(this).data('linenumber'));
});
2016-07-24 20:45:11 +00:00
};
return Diff;
})();
}).call(this);