From bea83d2579ca3b8ca48802f5c114cea60bce396e Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Thu, 27 Oct 2016 10:47:14 +0900 Subject: Remove an extra leading space from diff content --- app/assets/javascripts/diff.js | 4 ---- 1 file changed, 4 deletions(-) (limited to 'app/assets/javascripts/diff.js') diff --git a/app/assets/javascripts/diff.js b/app/assets/javascripts/diff.js index 4ddafff428f..82bfdcea0ca 100644 --- a/app/assets/javascripts/diff.js +++ b/app/assets/javascripts/diff.js @@ -43,10 +43,6 @@ bottom: unfoldBottom, offset: offset, unfold: unfold, - // indent is used to compensate for single space indent to fit - // '+' and '-' prepended to diff lines, - // see https://gitlab.com/gitlab-org/gitlab-ce/issues/707 - indent: 1, view: file.data('view') }; return $.get(link, params, function(response) { -- cgit v1.2.1 From 7cefaea876da9e25a1c3ea870f4e4b070a196905 Mon Sep 17 00:00:00 2001 From: "Luke \"Jared\" Bennett" Date: Tue, 15 Nov 2016 14:08:06 +0000 Subject: explicitly disable eslint inline --- app/assets/javascripts/diff.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/assets/javascripts/diff.js') diff --git a/app/assets/javascripts/diff.js b/app/assets/javascripts/diff.js index 82bfdcea0ca..00da5f17f9f 100644 --- a/app/assets/javascripts/diff.js +++ b/app/assets/javascripts/diff.js @@ -1,4 +1,4 @@ -/* eslint-disable */ +/* 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 */ (function() { this.Diff = (function() { var UNFOLD_COUNT; -- cgit v1.2.1 From 6c978994e1daf25da87d8b2cb6d8f1954022241f Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Tue, 25 Oct 2016 01:27:21 -0500 Subject: fix diff line highlighting by moving method from the MergeRequestTabs class to the Diff class. --- app/assets/javascripts/diff.js | 44 +++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) (limited to 'app/assets/javascripts/diff.js') 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; })(); -- cgit v1.2.1 From 4f107f3fc4333fe2234fac1bf1247164542484a2 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Tue, 25 Oct 2016 14:25:46 -0500 Subject: refactor Diff to es6 class syntax --- app/assets/javascripts/diff.js | 103 ----------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 app/assets/javascripts/diff.js (limited to 'app/assets/javascripts/diff.js') diff --git a/app/assets/javascripts/diff.js b/app/assets/javascripts/diff.js deleted file mode 100644 index 66580587629..00000000000 --- a/app/assets/javascripts/diff.js +++ /dev/null @@ -1,103 +0,0 @@ -/* 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 */ -(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'); - } - $(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]; - 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; - } - } - file = target.parents('.diff-file'); - link = file.data('blob-diff-path'); - params = { - since: since, - to: to, - bottom: unfoldBottom, - offset: offset, - unfold: unfold, - view: file.data('view') - }; - return $.get(link, params, function(response) { - return target.parent().replaceWith(response); - }); - }).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() { - return $('.inline-parallel-buttons a.active').data('view-type'); - } - - Diff.prototype.lineNumbers = function(line) { - if (!line.children().length) { - return [0, 0]; - } - - return line.find('.diff-line-num').map(function() { - return parseInt($(this).data('linenumber')); - }); - }; - - 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; - - })(); - -}).call(this); -- cgit v1.2.1