Commit 6149c2e2 authored by Mike Greiling's avatar Mike Greiling

refactor VisibilitySelect class to ES module syntax

parent f8909396
...@@ -160,7 +160,6 @@ import './user_tabs'; ...@@ -160,7 +160,6 @@ import './user_tabs';
import './username_validator'; import './username_validator';
import './users_select'; import './users_select';
import './version_check_image'; import './version_check_image';
import './visibility_select';
// eslint-disable-next-line global-require, import/no-commonjs // eslint-disable-next-line global-require, import/no-commonjs
if (process.env.NODE_ENV !== 'production') require('./test_utils/'); if (process.env.NODE_ENV !== 'production') require('./test_utils/');
......
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-unused-vars, one-var, no-underscore-dangle, prefer-template, no-else-return, prefer-arrow-callback, max-len */ /* eslint-disable func-names, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, no-unused-vars, one-var, no-underscore-dangle, prefer-template, no-else-return, prefer-arrow-callback, max-len */
import VisibilitySelect from './visibility_select';
function highlightChanges($elm) { function highlightChanges($elm) {
$elm.addClass('highlight-changes'); $elm.addClass('highlight-changes');
setTimeout(() => $elm.removeClass('highlight-changes'), 10); setTimeout(() => $elm.removeClass('highlight-changes'), 10);
...@@ -30,7 +32,7 @@ function highlightChanges($elm) { ...@@ -30,7 +32,7 @@ function highlightChanges($elm) {
ProjectNew.prototype.initVisibilitySelect = function() { ProjectNew.prototype.initVisibilitySelect = function() {
const visibilityContainer = document.querySelector('.js-visibility-select'); const visibilityContainer = document.querySelector('.js-visibility-select');
if (!visibilityContainer) return; if (!visibilityContainer) return;
const visibilitySelect = new gl.VisibilitySelect(visibilityContainer); const visibilitySelect = new VisibilitySelect(visibilityContainer);
visibilitySelect.init(); visibilitySelect.init();
const $visibilitySelect = $(visibilityContainer).find('select'); const $visibilitySelect = $(visibilityContainer).find('select');
......
class VisibilitySelect { export default class VisibilitySelect {
constructor(container) { constructor(container) {
if (!container) throw new Error('VisibilitySelect requires a container element as argument 1'); if (!container) throw new Error('VisibilitySelect requires a container element as argument 1');
this.container = container; this.container = container;
...@@ -19,6 +19,3 @@ class VisibilitySelect { ...@@ -19,6 +19,3 @@ class VisibilitySelect {
this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description; this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
} }
} }
window.gl = window.gl || {};
window.gl.VisibilitySelect = VisibilitySelect;
import '~/visibility_select'; import VisibilitySelect from '~/visibility_select';
(() => { (() => {
const VisibilitySelect = gl.VisibilitySelect;
describe('VisibilitySelect', function () { describe('VisibilitySelect', function () {
const lockedElement = document.createElement('div'); const lockedElement = document.createElement('div');
lockedElement.dataset.helpBlock = 'lockedHelpBlock'; lockedElement.dataset.helpBlock = 'lockedHelpBlock';
......
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