Commit c06dad62 authored by Mike Greiling's avatar Mike Greiling Committed by Clement Ho

Remove IIFEs around several javascript classes

parent 11e03bf4
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
/* eslint no-new: "off" */ /* eslint no-new: "off" */
import AccessorUtilities from './lib/utils/accessor'; import AccessorUtilities from './lib/utils/accessor';
((global) => { /**
/**
* Memorize the last selected tab after reloading a page. * Memorize the last selected tab after reloading a page.
* Does that setting the current selected tab in the localStorage * Does that setting the current selected tab in the localStorage
*/ */
class ActiveTabMemoizer { class ActiveTabMemoizer {
constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) { constructor({ currentTabKey = 'current_signin_tab', tabSelector = 'ul.nav-tabs' } = {}) {
this.currentTabKey = currentTabKey; this.currentTabKey = currentTabKey;
this.tabSelector = tabSelector; this.tabSelector = tabSelector;
...@@ -51,7 +50,6 @@ import AccessorUtilities from './lib/utils/accessor'; ...@@ -51,7 +50,6 @@ import AccessorUtilities from './lib/utils/accessor';
return window.localStorage.getItem(this.currentTabKey); return window.localStorage.getItem(this.currentTabKey);
} }
} }
global.ActiveTabMemoizer = ActiveTabMemoizer; window.ActiveTabMemoizer = ActiveTabMemoizer;
})(window);
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
import FilesCommentButton from './files_comment_button'; import FilesCommentButton from './files_comment_button';
(function() { window.SingleFileDiff = (function() {
window.SingleFileDiff = (function() {
var COLLAPSED_HTML, ERROR_HTML, LOADING_HTML, WRAPPER; var COLLAPSED_HTML, ERROR_HTML, LOADING_HTML, WRAPPER;
WRAPPER = '<div class="diff-content"></div>'; WRAPPER = '<div class="diff-content"></div>';
...@@ -88,13 +87,12 @@ import FilesCommentButton from './files_comment_button'; ...@@ -88,13 +87,12 @@ import FilesCommentButton from './files_comment_button';
}; };
return SingleFileDiff; return SingleFileDiff;
})(); })();
$.fn.singleFileDiff = function() { $.fn.singleFileDiff = function() {
return this.each(function() { return this.each(function() {
if (!$.data(this, 'singleFileDiff')) { if (!$.data(this, 'singleFileDiff')) {
return $.data(this, 'singleFileDiff', new window.SingleFileDiff(this)); return $.data(this, 'singleFileDiff', new window.SingleFileDiff(this));
} }
}); });
}; };
}).call(window);
/* /**
* Instances of SmartInterval extend the functionality of `setInterval`, make it configurable * Instances of SmartInterval extend the functionality of `setInterval`, make it configurable
* and controllable by a public API. * and controllable by a public API.
* */
* */
class SmartInterval {
(() => {
class SmartInterval {
/** /**
* @param { function } opts.callback Function to be called on each iteration (required) * @param { function } opts.callback Function to be called on each iteration (required)
* @param { milliseconds } opts.startingInterval `currentInterval` is set to this initially * @param { milliseconds } opts.startingInterval `currentInterval` is set to this initially
...@@ -37,6 +35,7 @@ ...@@ -37,6 +35,7 @@
this.initInterval(); this.initInterval();
} }
/* public */ /* public */
start() { start() {
...@@ -153,6 +152,6 @@ ...@@ -153,6 +152,6 @@
state.intervalId = window.clearInterval(state.intervalId); state.intervalId = window.clearInterval(state.intervalId);
} }
} }
gl.SmartInterval = SmartInterval;
})(window.gl || (window.gl = {})); window.gl.SmartInterval = SmartInterval;
/* eslint-disable arrow-parens, no-param-reassign, space-before-function-paren, func-names, no-var, max-len */ /* eslint-disable arrow-parens, no-param-reassign, space-before-function-paren, func-names, no-var, max-len */
(global => { window.gl.SnippetsList = function() {
global.gl = global.gl || {};
gl.SnippetsList = function() {
var $holder = $('.snippets-list-holder'); var $holder = $('.snippets-list-holder');
$holder.find('.pagination').on('ajax:success', (e, data) => { $holder.find('.pagination').on('ajax:success', (e, data) => {
$holder.replaceWith(data.html); $holder.replaceWith(data.html);
}); });
}; };
})(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-unused-vars, one-var, no-var, one-var-declaration-per-line, prefer-arrow-callback, no-new, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-unused-vars, one-var, no-var, one-var-declaration-per-line, prefer-arrow-callback, no-new, max-len */
/* global Flash */ /* global Flash */
(function() { window.Star = (function() {
this.Star = (function() {
function Star() { function Star() {
$('.project-home-panel .toggle-star').on('ajax:success', function(e, data, status, xhr) { $('.project-home-panel .toggle-star').on('ajax:success', function(e, data, status, xhr) {
var $starIcon, $starSpan, $this, toggleStar; var $starIcon, $starSpan, $this, toggleStar;
...@@ -26,5 +25,4 @@ ...@@ -26,5 +25,4 @@
} }
return Star; return Star;
})(); })();
}).call(window);
(() => { class Subscription {
class Subscription {
constructor(containerElm) { constructor(containerElm) {
this.containerElm = containerElm; this.containerElm = containerElm;
...@@ -40,8 +39,7 @@ ...@@ -40,8 +39,7 @@
static bindAll(selector) { static bindAll(selector) {
[].forEach.call(document.querySelectorAll(selector), elm => new Subscription(elm)); [].forEach.call(document.querySelectorAll(selector), elm => new Subscription(elm));
} }
} }
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.Subscription = Subscription; window.gl.Subscription = Subscription;
})();
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, quotes, object-shorthand, no-unused-vars, no-shadow, one-var, one-var-declaration-per-line, comma-dangle, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, quotes, object-shorthand, no-unused-vars, no-shadow, one-var, one-var-declaration-per-line, comma-dangle, max-len */
(function() {
this.SubscriptionSelect = (function() { window.SubscriptionSelect = (function() {
function SubscriptionSelect() { function SubscriptionSelect() {
$('.js-subscription-event').each(function(i, el) { $('.js-subscription-event').each(function(i, el) {
var fieldName; var fieldName;
...@@ -30,5 +30,4 @@ ...@@ -30,5 +30,4 @@
} }
return SubscriptionSelect; return SubscriptionSelect;
})(); })();
}).call(window);
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
// //
// <div class="js-syntax-highlight"></div> // <div class="js-syntax-highlight"></div>
// //
(function() {
$.fn.syntaxHighlight = function() { $.fn.syntaxHighlight = function() {
var $children; var $children;
if ($(this).hasClass('js-syntax-highlight')) { if ($(this).hasClass('js-syntax-highlight')) {
...@@ -23,5 +23,4 @@ ...@@ -23,5 +23,4 @@
return $children.syntaxHighlight(); return $children.syntaxHighlight();
} }
} }
}; };
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, max-len, quotes, consistent-return, no-var, one-var, one-var-declaration-per-line, no-else-return, prefer-arrow-callback, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, max-len, quotes, consistent-return, no-var, one-var, one-var-declaration-per-line, no-else-return, prefer-arrow-callback, max-len */
(function() { window.TreeView = (function() {
this.TreeView = (function() {
function TreeView() { function TreeView() {
this.initKeyNav(); this.initKeyNav();
// Code browser tree slider // Code browser tree slider
...@@ -64,5 +63,4 @@ ...@@ -64,5 +63,4 @@
}; };
return TreeView; return TreeView;
})(); })();
}).call(window);
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
((global) => { class User {
global.User = class {
constructor({ action }) { constructor({ action }) {
this.action = action; this.action = action;
this.placeProfileAvatarsToTop(); this.placeProfileAvatarsToTop();
...@@ -18,7 +17,7 @@ import Cookies from 'js-cookie'; ...@@ -18,7 +17,7 @@ import Cookies from 'js-cookie';
} }
initTabs() { initTabs() {
return new global.UserTabs({ return new window.gl.UserTabs({
parentEl: '.user-profile', parentEl: '.user-profile',
action: this.action action: this.action
}); });
...@@ -31,5 +30,7 @@ import Cookies from 'js-cookie'; ...@@ -31,5 +30,7 @@ import Cookies from 'js-cookie';
$(this).parents('.project-limit-message').remove(); $(this).parents('.project-limit-message').remove();
}); });
} }
}; }
})(window.gl || (window.gl = {}));
window.gl = window.gl || {};
window.gl.User = User;
...@@ -59,8 +59,8 @@ content on the Users#show page. ...@@ -59,8 +59,8 @@ content on the Users#show page.
</div> </div>
</div> </div>
*/ */
((global) => {
class UserTabs { class UserTabs {
constructor ({ defaultAction, action, parentEl }) { constructor ({ defaultAction, action, parentEl }) {
this.loaded = {}; this.loaded = {};
this.defaultAction = defaultAction || 'activity'; this.defaultAction = defaultAction || 'activity';
...@@ -170,6 +170,7 @@ content on the Users#show page. ...@@ -170,6 +170,7 @@ content on the Users#show page.
getCurrentAction() { getCurrentAction() {
return this.$parentEl.find('.nav-links .active a').data('action'); return this.$parentEl.find('.nav-links .active a').data('action');
} }
} }
global.UserTabs = UserTabs;
})(window.gl || (window.gl = {})); window.gl = window.gl || {};
window.gl.UserTabs = UserTabs;
/* eslint-disable comma-dangle, consistent-return, class-methods-use-this, arrow-parens, no-param-reassign, max-len */ /* eslint-disable comma-dangle, consistent-return, class-methods-use-this, arrow-parens, no-param-reassign, max-len */
((global) => { const debounceTimeoutDuration = 1000;
const debounceTimeoutDuration = 1000; const invalidInputClass = 'gl-field-error-outline';
const invalidInputClass = 'gl-field-error-outline'; const successInputClass = 'gl-field-success-outline';
const successInputClass = 'gl-field-success-outline'; const unavailableMessageSelector = '.username .validation-error';
const unavailableMessageSelector = '.username .validation-error'; const successMessageSelector = '.username .validation-success';
const successMessageSelector = '.username .validation-success'; const pendingMessageSelector = '.username .validation-pending';
const pendingMessageSelector = '.username .validation-pending'; const invalidMessageSelector = '.username .gl-field-error';
const invalidMessageSelector = '.username .gl-field-error';
class UsernameValidator {
class UsernameValidator {
constructor() { constructor() {
this.inputElement = $('#new_user_username'); this.inputElement = $('#new_user_username');
this.inputDomElement = this.inputElement.get(0); this.inputDomElement = this.inputElement.get(0);
...@@ -129,7 +128,6 @@ ...@@ -129,7 +128,6 @@
this.inputElement.addClass(invalidInputClass).removeClass(successInputClass); this.inputElement.addClass(invalidInputClass).removeClass(successInputClass);
$inputErrorMessage.show(); $inputErrorMessage.show();
} }
} }
global.UsernameValidator = UsernameValidator; window.UsernameValidator = UsernameValidator;
})(window);
(() => { class VisibilitySelect {
const gl = window.gl || (window.gl = {});
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;
...@@ -21,7 +18,7 @@ ...@@ -21,7 +18,7 @@
updateHelpText() { updateHelpText() {
this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description; this.helpBlock.textContent = this.select.querySelector('option:checked').dataset.description;
} }
} }
gl.VisibilitySelect = VisibilitySelect; window.gl = window.gl || {};
})(); window.gl.VisibilitySelect = VisibilitySelect;
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
import 'vendor/jquery.nicescroll'; import 'vendor/jquery.nicescroll';
import './breakpoints'; import './breakpoints';
((global) => { class Wikis {
class Wikis {
constructor() { constructor() {
this.bp = Breakpoints.get(); this.bp = Breakpoints.get();
this.sidebarEl = document.querySelector('.js-wiki-sidebar'); this.sidebarEl = document.querySelector('.js-wiki-sidebar');
...@@ -63,7 +62,7 @@ import './breakpoints'; ...@@ -63,7 +62,7 @@ import './breakpoints';
classList.remove('right-sidebar-expanded'); classList.remove('right-sidebar-expanded');
} }
} }
} }
global.Wikis = Wikis; window.gl = window.gl || {};
})(window.gl || (window.gl = {})); window.gl.Wikis = Wikis;
...@@ -34,8 +34,8 @@ window.Dropzone = Dropzone; ...@@ -34,8 +34,8 @@ window.Dropzone = Dropzone;
// **Cancelable** No // **Cancelable** No
// **Target** a.js-zen-leave // **Target** a.js-zen-leave
// //
(function() {
this.ZenMode = (function() { window.ZenMode = (function() {
function ZenMode() { function ZenMode() {
this.active_backdrop = null; this.active_backdrop = null;
this.active_textarea = null; this.active_textarea = null;
...@@ -94,5 +94,4 @@ window.Dropzone = Dropzone; ...@@ -94,5 +94,4 @@ window.Dropzone = Dropzone;
}; };
return ZenMode; return ZenMode;
})(); })();
}).call(window);
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