summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-10-26 23:14:18 +0300
committerFilipa Lacerda <filipa@gitlab.com>2017-10-26 23:14:46 +0300
commita665a35438fe1ddf96228918fd99f790de9b6517 (patch)
tree48b2f84e2d8da09f78ae8e2a9703aef9d5084c10
parentcf542f9ed0ff54e9072eca250244662808b80eab (diff)
downloadgitlab-ce-a665a35438fe1ddf96228918fd99f790de9b6517.tar.gz
Remove issuableContext from global namespace
-rw-r--r--app/assets/javascripts/boards/components/board_sidebar.js2
-rw-r--r--app/assets/javascripts/init_issuable_sidebar.js2
-rw-r--r--app/assets/javascripts/issuable_context.js113
-rw-r--r--app/assets/javascripts/main.js2
-rw-r--r--spec/javascripts/issuable_context_spec.js3
-rw-r--r--spec/javascripts/labels_issue_sidebar_spec.js2
6 files changed, 60 insertions, 64 deletions
diff --git a/app/assets/javascripts/boards/components/board_sidebar.js b/app/assets/javascripts/boards/components/board_sidebar.js
index c1f902a785a..6fa41dbd0dd 100644
--- a/app/assets/javascripts/boards/components/board_sidebar.js
+++ b/app/assets/javascripts/boards/components/board_sidebar.js
@@ -1,5 +1,5 @@
/* eslint-disable comma-dangle, space-before-function-paren, no-new */
-/* global IssuableContext */
+import IssuableContext from '../../issuable_context';
/* global MilestoneSelect */
/* global LabelsSelect */
/* global Sidebar */
diff --git a/app/assets/javascripts/init_issuable_sidebar.js b/app/assets/javascripts/init_issuable_sidebar.js
index 32a1a269f9a..6f476f96f72 100644
--- a/app/assets/javascripts/init_issuable_sidebar.js
+++ b/app/assets/javascripts/init_issuable_sidebar.js
@@ -1,7 +1,7 @@
/* eslint-disable no-new */
/* global MilestoneSelect */
/* global LabelsSelect */
-/* global IssuableContext */
+import IssuableContext from './issuable_context';
/* global Sidebar */
import DueDateSelectors from './due_date_select';
diff --git a/app/assets/javascripts/issuable_context.js b/app/assets/javascripts/issuable_context.js
index 73791edaebb..5bc7f8d9cb9 100644
--- a/app/assets/javascripts/issuable_context.js
+++ b/app/assets/javascripts/issuable_context.js
@@ -1,33 +1,35 @@
-/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-new, comma-dangle, quotes, prefer-arrow-callback, consistent-return, one-var, no-var, one-var-declaration-per-line, no-underscore-dangle, max-len */
import Cookies from 'js-cookie';
import bp from './breakpoints';
import UsersSelect from './users_select';
const PARTICIPANTS_ROW_COUNT = 7;
-(function() {
- this.IssuableContext = (function() {
- function IssuableContext(currentUser) {
- this.initParticipants();
- new UsersSelect(currentUser);
- $('select.select2').select2({
- width: 'resolve',
- dropdownAutoWidth: true
- });
- $(".issuable-sidebar .inline-update").on("change", "select", function() {
- return $(this).submit();
- });
- $(".issuable-sidebar .inline-update").on("change", ".js-assignee", function() {
- return $(this).submit();
- });
- $(document).off('click', '.issuable-sidebar .dropdown-content a').on('click', '.issuable-sidebar .dropdown-content a', function(e) {
- return e.preventDefault();
- });
- $(document).off('click', '.edit-link').on('click', '.edit-link', function(e) {
- var $block, $selectbox;
+export default class IssuableContext {
+ constructor(currentUser) {
+ this.initParticipants();
+ this.userSelect = new UsersSelect(currentUser);
+
+ $('select.select2').select2({
+ width: 'resolve',
+ dropdownAutoWidth: true,
+ });
+
+ $('.issuable-sidebar .inline-update').on('change', 'select', function onClickSelect() {
+ return $(this).submit();
+ });
+ $('.issuable-sidebar .inline-update').on('change', '.js-assignee', function onClickAssignee() {
+ return $(this).submit();
+ });
+ $(document)
+ .off('click', '.issuable-sidebar .dropdown-content a')
+ .on('click', '.issuable-sidebar .dropdown-content a', e => e.preventDefault());
+
+ $(document)
+ .off('click', '.edit-link')
+ .on('click', '.edit-link', function onClickEdit(e) {
e.preventDefault();
- $block = $(this).parents('.block');
- $selectbox = $block.find('.selectbox');
+ const $block = $(this).parents('.block');
+ const $selectbox = $block.find('.selectbox');
if ($selectbox.is(':visible')) {
$selectbox.hide();
$block.find('.value').show();
@@ -35,46 +37,43 @@ const PARTICIPANTS_ROW_COUNT = 7;
$selectbox.show();
$block.find('.value').hide();
}
+
if ($selectbox.is(':visible')) {
- return setTimeout(function() {
- return $block.find('.dropdown-menu-toggle').trigger('click');
- }, 0);
+ setTimeout(() => $block.find('.dropdown-menu-toggle').trigger('click'), 0);
}
});
- window.addEventListener('beforeunload', function() {
- // collapsed_gutter cookie hides the sidebar
- var bpBreakpoint = bp.getBreakpointSize();
- if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm') {
- Cookies.set('collapsed_gutter', true);
- }
- });
- }
- IssuableContext.prototype.initParticipants = function() {
- $(document).on('click', '.js-participants-more', this.toggleHiddenParticipants);
- return $('.js-participants-author').each(function(i) {
- if (i >= PARTICIPANTS_ROW_COUNT) {
- return $(this).addClass('js-participants-hidden').hide();
- }
- });
- };
+ window.addEventListener('beforeunload', () => {
+ // collapsed_gutter cookie hides the sidebar
+ const bpBreakpoint = bp.getBreakpointSize();
+ if (bpBreakpoint === 'xs' || bpBreakpoint === 'sm') {
+ Cookies.set('collapsed_gutter', true);
+ }
+ });
+ }
- IssuableContext.prototype.toggleHiddenParticipants = function() {
- const currentText = $(this).text().trim();
- const lessText = $(this).data('less-text');
- const originalText = $(this).data('original-text');
+ initParticipants() {
+ $(document).on('click', '.js-participants-more', this.toggleHiddenParticipants);
+ return $('.js-participants-author').each(function forEachAuthor(i) {
+ if (i >= PARTICIPANTS_ROW_COUNT) {
+ $(this).addClass('js-participants-hidden').hide();
+ }
+ });
+ }
- if (currentText === originalText) {
- $(this).text(lessText);
+ toggleHiddenParticipants() {
+ const currentText = $(this).text().trim();
+ const lessText = $(this).data('less-text');
+ const originalText = $(this).data('original-text');
- if (gl.lazyLoader) gl.lazyLoader.loadCheck();
- } else {
- $(this).text(originalText);
- }
+ if (currentText === originalText) {
+ $(this).text(lessText);
- $('.js-participants-hidden').toggle();
- };
+ if (gl.lazyLoader) gl.lazyLoader.loadCheck();
+ } else {
+ $(this).text(originalText);
+ }
- return IssuableContext;
- })();
-}).call(window);
+ $('.js-participants-hidden').toggle();
+ }
+}
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
index 00a94c45b47..94951cfbdfe 100644
--- a/app/assets/javascripts/main.js
+++ b/app/assets/javascripts/main.js
@@ -58,8 +58,6 @@ import './gl_form';
import './groups_select';
import './header';
import initImporterStatus from './importer_status';
-import './issuable_index';
-import './issuable_context';
import './issuable_form';
import './issue';
import './issue_status_select';
diff --git a/spec/javascripts/issuable_context_spec.js b/spec/javascripts/issuable_context_spec.js
index bcb2b7b24a0..f266209027a 100644
--- a/spec/javascripts/issuable_context_spec.js
+++ b/spec/javascripts/issuable_context_spec.js
@@ -1,6 +1,5 @@
-/* global IssuableContext */
-import '~/issuable_context';
import $ from 'jquery';
+import IssuableContext from '~/issuable_context';
describe('IssuableContext', () => {
describe('toggleHiddenParticipants', () => {
diff --git a/spec/javascripts/labels_issue_sidebar_spec.js b/spec/javascripts/labels_issue_sidebar_spec.js
index e47adc49224..775a81d3d78 100644
--- a/spec/javascripts/labels_issue_sidebar_spec.js
+++ b/spec/javascripts/labels_issue_sidebar_spec.js
@@ -1,5 +1,5 @@
/* eslint-disable no-new */
-/* global IssuableContext */
+import IssuableContext from '~/issuable_context';
/* global LabelsSelect */
import '~/gl_dropdown';