diff options
author | Phil Hughes <me@iamphill.com> | 2017-10-23 07:52:21 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-10-23 07:52:21 +0000 |
commit | c1ed00e81df21365bd783da8cb40957e474ed35d (patch) | |
tree | 534b200c446d000d7b6659795cc24054d2289869 | |
parent | 5d74973d8148548f505478ed773795d377e6f0d6 (diff) | |
parent | cf347a5739f31af1f368717b7850d8fbeb48ecd8 (diff) | |
download | gitlab-ce-c1ed00e81df21365bd783da8cb40957e474ed35d.tar.gz |
Merge branch '38869-diff' into 'master'
Remove Diff class from global namespace
See merge request gitlab-org/gitlab-ce!14965
-rw-r--r-- | app/assets/javascripts/diff.js | 15 | ||||
-rw-r--r-- | app/assets/javascripts/dispatcher.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/files_comment_button.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/main.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 4 | ||||
-rw-r--r-- | spec/javascripts/merge_request_tabs_spec.js | 5 |
6 files changed, 18 insertions, 26 deletions
diff --git a/app/assets/javascripts/diff.js b/app/assets/javascripts/diff.js index 6c78662baa7..c8874e48c09 100644 --- a/app/assets/javascripts/diff.js +++ b/app/assets/javascripts/diff.js @@ -1,5 +1,3 @@ -/* eslint-disable class-methods-use-this */ - import './lib/utils/url_utility'; import FilesCommentButton from './files_comment_button'; import SingleFileDiff from './single_file_diff'; @@ -8,7 +6,7 @@ import imageDiffHelper from './image_diff/helpers/index'; const UNFOLD_COUNT = 20; let isBound = false; -class Diff { +export default class Diff { constructor() { const $diffFile = $('.files .diff-file'); @@ -104,7 +102,7 @@ class Diff { } this.highlightSelectedLine(); } - + // eslint-disable-next-line class-methods-use-this handleParallelLineDown(e) { const line = $(e.currentTarget); const table = line.closest('table'); @@ -116,11 +114,11 @@ class Diff { table.addClass(`${lineClass}-selected`); } } - + // eslint-disable-next-line class-methods-use-this diffViewType() { return $('.inline-parallel-buttons a.active').data('view-type'); } - + // eslint-disable-next-line class-methods-use-this lineNumbers(line) { const children = line.find('.diff-line-num').toArray(); if (children.length !== 2) { @@ -128,7 +126,7 @@ class Diff { } return children.map(elm => parseInt($(elm).data('linenumber'), 10) || 0); } - + // eslint-disable-next-line class-methods-use-this highlightSelectedLine() { const hash = gl.utils.getLocationHash(); const $diffFiles = $('.diff-file'); @@ -141,6 +139,3 @@ class Diff { } } } - -window.gl = window.gl || {}; -window.gl.Diff = Diff; diff --git a/app/assets/javascripts/dispatcher.js b/app/assets/javascripts/dispatcher.js index 2885923aeda..5ca1708f1b3 100644 --- a/app/assets/javascripts/dispatcher.js +++ b/app/assets/javascripts/dispatcher.js @@ -87,6 +87,7 @@ import U2FAuthenticate from './u2f/authenticate'; import Members from './members'; import memberExpirationDate from './member_expiration_date'; import DueDateSelectors from './due_date_select'; +import Diff from './diff'; (function() { var Dispatcher; @@ -237,7 +238,7 @@ import DueDateSelectors from './due_date_select'; new GLForm($('.milestone-form'), true); break; case 'projects:compare:show': - new gl.Diff(); + new Diff(); initChangesDropdown(); break; case 'projects:branches:new': @@ -273,7 +274,7 @@ import DueDateSelectors from './due_date_select'; } case 'projects:merge_requests:creations:diffs': case 'projects:merge_requests:edit': - new gl.Diff(); + new Diff(); shortcut_handler = new ShortcutsNavigation(); new GLForm($('.merge-request-form'), true); new IssuableForm($('.merge-request-form')); @@ -307,7 +308,7 @@ import DueDateSelectors from './due_date_select'; new GLForm($('.release-form'), true); break; case 'projects:merge_requests:show': - new gl.Diff(); + new Diff(); shortcut_handler = new ShortcutsIssuable(true); new ZenMode(); @@ -323,7 +324,7 @@ import DueDateSelectors from './due_date_select'; new gl.Activities(); break; case 'projects:commit:show': - new gl.Diff(); + new Diff(); new ZenMode(); shortcut_handler = new ShortcutsNavigation(); new MiniPipelineGraph({ diff --git a/app/assets/javascripts/files_comment_button.js b/app/assets/javascripts/files_comment_button.js index a00d29a845a..90020344748 100644 --- a/app/assets/javascripts/files_comment_button.js +++ b/app/assets/javascripts/files_comment_button.js @@ -1,6 +1,3 @@ -/* 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 * that will force a reflow. Doing so will create a signficant performance * bottleneck for pages with large diffs. For a comprehensive list of what @@ -20,8 +17,10 @@ const DIFF_EXPANDED_CLASS = 'diff-expanded'; export default { init($diffFile) { - /* Caching is used only when the following members are *true*. This is because there are likely to be - * differently configured versions of diffs in the same session. However if these values are true, they + /* Caching is used only when the following members are *true*. + * 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 */ if (!this.userCanCreateNote) { diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 4cf07e99161..6b13fda0d44 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -50,8 +50,6 @@ import './compare_autocomplete'; import './confirm_danger_modal'; import './copy_as_gfm'; import './copy_to_clipboard'; -import './diff'; -import './files_comment_button'; import Flash, { removeFlashClickListener } from './flash'; import './gl_dropdown'; import './gl_field_error'; diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index df042c7baff..789ccf48190 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -11,8 +11,8 @@ import { handleLocationHash, isMetaClick, } from './lib/utils/common_utils'; - import initDiscussionTab from './image_diff/init_discussion_tab'; +import Diff from './diff'; /* eslint-disable max-len */ // MergeRequestTabs @@ -292,7 +292,7 @@ import initDiscussionTab from './image_diff/init_discussion_tab'; } this.diffsLoaded = true; - new gl.Diff(); + new Diff(); this.scrollToElement('#diffs'); $('.diff-file').each((i, el) => { diff --git a/spec/javascripts/merge_request_tabs_spec.js b/spec/javascripts/merge_request_tabs_spec.js index 18916c5aa97..e441d1153ed 100644 --- a/spec/javascripts/merge_request_tabs_spec.js +++ b/spec/javascripts/merge_request_tabs_spec.js @@ -5,8 +5,7 @@ import '~/merge_request_tabs'; import '~/commit/pipelines/pipelines_bundle'; import '~/breakpoints'; import '~/lib/utils/common_utils'; -import '~/diff'; -import '~/files_comment_button'; +import Diff from '~/diff'; import '~/notes'; import 'vendor/jquery.scrollTo'; @@ -225,7 +224,7 @@ import 'vendor/jquery.scrollTo'; describe('with "Side-by-side"/parallel diff view', () => { beforeEach(function () { this.class.diffViewType = () => 'parallel'; - gl.Diff.prototype.diffViewType = () => 'parallel'; + Diff.prototype.diffViewType = () => 'parallel'; }); it('maintains `container-limited` for pipelines tab', function (done) { |