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