Commit cf347a57 authored by Filipa Lacerda's avatar Filipa Lacerda

Remove Diff class from globalnamespace

parent 00c15cc2
/* eslint-disable class-methods-use-this */
import './lib/utils/url_utility'; import './lib/utils/url_utility';
import FilesCommentButton from './files_comment_button'; import FilesCommentButton from './files_comment_button';
import SingleFileDiff from './single_file_diff'; import SingleFileDiff from './single_file_diff';
...@@ -8,7 +6,7 @@ import imageDiffHelper from './image_diff/helpers/index'; ...@@ -8,7 +6,7 @@ import imageDiffHelper from './image_diff/helpers/index';
const UNFOLD_COUNT = 20; const UNFOLD_COUNT = 20;
let isBound = false; let isBound = false;
class Diff { export default class Diff {
constructor() { constructor() {
const $diffFile = $('.files .diff-file'); const $diffFile = $('.files .diff-file');
...@@ -104,7 +102,7 @@ class Diff { ...@@ -104,7 +102,7 @@ class Diff {
} }
this.highlightSelectedLine(); this.highlightSelectedLine();
} }
// eslint-disable-next-line class-methods-use-this
handleParallelLineDown(e) { handleParallelLineDown(e) {
const line = $(e.currentTarget); const line = $(e.currentTarget);
const table = line.closest('table'); const table = line.closest('table');
...@@ -116,11 +114,11 @@ class Diff { ...@@ -116,11 +114,11 @@ class Diff {
table.addClass(`${lineClass}-selected`); table.addClass(`${lineClass}-selected`);
} }
} }
// eslint-disable-next-line class-methods-use-this
diffViewType() { diffViewType() {
return $('.inline-parallel-buttons a.active').data('view-type'); return $('.inline-parallel-buttons a.active').data('view-type');
} }
// eslint-disable-next-line class-methods-use-this
lineNumbers(line) { lineNumbers(line) {
const children = line.find('.diff-line-num').toArray(); const children = line.find('.diff-line-num').toArray();
if (children.length !== 2) { if (children.length !== 2) {
...@@ -128,7 +126,7 @@ class Diff { ...@@ -128,7 +126,7 @@ class Diff {
} }
return children.map(elm => parseInt($(elm).data('linenumber'), 10) || 0); return children.map(elm => parseInt($(elm).data('linenumber'), 10) || 0);
} }
// eslint-disable-next-line class-methods-use-this
highlightSelectedLine() { highlightSelectedLine() {
const hash = gl.utils.getLocationHash(); const hash = gl.utils.getLocationHash();
const $diffFiles = $('.diff-file'); const $diffFiles = $('.diff-file');
...@@ -141,6 +139,3 @@ class Diff { ...@@ -141,6 +139,3 @@ class Diff {
} }
} }
} }
window.gl = window.gl || {};
window.gl.Diff = Diff;
...@@ -87,6 +87,7 @@ import U2FAuthenticate from './u2f/authenticate'; ...@@ -87,6 +87,7 @@ import U2FAuthenticate from './u2f/authenticate';
import Members from './members'; import Members from './members';
import memberExpirationDate from './member_expiration_date'; import memberExpirationDate from './member_expiration_date';
import DueDateSelectors from './due_date_select'; import DueDateSelectors from './due_date_select';
import Diff from './diff';
(function() { (function() {
var Dispatcher; var Dispatcher;
...@@ -237,7 +238,7 @@ import DueDateSelectors from './due_date_select'; ...@@ -237,7 +238,7 @@ import DueDateSelectors from './due_date_select';
new GLForm($('.milestone-form'), true); new GLForm($('.milestone-form'), true);
break; break;
case 'projects:compare:show': case 'projects:compare:show':
new gl.Diff(); new Diff();
initChangesDropdown(); initChangesDropdown();
break; break;
case 'projects:branches:new': case 'projects:branches:new':
...@@ -273,7 +274,7 @@ import DueDateSelectors from './due_date_select'; ...@@ -273,7 +274,7 @@ import DueDateSelectors from './due_date_select';
} }
case 'projects:merge_requests:creations:diffs': case 'projects:merge_requests:creations:diffs':
case 'projects:merge_requests:edit': case 'projects:merge_requests:edit':
new gl.Diff(); new Diff();
shortcut_handler = new ShortcutsNavigation(); shortcut_handler = new ShortcutsNavigation();
new GLForm($('.merge-request-form'), true); new GLForm($('.merge-request-form'), true);
new IssuableForm($('.merge-request-form')); new IssuableForm($('.merge-request-form'));
...@@ -307,7 +308,7 @@ import DueDateSelectors from './due_date_select'; ...@@ -307,7 +308,7 @@ import DueDateSelectors from './due_date_select';
new GLForm($('.release-form'), true); new GLForm($('.release-form'), true);
break; break;
case 'projects:merge_requests:show': case 'projects:merge_requests:show':
new gl.Diff(); new Diff();
shortcut_handler = new ShortcutsIssuable(true); shortcut_handler = new ShortcutsIssuable(true);
new ZenMode(); new ZenMode();
...@@ -323,7 +324,7 @@ import DueDateSelectors from './due_date_select'; ...@@ -323,7 +324,7 @@ import DueDateSelectors from './due_date_select';
new gl.Activities(); new gl.Activities();
break; break;
case 'projects:commit:show': case 'projects:commit:show':
new gl.Diff(); new Diff();
new ZenMode(); new ZenMode();
shortcut_handler = new ShortcutsNavigation(); shortcut_handler = new ShortcutsNavigation();
new MiniPipelineGraph({ new MiniPipelineGraph({
......
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, max-len, one-var, one-var-declaration-per-line, quotes, prefer-template, newline-per-chained-call, comma-dangle, new-cap, no-else-return, consistent-return */
/* global notes */
/* Developer beware! Do not add logic to showButton or hideButton /* Developer beware! Do not add logic to showButton or hideButton
* that will force a reflow. Doing so will create a signficant performance * that will force a reflow. Doing so will create a signficant performance
* bottleneck for pages with large diffs. For a comprehensive list of what * bottleneck for pages with large diffs. For a comprehensive list of what
...@@ -20,8 +17,10 @@ const DIFF_EXPANDED_CLASS = 'diff-expanded'; ...@@ -20,8 +17,10 @@ const DIFF_EXPANDED_CLASS = 'diff-expanded';
export default { export default {
init($diffFile) { init($diffFile) {
/* Caching is used only when the following members are *true*. This is because there are likely to be /* Caching is used only when the following members are *true*.
* differently configured versions of diffs in the same session. However if these values are true, they * This is because there are likely to be
* differently configured versions of diffs in the same session.
* However if these values are true, they
* will be true in all cases */ * will be true in all cases */
if (!this.userCanCreateNote) { if (!this.userCanCreateNote) {
......
...@@ -50,8 +50,6 @@ import './compare_autocomplete'; ...@@ -50,8 +50,6 @@ import './compare_autocomplete';
import './confirm_danger_modal'; import './confirm_danger_modal';
import './copy_as_gfm'; import './copy_as_gfm';
import './copy_to_clipboard'; import './copy_to_clipboard';
import './diff';
import './files_comment_button';
import Flash, { removeFlashClickListener } from './flash'; import Flash, { removeFlashClickListener } from './flash';
import './gl_dropdown'; import './gl_dropdown';
import './gl_field_error'; import './gl_field_error';
......
...@@ -11,8 +11,8 @@ import { ...@@ -11,8 +11,8 @@ import {
handleLocationHash, handleLocationHash,
isMetaClick, isMetaClick,
} from './lib/utils/common_utils'; } from './lib/utils/common_utils';
import initDiscussionTab from './image_diff/init_discussion_tab'; import initDiscussionTab from './image_diff/init_discussion_tab';
import Diff from './diff';
/* eslint-disable max-len */ /* eslint-disable max-len */
// MergeRequestTabs // MergeRequestTabs
...@@ -292,7 +292,7 @@ import initDiscussionTab from './image_diff/init_discussion_tab'; ...@@ -292,7 +292,7 @@ import initDiscussionTab from './image_diff/init_discussion_tab';
} }
this.diffsLoaded = true; this.diffsLoaded = true;
new gl.Diff(); new Diff();
this.scrollToElement('#diffs'); this.scrollToElement('#diffs');
$('.diff-file').each((i, el) => { $('.diff-file').each((i, el) => {
......
...@@ -5,8 +5,7 @@ import '~/merge_request_tabs'; ...@@ -5,8 +5,7 @@ import '~/merge_request_tabs';
import '~/commit/pipelines/pipelines_bundle'; import '~/commit/pipelines/pipelines_bundle';
import '~/breakpoints'; import '~/breakpoints';
import '~/lib/utils/common_utils'; import '~/lib/utils/common_utils';
import '~/diff'; import Diff from '~/diff';
import '~/files_comment_button';
import '~/notes'; import '~/notes';
import 'vendor/jquery.scrollTo'; import 'vendor/jquery.scrollTo';
...@@ -225,7 +224,7 @@ import 'vendor/jquery.scrollTo'; ...@@ -225,7 +224,7 @@ import 'vendor/jquery.scrollTo';
describe('with "Side-by-side"/parallel diff view', () => { describe('with "Side-by-side"/parallel diff view', () => {
beforeEach(function () { beforeEach(function () {
this.class.diffViewType = () => 'parallel'; this.class.diffViewType = () => 'parallel';
gl.Diff.prototype.diffViewType = () => 'parallel'; Diff.prototype.diffViewType = () => 'parallel';
}); });
it('maintains `container-limited` for pipelines tab', function (done) { it('maintains `container-limited` for pipelines tab', function (done) {
......
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