Commit 302d0453 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Merge branch 'remove-iifes-1' into 'master'

Remove IIFEs for several JS files - Part 1

See merge request !9884
parents 18a688ff c8f986fe
No related merge requests found
/* eslint-disable no-param-reassign */ const MAX_MESSAGE_LENGTH = 500;
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message';
((global) => { class AbuseReports {
const MAX_MESSAGE_LENGTH = 500; constructor() {
const MESSAGE_CELL_SELECTOR = '.abuse-reports .message'; $(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage);
$(document)
class AbuseReports { .off('click', MESSAGE_CELL_SELECTOR)
constructor() { .on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation);
$(MESSAGE_CELL_SELECTOR).each(this.truncateLongMessage); }
$(document)
.off('click', MESSAGE_CELL_SELECTOR)
.on('click', MESSAGE_CELL_SELECTOR, this.toggleMessageTruncation);
}
truncateLongMessage() { truncateLongMessage() {
const $messageCellElement = $(this); const $messageCellElement = $(this);
const reportMessage = $messageCellElement.text(); const reportMessage = $messageCellElement.text();
if (reportMessage.length > MAX_MESSAGE_LENGTH) { if (reportMessage.length > MAX_MESSAGE_LENGTH) {
$messageCellElement.data('original-message', reportMessage); $messageCellElement.data('original-message', reportMessage);
$messageCellElement.data('message-truncated', 'true'); $messageCellElement.data('message-truncated', 'true');
$messageCellElement.text(global.text.truncate(reportMessage, MAX_MESSAGE_LENGTH)); $messageCellElement.text(window.gl.text.truncate(reportMessage, MAX_MESSAGE_LENGTH));
}
} }
}
toggleMessageTruncation() { toggleMessageTruncation() {
const $messageCellElement = $(this); const $messageCellElement = $(this);
const originalMessage = $messageCellElement.data('original-message'); const originalMessage = $messageCellElement.data('original-message');
if (!originalMessage) return; if (!originalMessage) return;
if ($messageCellElement.data('message-truncated') === 'true') { if ($messageCellElement.data('message-truncated') === 'true') {
$messageCellElement.data('message-truncated', 'false'); $messageCellElement.data('message-truncated', 'false');
$messageCellElement.text(originalMessage); $messageCellElement.text(originalMessage);
} else { } else {
$messageCellElement.data('message-truncated', 'true'); $messageCellElement.data('message-truncated', 'true');
$messageCellElement.text(`${originalMessage.substr(0, (MAX_MESSAGE_LENGTH - 3))}...`); $messageCellElement.text(`${originalMessage.substr(0, (MAX_MESSAGE_LENGTH - 3))}...`);
}
} }
} }
}
global.AbuseReports = AbuseReports; window.gl = window.gl || {};
})(window.gl || (window.gl = {})); window.gl.AbuseReports = AbuseReports;
...@@ -2,36 +2,35 @@ ...@@ -2,36 +2,35 @@
/* global Pager */ /* global Pager */
/* global Cookies */ /* global Cookies */
((global) => { class Activities {
class Activities { constructor() {
constructor() { Pager.init(20, true, false, this.updateTooltips);
Pager.init(20, true, false, this.updateTooltips); $('.event-filter-link').on('click', (e) => {
$('.event-filter-link').on('click', (e) => { e.preventDefault();
e.preventDefault(); this.toggleFilter(e.currentTarget);
this.toggleFilter(e.currentTarget); this.reloadActivities();
this.reloadActivities(); });
}); }
}
updateTooltips() { updateTooltips() {
gl.utils.localTimeAgo($('.js-timeago', '.content_list')); gl.utils.localTimeAgo($('.js-timeago', '.content_list'));
} }
reloadActivities() { reloadActivities() {
$('.content_list').html(''); $('.content_list').html('');
Pager.init(20, true, false, this.updateTooltips); Pager.init(20, true, false, this.updateTooltips);
} }
toggleFilter(sender) { toggleFilter(sender) {
const $sender = $(sender); const $sender = $(sender);
const filter = $sender.attr('id').split('_')[0]; const filter = $sender.attr('id').split('_')[0];
$('.event-filter .active').removeClass('active'); $('.event-filter .active').removeClass('active');
Cookies.set('event_filter', filter); Cookies.set('event_filter', filter);
$sender.closest('li').toggleClass('active'); $sender.closest('li').toggleClass('active');
}
} }
}
global.Activities = Activities; window.gl = window.gl || {};
})(window.gl || (window.gl = {})); window.gl.Activities = Activities;
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, no-unused-vars, no-else-return, prefer-arrow-callback, camelcase, quotes, comma-dangle, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, no-unused-vars, no-else-return, prefer-arrow-callback, camelcase, quotes, comma-dangle, max-len */
(function() { window.Admin = (function() {
this.Admin = (function() { function Admin() {
function Admin() { var modal, showBlacklistType;
var modal, showBlacklistType; $('input#user_force_random_password').on('change', function(elem) {
$('input#user_force_random_password').on('change', function(elem) { var elems;
var elems; elems = $('#user_password, #user_password_confirmation');
elems = $('#user_password, #user_password_confirmation'); if ($(this).attr('checked')) {
if ($(this).attr('checked')) { return elems.val('').attr('disabled', true);
return elems.val('').attr('disabled', true); } else {
} else { return elems.removeAttr('disabled');
return elems.removeAttr('disabled'); }
} });
}); $('body').on('click', '.js-toggle-colors-link', function(e) {
$('body').on('click', '.js-toggle-colors-link', function(e) { e.preventDefault();
e.preventDefault(); return $('.js-toggle-colors-container').toggle();
return $('.js-toggle-colors-container').toggle(); });
}); $('.log-tabs a').click(function(e) {
$('.log-tabs a').click(function(e) { e.preventDefault();
e.preventDefault(); return $(this).tab('show');
return $(this).tab('show'); });
}); $('.log-bottom').click(function(e) {
$('.log-bottom').click(function(e) { var visible_log;
var visible_log; e.preventDefault();
e.preventDefault(); visible_log = $(".file-content:visible");
visible_log = $(".file-content:visible"); return visible_log.animate({
return visible_log.animate({ scrollTop: visible_log.find('ol').height()
scrollTop: visible_log.find('ol').height() }, "fast");
}, "fast"); });
}); modal = $('.change-owner-holder');
modal = $('.change-owner-holder'); $('.change-owner-link').bind("click", function(e) {
$('.change-owner-link').bind("click", function(e) { e.preventDefault();
e.preventDefault(); $(this).hide();
$(this).hide(); return modal.show();
return modal.show(); });
}); $('.change-owner-cancel-link').bind("click", function(e) {
$('.change-owner-cancel-link').bind("click", function(e) { e.preventDefault();
e.preventDefault(); modal.hide();
modal.hide(); return $('.change-owner-link').show();
return $('.change-owner-link').show(); });
}); $('li.project_member').bind('ajax:success', function() {
$('li.project_member').bind('ajax:success', function() { return gl.utils.refreshCurrentPage();
return gl.utils.refreshCurrentPage(); });
}); $('li.group_member').bind('ajax:success', function() {
$('li.group_member').bind('ajax:success', function() { return gl.utils.refreshCurrentPage();
return gl.utils.refreshCurrentPage(); });
}); showBlacklistType = function() {
showBlacklistType = function() { if ($("input[name='blacklist_type']:checked").val() === 'file') {
if ($("input[name='blacklist_type']:checked").val() === 'file') { $('.blacklist-file').show();
$('.blacklist-file').show(); return $('.blacklist-raw').hide();
return $('.blacklist-raw').hide(); } else {
} else { $('.blacklist-file').hide();
$('.blacklist-file').hide(); return $('.blacklist-raw').show();
return $('.blacklist-raw').show(); }
} };
}; $("input[name='blacklist_type']").click(showBlacklistType);
$("input[name='blacklist_type']").click(showBlacklistType); showBlacklistType();
showBlacklistType(); }
}
return Admin; return Admin;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, quotes, object-shorthand, camelcase, no-var, comma-dangle, prefer-arrow-callback, quote-props, no-param-reassign, max-len */ /* eslint-disable func-names, space-before-function-paren, quotes, object-shorthand, camelcase, no-var, comma-dangle, prefer-arrow-callback, quote-props, no-param-reassign, max-len */
(function() { var Api = {
var Api = { groupsPath: "/api/:version/groups.json",
groupsPath: "/api/:version/groups.json", groupPath: "/api/:version/groups/:id.json",
groupPath: "/api/:version/groups/:id.json", namespacesPath: "/api/:version/namespaces.json",
namespacesPath: "/api/:version/namespaces.json", groupProjectsPath: "/api/:version/groups/:id/projects.json",
groupProjectsPath: "/api/:version/groups/:id/projects.json", projectsPath: "/api/:version/projects.json?simple=true",
projectsPath: "/api/:version/projects.json?simple=true", labelsPath: "/:namespace_path/:project_path/labels",
labelsPath: "/:namespace_path/:project_path/labels", licensePath: "/api/:version/templates/licenses/:key",
licensePath: "/api/:version/templates/licenses/:key", gitignorePath: "/api/:version/templates/gitignores/:key",
gitignorePath: "/api/:version/templates/gitignores/:key", gitlabCiYmlPath: "/api/:version/templates/gitlab_ci_ymls/:key",
gitlabCiYmlPath: "/api/:version/templates/gitlab_ci_ymls/:key", dockerfilePath: "/api/:version/templates/dockerfiles/:key",
dockerfilePath: "/api/:version/templates/dockerfiles/:key", issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key",
issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key", group: function(group_id, callback) {
group: function(group_id, callback) { var url = Api.buildUrl(Api.groupPath)
var url = Api.buildUrl(Api.groupPath) .replace(':id', group_id);
.replace(':id', group_id); return $.ajax({
return $.ajax({ url: url,
url: url, dataType: "json"
dataType: "json" }).done(function(group) {
}).done(function(group) { return callback(group);
return callback(group); });
}); },
}, // Return groups list. Filtered by query
// Return groups list. Filtered by query groups: function(query, options, callback) {
groups: function(query, options, callback) { var url = Api.buildUrl(Api.groupsPath);
var url = Api.buildUrl(Api.groupsPath); return $.ajax({
return $.ajax({ url: url,
url: url, data: $.extend({
data: $.extend({ search: query,
search: query, per_page: 20
per_page: 20 }, options),
}, options), dataType: "json"
dataType: "json" }).done(function(groups) {
}).done(function(groups) { return callback(groups);
return callback(groups); });
}); },
}, // Return namespaces list. Filtered by query
// Return namespaces list. Filtered by query namespaces: function(query, callback) {
namespaces: function(query, callback) { var url = Api.buildUrl(Api.namespacesPath);
var url = Api.buildUrl(Api.namespacesPath); return $.ajax({
return $.ajax({ url: url,
url: url, data: {
data: { search: query,
search: query, per_page: 20
per_page: 20 },
}, dataType: "json"
dataType: "json" }).done(function(namespaces) {
}).done(function(namespaces) { return callback(namespaces);
return callback(namespaces); });
}); },
}, // Return projects list. Filtered by query
// Return projects list. Filtered by query projects: function(query, order, callback) {
projects: function(query, order, callback) { var url = Api.buildUrl(Api.projectsPath);
var url = Api.buildUrl(Api.projectsPath); return $.ajax({
return $.ajax({ url: url,
url: url, data: {
data: { search: query,
search: query, order_by: order,
order_by: order, per_page: 20
per_page: 20 },
}, dataType: "json"
dataType: "json" }).done(function(projects) {
}).done(function(projects) { return callback(projects);
return callback(projects); });
}); },
}, newLabel: function(namespace_path, project_path, data, callback) {
newLabel: function(namespace_path, project_path, data, callback) { var url = Api.buildUrl(Api.labelsPath)
var url = Api.buildUrl(Api.labelsPath) .replace(':namespace_path', namespace_path)
.replace(':namespace_path', namespace_path) .replace(':project_path', project_path);
.replace(':project_path', project_path); return $.ajax({
return $.ajax({ url: url,
url: url, type: "POST",
type: "POST", data: { 'label': data },
data: { 'label': data }, dataType: "json"
dataType: "json" }).done(function(label) {
}).done(function(label) { return callback(label);
return callback(label); }).error(function(message) {
}).error(function(message) { return callback(message.responseJSON);
return callback(message.responseJSON); });
}); },
}, // Return group projects list. Filtered by query
// Return group projects list. Filtered by query groupProjects: function(group_id, query, callback) {
groupProjects: function(group_id, query, callback) { var url = Api.buildUrl(Api.groupProjectsPath)
var url = Api.buildUrl(Api.groupProjectsPath) .replace(':id', group_id);
.replace(':id', group_id); return $.ajax({
return $.ajax({ url: url,
url: url, data: {
data: { search: query,
search: query, per_page: 20
per_page: 20 },
}, dataType: "json"
dataType: "json" }).done(function(projects) {
}).done(function(projects) { return callback(projects);
return callback(projects); });
}); },
}, // Return text for a specific license
// Return text for a specific license licenseText: function(key, data, callback) {
licenseText: function(key, data, callback) { var url = Api.buildUrl(Api.licensePath)
var url = Api.buildUrl(Api.licensePath) .replace(':key', key);
.replace(':key', key); return $.ajax({
return $.ajax({ url: url,
url: url, data: data
data: data }).done(function(license) {
}).done(function(license) { return callback(license);
return callback(license); });
}); },
}, gitignoreText: function(key, callback) {
gitignoreText: function(key, callback) { var url = Api.buildUrl(Api.gitignorePath)
var url = Api.buildUrl(Api.gitignorePath) .replace(':key', key);
.replace(':key', key); return $.get(url, function(gitignore) {
return $.get(url, function(gitignore) { return callback(gitignore);
return callback(gitignore); });
}); },
}, gitlabCiYml: function(key, callback) {
gitlabCiYml: function(key, callback) { var url = Api.buildUrl(Api.gitlabCiYmlPath)
var url = Api.buildUrl(Api.gitlabCiYmlPath) .replace(':key', key);
.replace(':key', key); return $.get(url, function(file) {
return $.get(url, function(file) { return callback(file);
return callback(file); });
}); },
}, dockerfileYml: function(key, callback) {
dockerfileYml: function(key, callback) { var url = Api.buildUrl(Api.dockerfilePath).replace(':key', key);
var url = Api.buildUrl(Api.dockerfilePath).replace(':key', key); $.get(url, callback);
$.get(url, callback); },
}, issueTemplate: function(namespacePath, projectPath, key, type, callback) {
issueTemplate: function(namespacePath, projectPath, key, type, callback) { var url = Api.buildUrl(Api.issuableTemplatePath)
var url = Api.buildUrl(Api.issuableTemplatePath) .replace(':key', key)
.replace(':key', key) .replace(':type', type)
.replace(':type', type) .replace(':project_path', projectPath)
.replace(':project_path', projectPath) .replace(':namespace_path', namespacePath);
.replace(':namespace_path', namespacePath); $.ajax({
$.ajax({ url: url,
url: url, dataType: 'json'
dataType: 'json' }).done(function(file) {
}).done(function(file) { callback(null, file);
callback(null, file); }).error(callback);
}).error(callback); },
}, buildUrl: function(url) {
buildUrl: function(url) { if (gon.relative_url_root != null) {
if (gon.relative_url_root != null) { url = gon.relative_url_root + url;
url = gon.relative_url_root + url;
}
return url.replace(':version', gon.api_version);
} }
}; return url.replace(':version', gon.api_version);
}
};
window.Api = Api; window.Api = Api;
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, prefer-arrow-callback, no-var, one-var, one-var-declaration-per-line, no-else-return, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, prefer-arrow-callback, no-var, one-var, one-var-declaration-per-line, no-else-return, max-len */
(function() {
this.Aside = (function() {
function Aside() {
$(document).off("click", "a.show-aside");
$(document).on("click", 'a.show-aside', function(e) {
var btn, icon;
e.preventDefault();
btn = $(e.currentTarget);
icon = btn.find('i');
if (icon.hasClass('fa-angle-left')) {
btn.parent().find('section').hide();
btn.parent().find('aside').fadeIn();
return icon.removeClass('fa-angle-left').addClass('fa-angle-right');
} else {
btn.parent().find('aside').hide();
btn.parent().find('section').fadeIn();
return icon.removeClass('fa-angle-right').addClass('fa-angle-left');
}
});
}
return Aside; window.Aside = (function() {
})(); function Aside() {
}).call(window); $(document).off("click", "a.show-aside");
$(document).on("click", 'a.show-aside', function(e) {
var btn, icon;
e.preventDefault();
btn = $(e.currentTarget);
icon = btn.find('i');
if (icon.hasClass('fa-angle-left')) {
btn.parent().find('section').hide();
btn.parent().find('aside').fadeIn();
return icon.removeClass('fa-angle-left').addClass('fa-angle-right');
} else {
btn.parent().find('aside').hide();
btn.parent().find('section').fadeIn();
return icon.removeClass('fa-angle-right').addClass('fa-angle-left');
}
});
}
return Aside;
})();
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-param-reassign, quotes, prefer-template, no-var, one-var, no-unused-vars, one-var-declaration-per-line, no-void, consistent-return, no-empty, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-param-reassign, quotes, prefer-template, no-var, one-var, no-unused-vars, one-var-declaration-per-line, no-void, consistent-return, no-empty, max-len */
(function() {
this.Autosave = (function() {
function Autosave(field, key) {
this.field = field;
if (key.join != null) {
key = key.join("/");
}
this.key = "autosave/" + key;
this.field.data("autosave", this);
this.restore();
this.field.on("input", (function(_this) {
return function() {
return _this.save();
};
})(this));
}
Autosave.prototype.restore = function() { window.Autosave = (function() {
var e, text; function Autosave(field, key) {
if (window.localStorage == null) { this.field = field;
return; if (key.join != null) {
} key = key.join("/");
try { }
text = window.localStorage.getItem(this.key); this.key = "autosave/" + key;
} catch (error) { this.field.data("autosave", this);
e = error; this.restore();
return; this.field.on("input", (function(_this) {
} return function() {
if ((text != null ? text.length : void 0) > 0) { return _this.save();
this.field.val(text); };
} })(this));
return this.field.trigger("input"); }
};
Autosave.prototype.save = function() { Autosave.prototype.restore = function() {
var text; var e, text;
if (window.localStorage == null) { if (window.localStorage == null) {
return; return;
} }
text = this.field.val(); try {
if ((text != null ? text.length : void 0) > 0) { text = window.localStorage.getItem(this.key);
try { } catch (error) {
return window.localStorage.setItem(this.key, text); e = error;
} catch (error) {} return;
} else { }
return this.reset(); if ((text != null ? text.length : void 0) > 0) {
} this.field.val(text);
}; }
return this.field.trigger("input");
};
Autosave.prototype.reset = function() { Autosave.prototype.save = function() {
if (window.localStorage == null) { var text;
return; if (window.localStorage == null) {
} return;
}
text = this.field.val();
if ((text != null ? text.length : void 0) > 0) {
try { try {
return window.localStorage.removeItem(this.key); return window.localStorage.setItem(this.key, text);
} catch (error) {} } catch (error) {}
}; } else {
return this.reset();
}
};
Autosave.prototype.reset = function() {
if (window.localStorage == null) {
return;
}
try {
return window.localStorage.removeItem(this.key);
} catch (error) {}
};
return Autosave; return Autosave;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, quotes, no-shadow, prefer-arrow-callback, prefer-template, consistent-return, no-return-assign, new-parens, no-param-reassign, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, one-var-declaration-per-line, quotes, no-shadow, prefer-arrow-callback, prefer-template, consistent-return, no-return-assign, new-parens, no-param-reassign, max-len */
(function() { var Breakpoints = (function() {
var Breakpoints = (function() { var BreakpointInstance, instance;
var BreakpointInstance, instance;
function Breakpoints() {} function Breakpoints() {}
instance = null; instance = null;
BreakpointInstance = (function() { BreakpointInstance = (function() {
var BREAKPOINTS; var BREAKPOINTS;
BREAKPOINTS = ["xs", "sm", "md", "lg"]; BREAKPOINTS = ["xs", "sm", "md", "lg"];
function BreakpointInstance() { function BreakpointInstance() {
this.setup(); this.setup();
} }
BreakpointInstance.prototype.setup = function() {
var allDeviceSelector, els;
allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
return ".device-" + breakpoint;
});
if ($(allDeviceSelector.join(",")).length) {
return;
}
// Create all the elements
els = $.map(BREAKPOINTS, function(breakpoint) {
return "<div class='device-" + breakpoint + " visible-" + breakpoint + "'></div>";
});
return $("body").append(els.join(''));
};
BreakpointInstance.prototype.visibleDevice = function() { BreakpointInstance.prototype.setup = function() {
var allDeviceSelector; var allDeviceSelector, els;
allDeviceSelector = BREAKPOINTS.map(function(breakpoint) { allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
return ".device-" + breakpoint; return ".device-" + breakpoint;
}); });
return $(allDeviceSelector.join(",")).filter(":visible"); if ($(allDeviceSelector.join(",")).length) {
}; return;
}
BreakpointInstance.prototype.getBreakpointSize = function() { // Create all the elements
var $visibleDevice; els = $.map(BREAKPOINTS, function(breakpoint) {
$visibleDevice = this.visibleDevice; return "<div class='device-" + breakpoint + " visible-" + breakpoint + "'></div>";
// TODO: Consider refactoring in light of turbolinks removal. });
// the page refreshed via turbolinks return $("body").append(els.join(''));
if (!$visibleDevice().length) { };
this.setup();
}
$visibleDevice = this.visibleDevice();
return $visibleDevice.attr("class").split("visible-")[1];
};
return BreakpointInstance; BreakpointInstance.prototype.visibleDevice = function() {
})(); var allDeviceSelector;
allDeviceSelector = BREAKPOINTS.map(function(breakpoint) {
return ".device-" + breakpoint;
});
return $(allDeviceSelector.join(",")).filter(":visible");
};
Breakpoints.get = function() { BreakpointInstance.prototype.getBreakpointSize = function() {
return instance != null ? instance : instance = new BreakpointInstance; var $visibleDevice;
$visibleDevice = this.visibleDevice;
// TODO: Consider refactoring in light of turbolinks removal.
// the page refreshed via turbolinks
if (!$visibleDevice().length) {
this.setup();
}
$visibleDevice = this.visibleDevice();
return $visibleDevice.attr("class").split("visible-")[1];
}; };
return Breakpoints; return BreakpointInstance;
})(); })();
$((function(_this) { Breakpoints.get = function() {
return function() { return instance != null ? instance : instance = new BreakpointInstance;
return _this.bp = Breakpoints.get(); };
};
})(this)); return Breakpoints;
})();
$(() => { window.bp = Breakpoints.get(); });
window.Breakpoints = Breakpoints; window.Breakpoints = Breakpoints;
}).call(window);
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, no-else-return, object-shorthand, comma-dangle, max-len */ /* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, quotes, no-else-return, object-shorthand, comma-dangle, max-len */
(function() {
$(function() { $(function() {
var previewPath; var previewPath;
$('input#broadcast_message_color').on('input', function() { $('input#broadcast_message_color').on('input', function() {
var previewColor; var previewColor;
previewColor = $(this).val(); previewColor = $(this).val();
return $('div.broadcast-message-preview').css('background-color', previewColor); return $('div.broadcast-message-preview').css('background-color', previewColor);
}); });
$('input#broadcast_message_font').on('input', function() { $('input#broadcast_message_font').on('input', function() {
var previewColor; var previewColor;
previewColor = $(this).val(); previewColor = $(this).val();
return $('div.broadcast-message-preview').css('color', previewColor); return $('div.broadcast-message-preview').css('color', previewColor);
}); });
previewPath = $('textarea#broadcast_message_message').data('preview-path'); previewPath = $('textarea#broadcast_message_message').data('preview-path');
return $('textarea#broadcast_message_message').on('input', function() { return $('textarea#broadcast_message_message').on('input', function() {
var message; var message;
message = $(this).val(); message = $(this).val();
if (message === '') { if (message === '') {
return $('.js-broadcast-message-preview').text("Your message here"); return $('.js-broadcast-message-preview').text("Your message here");
} else { } else {
return $.ajax({ return $.ajax({
url: previewPath, url: previewPath,
type: "POST", type: "POST",
data: { data: {
broadcast_message: { broadcast_message: {
message: message message: message
}
} }
}); }
} });
}); }
}); });
}).call(window); });
This diff is collapsed.
/* eslint-disable func-names, space-before-function-paren, wrap-iife, prefer-arrow-callback, no-unused-vars, no-return-assign, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, prefer-arrow-callback, no-unused-vars, no-return-assign, max-len */
(function() {
this.BuildArtifacts = (function() {
function BuildArtifacts() {
this.disablePropagation();
this.setupEntryClick();
}
BuildArtifacts.prototype.disablePropagation = function() { window.BuildArtifacts = (function() {
$('.top-block').on('click', '.download', function(e) { function BuildArtifacts() {
return e.stopPropagation(); this.disablePropagation();
}); this.setupEntryClick();
return $('.tree-holder').on('click', 'tr[data-link] a', function(e) { }
return e.stopImmediatePropagation();
});
};
BuildArtifacts.prototype.setupEntryClick = function() { BuildArtifacts.prototype.disablePropagation = function() {
return $('.tree-holder').on('click', 'tr[data-link]', function(e) { $('.top-block').on('click', '.download', function(e) {
return window.location = this.dataset.link; return e.stopPropagation();
}); });
}; return $('.tree-holder').on('click', 'tr[data-link] a', function(e) {
return e.stopImmediatePropagation();
});
};
return BuildArtifacts; BuildArtifacts.prototype.setupEntryClick = function() {
})(); return $('.tree-holder').on('click', 'tr[data-link]', function(e) {
}).call(window); return window.location = this.dataset.link;
});
};
return BuildArtifacts;
})();
(() => {
window.gl = window.gl || {};
class CILintEditor { window.gl = window.gl || {};
constructor() {
this.editor = window.ace.edit('ci-editor');
this.textarea = document.querySelector('#content');
this.editor.getSession().setMode('ace/mode/yaml'); class CILintEditor {
this.editor.on('input', () => { constructor() {
const content = this.editor.getSession().getValue(); this.editor = window.ace.edit('ci-editor');
this.textarea.value = content; this.textarea = document.querySelector('#content');
});
} this.editor.getSession().setMode('ace/mode/yaml');
this.editor.on('input', () => {
const content = this.editor.getSession().getValue();
this.textarea.value = content;
});
} }
}
gl.CILintEditor = CILintEditor; gl.CILintEditor = CILintEditor;
})();
/* eslint-disable func-names, space-before-function-paren, wrap-iife */ /* eslint-disable func-names, space-before-function-paren, wrap-iife */
/* global CommitFile */ /* global CommitFile */
(function() { window.Commit = (function() {
this.Commit = (function() { function Commit() {
function Commit() { $('.files .diff-file').each(function() {
$('.files .diff-file').each(function() { return new CommitFile(this);
return new CommitFile(this); });
}); }
}
return Commit; return Commit;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, consistent-return, no-return-assign, no-param-reassign, one-var, no-var, one-var-declaration-per-line, no-unused-vars, prefer-template, object-shorthand, comma-dangle, max-len, prefer-arrow-callback */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, consistent-return, no-return-assign, no-param-reassign, one-var, no-var, one-var-declaration-per-line, no-unused-vars, prefer-template, object-shorthand, comma-dangle, max-len, prefer-arrow-callback */
/* global Pager */ /* global Pager */
(function() { window.CommitsList = (function() {
this.CommitsList = (function() { var CommitsList = {};
var CommitsList = {};
CommitsList.timer = null; CommitsList.timer = null;
CommitsList.init = function(limit) { CommitsList.init = function(limit) {
$("body").on("click", ".day-commits-table li.commit", function(e) { $("body").on("click", ".day-commits-table li.commit", function(e) {
if (e.target.nodeName !== "A") { if (e.target.nodeName !== "A") {
location.href = $(this).attr("url"); location.href = $(this).attr("url");
e.stopPropagation(); e.stopPropagation();
return false; return false;
} }
}); });
Pager.init(limit, false, false, function() { Pager.init(limit, false, false, function() {
gl.utils.localTimeAgo($('.js-timeago')); gl.utils.localTimeAgo($('.js-timeago'));
}); });
this.content = $("#commits-list"); this.content = $("#commits-list");
this.searchField = $("#commits-search"); this.searchField = $("#commits-search");
this.lastSearch = this.searchField.val(); this.lastSearch = this.searchField.val();
return this.initSearch(); return this.initSearch();
}; };
CommitsList.initSearch = function() { CommitsList.initSearch = function() {
this.timer = null; this.timer = null;
return this.searchField.keyup((function(_this) { return this.searchField.keyup((function(_this) {
return function() { return function() {
clearTimeout(_this.timer); clearTimeout(_this.timer);
return _this.timer = setTimeout(_this.filterResults, 500); return _this.timer = setTimeout(_this.filterResults, 500);
}; };
})(this)); })(this));
}; };
CommitsList.filterResults = function() { CommitsList.filterResults = function() {
var commitsUrl, form, search; var commitsUrl, form, search;
form = $(".commits-search-form"); form = $(".commits-search-form");
search = CommitsList.searchField.val(); search = CommitsList.searchField.val();
if (search === CommitsList.lastSearch) return; if (search === CommitsList.lastSearch) return;
commitsUrl = form.attr("action") + '?' + form.serialize(); commitsUrl = form.attr("action") + '?' + form.serialize();
CommitsList.content.fadeTo('fast', 0.5); CommitsList.content.fadeTo('fast', 0.5);
return $.ajax({ return $.ajax({
type: "GET", type: "GET",
url: form.attr("action"), url: form.attr("action"),
data: form.serialize(), data: form.serialize(),
complete: function() { complete: function() {
return CommitsList.content.fadeTo('fast', 1.0); return CommitsList.content.fadeTo('fast', 1.0);
}, },
success: function(data) { success: function(data) {
CommitsList.lastSearch = search; CommitsList.lastSearch = search;
CommitsList.content.html(data.html); CommitsList.content.html(data.html);
return history.replaceState({ return history.replaceState({
page: commitsUrl page: commitsUrl
// Change url so if user reload a page - search results are saved // Change url so if user reload a page - search results are saved
}, document.title, commitsUrl); }, document.title, commitsUrl);
}, },
error: function() { error: function() {
CommitsList.lastSearch = null; CommitsList.lastSearch = null;
}, },
dataType: "json" dataType: "json"
}); });
}; };
return CommitsList; return CommitsList;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, object-shorthand, consistent-return, no-unused-vars, comma-dangle, vars-on-top, prefer-template, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, object-shorthand, consistent-return, no-unused-vars, comma-dangle, vars-on-top, prefer-template, max-len */
(function() {
this.Compare = (function() { window.Compare = (function() {
function Compare(opts) { function Compare(opts) {
this.opts = opts; this.opts = opts;
this.source_loading = $(".js-source-loading"); this.source_loading = $(".js-source-loading");
this.target_loading = $(".js-target-loading"); this.target_loading = $(".js-target-loading");
$('.js-compare-dropdown').each((function(_this) { $('.js-compare-dropdown').each((function(_this) {
return function(i, dropdown) { return function(i, dropdown) {
var $dropdown; var $dropdown;
$dropdown = $(dropdown); $dropdown = $(dropdown);
return $dropdown.glDropdown({ return $dropdown.glDropdown({
selectable: true, selectable: true,
fieldName: $dropdown.data('field-name'), fieldName: $dropdown.data('field-name'),
filterable: true, filterable: true,
id: function(obj, $el) { id: function(obj, $el) {
return $el.data('id'); return $el.data('id');
}, },
toggleLabel: function(obj, $el) { toggleLabel: function(obj, $el) {
return $el.text().trim(); return $el.text().trim();
}, },
clicked: function(e, el) { clicked: function(e, el) {
if ($dropdown.is('.js-target-branch')) { if ($dropdown.is('.js-target-branch')) {
return _this.getTargetHtml(); return _this.getTargetHtml();
} else if ($dropdown.is('.js-source-branch')) { } else if ($dropdown.is('.js-source-branch')) {
return _this.getSourceHtml(); return _this.getSourceHtml();
} else if ($dropdown.is('.js-target-project')) { } else if ($dropdown.is('.js-target-project')) {
return _this.getTargetProject(); return _this.getTargetProject();
}
} }
}); }
}; });
})(this)); };
this.initialState(); })(this));
} this.initialState();
}
Compare.prototype.initialState = function() { Compare.prototype.initialState = function() {
this.getSourceHtml(); this.getSourceHtml();
return this.getTargetHtml(); return this.getTargetHtml();
}; };
Compare.prototype.getTargetProject = function() { Compare.prototype.getTargetProject = function() {
return $.ajax({ return $.ajax({
url: this.opts.targetProjectUrl, url: this.opts.targetProjectUrl,
data: { data: {
target_project_id: $("input[name='merge_request[target_project_id]']").val() target_project_id: $("input[name='merge_request[target_project_id]']").val()
}, },
beforeSend: function() { beforeSend: function() {
return $('.mr_target_commit').empty(); return $('.mr_target_commit').empty();
}, },
success: function(html) { success: function(html) {
return $('.js-target-branch-dropdown .dropdown-content').html(html); return $('.js-target-branch-dropdown .dropdown-content').html(html);
} }
}); });
}; };
Compare.prototype.getSourceHtml = function() { Compare.prototype.getSourceHtml = function() {
return this.sendAjax(this.opts.sourceBranchUrl, this.source_loading, '.mr_source_commit', { return this.sendAjax(this.opts.sourceBranchUrl, this.source_loading, '.mr_source_commit', {
ref: $("input[name='merge_request[source_branch]']").val() ref: $("input[name='merge_request[source_branch]']").val()
}); });
}; };
Compare.prototype.getTargetHtml = function() { Compare.prototype.getTargetHtml = function() {
return this.sendAjax(this.opts.targetBranchUrl, this.target_loading, '.mr_target_commit', { return this.sendAjax(this.opts.targetBranchUrl, this.target_loading, '.mr_target_commit', {
target_project_id: $("input[name='merge_request[target_project_id]']").val(), target_project_id: $("input[name='merge_request[target_project_id]']").val(),
ref: $("input[name='merge_request[target_branch]']").val() ref: $("input[name='merge_request[target_branch]']").val()
}); });
}; };
Compare.prototype.sendAjax = function(url, loading, target, data) { Compare.prototype.sendAjax = function(url, loading, target, data) {
var $target; var $target;
$target = $(target); $target = $(target);
return $.ajax({ return $.ajax({
url: url, url: url,
data: data, data: data,
beforeSend: function() { beforeSend: function() {
loading.show(); loading.show();
return $target.empty(); return $target.empty();
}, },
success: function(html) { success: function(html) {
loading.hide(); loading.hide();
$target.html(html); $target.html(html);
var className = '.' + $target[0].className.replace(' ', '.'); var className = '.' + $target[0].className.replace(' ', '.');
gl.utils.localTimeAgo($('.js-timeago', className)); gl.utils.localTimeAgo($('.js-timeago', className));
} }
}); });
}; };
return Compare; return Compare;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, object-shorthand, comma-dangle, prefer-arrow-callback, no-else-return, newline-per-chained-call, wrap-iife, max-len */ /* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, object-shorthand, comma-dangle, prefer-arrow-callback, no-else-return, newline-per-chained-call, wrap-iife, max-len */
(function() { window.CompareAutocomplete = (function() {
this.CompareAutocomplete = (function() { function CompareAutocomplete() {
function CompareAutocomplete() { this.initDropdown();
this.initDropdown(); }
}
CompareAutocomplete.prototype.initDropdown = function() { CompareAutocomplete.prototype.initDropdown = function() {
return $('.js-compare-dropdown').each(function() { return $('.js-compare-dropdown').each(function() {
var $dropdown, selected; var $dropdown, selected;
$dropdown = $(this); $dropdown = $(this);
selected = $dropdown.data('selected'); selected = $dropdown.data('selected');
const $dropdownContainer = $dropdown.closest('.dropdown'); const $dropdownContainer = $dropdown.closest('.dropdown');
const $fieldInput = $(`input[name="${$dropdown.data('field-name')}"]`, $dropdownContainer); const $fieldInput = $(`input[name="${$dropdown.data('field-name')}"]`, $dropdownContainer);
const $filterInput = $('input[type="search"]', $dropdownContainer); const $filterInput = $('input[type="search"]', $dropdownContainer);
$dropdown.glDropdown({ $dropdown.glDropdown({
data: function(term, callback) { data: function(term, callback) {
return $.ajax({ return $.ajax({
url: $dropdown.data('refs-url'), url: $dropdown.data('refs-url'),
data: { data: {
ref: $dropdown.data('ref') ref: $dropdown.data('ref')
}
}).done(function(refs) {
return callback(refs);
});
},
selectable: true,
filterable: true,
filterByText: true,
fieldName: $dropdown.data('field-name'),
filterInput: 'input[type="search"]',
renderRow: function(ref) {
var link;
if (ref.header != null) {
return $('<li />').addClass('dropdown-header').text(ref.header);
} else {
link = $('<a />').attr('href', '#').addClass(ref === selected ? 'is-active' : '').text(ref).attr('data-ref', escape(ref));
return $('<li />').append(link);
} }
}, }).done(function(refs) {
id: function(obj, $el) { return callback(refs);
return $el.attr('data-ref'); });
}, },
toggleLabel: function(obj, $el) { selectable: true,
return $el.text().trim(); filterable: true,
filterByText: true,
fieldName: $dropdown.data('field-name'),
filterInput: 'input[type="search"]',
renderRow: function(ref) {
var link;
if (ref.header != null) {
return $('<li />').addClass('dropdown-header').text(ref.header);
} else {
link = $('<a />').attr('href', '#').addClass(ref === selected ? 'is-active' : '').text(ref).attr('data-ref', escape(ref));
return $('<li />').append(link);
} }
}); },
$filterInput.on('keyup', (e) => { id: function(obj, $el) {
const keyCode = e.keyCode || e.which; return $el.attr('data-ref');
if (keyCode !== 13) return; },
const text = $filterInput.val(); toggleLabel: function(obj, $el) {
$fieldInput.val(text); return $el.text().trim();
$('.dropdown-toggle-text', $dropdown).text(text); }
$dropdownContainer.removeClass('open'); });
}); $filterInput.on('keyup', (e) => {
const keyCode = e.keyCode || e.which;
if (keyCode !== 13) return;
const text = $filterInput.val();
$fieldInput.val(text);
$('.dropdown-toggle-text', $dropdown).text(text);
$dropdownContainer.removeClass('open');
});
$dropdownContainer.on('click', '.dropdown-content a', (e) => { $dropdownContainer.on('click', '.dropdown-content a', (e) => {
$dropdown.prop('title', e.target.text.replace(/_+?/g, '-')); $dropdown.prop('title', e.target.text.replace(/_+?/g, '-'));
if ($dropdown.hasClass('has-tooltip')) { if ($dropdown.hasClass('has-tooltip')) {
$dropdown.tooltip('fixTitle'); $dropdown.tooltip('fixTitle');
} }
});
}); });
}; });
};
return CompareAutocomplete; return CompareAutocomplete;
})(); })();
}).call(window);
/* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, camelcase, one-var-declaration-per-line, no-else-return, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, one-var, no-var, camelcase, one-var-declaration-per-line, no-else-return, max-len */
(function() {
this.ConfirmDangerModal = (function() {
function ConfirmDangerModal(form, text) {
var project_path, submit;
this.form = form;
$('.js-confirm-text').text(text || '');
$('.js-confirm-danger-input').val('');
$('#modal-confirm-danger').modal('show');
project_path = $('.js-confirm-danger-match').text();
submit = $('.js-confirm-danger-submit');
submit.disable();
$('.js-confirm-danger-input').off('input');
$('.js-confirm-danger-input').on('input', function() {
if (gl.utils.rstrip($(this).val()) === project_path) {
return submit.enable();
} else {
return submit.disable();
}
});
$('.js-confirm-danger-submit').off('click');
$('.js-confirm-danger-submit').on('click', (function(_this) {
return function() {
return _this.form.submit();
};
})(this));
}
return ConfirmDangerModal; window.ConfirmDangerModal = (function() {
})(); function ConfirmDangerModal(form, text) {
}).call(window); var project_path, submit;
this.form = form;
$('.js-confirm-text').text(text || '');
$('.js-confirm-danger-input').val('');
$('#modal-confirm-danger').modal('show');
project_path = $('.js-confirm-danger-match').text();
submit = $('.js-confirm-danger-submit');
submit.disable();
$('.js-confirm-danger-input').off('input');
$('.js-confirm-danger-input').on('input', function() {
if (gl.utils.rstrip($(this).val()) === project_path) {
return submit.enable();
} else {
return submit.disable();
}
});
$('.js-confirm-danger-submit').off('click');
$('.js-confirm-danger-submit').on('click', (function(_this) {
return function() {
return _this.form.submit();
};
})(this));
}
return ConfirmDangerModal;
})();
This diff is collapsed.
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, prefer-template, quotes, no-unused-vars, prefer-arrow-callback, max-len */ /* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, prefer-template, quotes, no-unused-vars, prefer-arrow-callback, max-len */
/* global Clipboard */
import Clipboard from 'vendor/clipboard';
window.Clipboard = require('vendor/clipboard');
var genericError, genericSuccess, showTooltip;
(function() {
var genericError, genericSuccess, showTooltip; genericSuccess = function(e) {
showTooltip(e.trigger, 'Copied');
genericSuccess = function(e) { // Clear the selection and blur the trigger so it loses its border
showTooltip(e.trigger, 'Copied'); e.clearSelection();
// Clear the selection and blur the trigger so it loses its border return $(e.trigger).blur();
e.clearSelection(); };
return $(e.trigger).blur();
}; // Safari doesn't support `execCommand`, so instead we inform the user to
// copy manually.
// Safari doesn't support `execCommand`, so instead we inform the user to //
// copy manually. // See http://clipboardjs.com/#browser-support
// genericError = function(e) {
// See http://clipboardjs.com/#browser-support var key;
genericError = function(e) { if (/Mac/i.test(navigator.userAgent)) {
var key; key = '&#8984;'; // Command
if (/Mac/i.test(navigator.userAgent)) { } else {
key = '&#8984;'; // Command key = 'Ctrl';
} else { }
key = 'Ctrl'; return showTooltip(e.trigger, "Press " + key + "-C to copy");
} };
return showTooltip(e.trigger, "Press " + key + "-C to copy");
}; showTooltip = function(target, title) {
var $target = $(target);
showTooltip = function(target, title) { var originalTitle = $target.data('original-title');
var $target = $(target);
var originalTitle = $target.data('original-title'); $target
.attr('title', 'Copied')
$target .tooltip('fixTitle')
.attr('title', 'Copied') .tooltip('show')
.tooltip('fixTitle') .attr('title', originalTitle)
.tooltip('show') .tooltip('fixTitle');
.attr('title', originalTitle) };
.tooltip('fixTitle');
}; $(function() {
var clipboard;
$(function() {
var clipboard; clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
clipboard.on('success', genericSuccess);
clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]'); return clipboard.on('error', genericError);
clipboard.on('success', genericSuccess); });
return clipboard.on('error', genericError);
});
}).call(window);
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-param-reassign, wrap-iife, max-len */ /* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-param-reassign, wrap-iife, max-len */
/* global Api */ /* global Api */
(function (w) { class CreateLabelDropdown {
class CreateLabelDropdown { constructor ($el, namespacePath, projectPath) {
constructor ($el, namespacePath, projectPath) { this.$el = $el;
this.$el = $el; this.namespacePath = namespacePath;
this.namespacePath = namespacePath; this.projectPath = projectPath;
this.projectPath = projectPath; this.$dropdownBack = $('.dropdown-menu-back', this.$el.closest('.dropdown'));
this.$dropdownBack = $('.dropdown-menu-back', this.$el.closest('.dropdown')); this.$cancelButton = $('.js-cancel-label-btn', this.$el);
this.$cancelButton = $('.js-cancel-label-btn', this.$el); this.$newLabelField = $('#new_label_name', this.$el);
this.$newLabelField = $('#new_label_name', this.$el); this.$newColorField = $('#new_label_color', this.$el);
this.$newColorField = $('#new_label_color', this.$el); this.$colorPreview = $('.js-dropdown-label-color-preview', this.$el);
this.$colorPreview = $('.js-dropdown-label-color-preview', this.$el); this.$newLabelError = $('.js-label-error', this.$el);
this.$newLabelError = $('.js-label-error', this.$el); this.$newLabelCreateButton = $('.js-new-label-btn', this.$el);
this.$newLabelCreateButton = $('.js-new-label-btn', this.$el); this.$colorSuggestions = $('.suggest-colors-dropdown a', this.$el);
this.$colorSuggestions = $('.suggest-colors-dropdown a', this.$el);
this.$newLabelError.hide();
this.$newLabelError.hide(); this.$newLabelCreateButton.disable();
this.$newLabelCreateButton.disable();
this.cleanBinding();
this.addBinding();
}
this.cleanBinding(); cleanBinding () {
this.addBinding(); this.$colorSuggestions.off('click');
} this.$newLabelField.off('keyup change');
this.$newColorField.off('keyup change');
this.$dropdownBack.off('click');
this.$cancelButton.off('click');
this.$newLabelCreateButton.off('click');
}
cleanBinding () { addBinding () {
this.$colorSuggestions.off('click'); const self = this;
this.$newLabelField.off('keyup change');
this.$newColorField.off('keyup change');
this.$dropdownBack.off('click');
this.$cancelButton.off('click');
this.$newLabelCreateButton.off('click');
}
addBinding () { this.$colorSuggestions.on('click', function (e) {
const self = this; const $this = $(this);
self.addColorValue(e, $this);
});
this.$colorSuggestions.on('click', function (e) { this.$newLabelField.on('keyup change', this.enableLabelCreateButton.bind(this));
const $this = $(this); this.$newColorField.on('keyup change', this.enableLabelCreateButton.bind(this));
self.addColorValue(e, $this);
});
this.$newLabelField.on('keyup change', this.enableLabelCreateButton.bind(this)); this.$dropdownBack.on('click', this.resetForm.bind(this));
this.$newColorField.on('keyup change', this.enableLabelCreateButton.bind(this));
this.$dropdownBack.on('click', this.resetForm.bind(this)); this.$cancelButton.on('click', function(e) {
e.preventDefault();
e.stopPropagation();
this.$cancelButton.on('click', function(e) { self.resetForm();
e.preventDefault(); self.$dropdownBack.trigger('click');
e.stopPropagation(); });
self.resetForm(); this.$newLabelCreateButton.on('click', this.saveLabel.bind(this));
self.$dropdownBack.trigger('click'); }
});
this.$newLabelCreateButton.on('click', this.saveLabel.bind(this)); addColorValue (e, $this) {
} e.preventDefault();
e.stopPropagation();
addColorValue (e, $this) { this.$newColorField.val($this.data('color')).trigger('change');
e.preventDefault(); this.$colorPreview
e.stopPropagation(); .css('background-color', $this.data('color'))
.parent()
.addClass('is-active');
}
this.$newColorField.val($this.data('color')).trigger('change'); enableLabelCreateButton () {
this.$colorPreview if (this.$newLabelField.val() !== '' && this.$newColorField.val() !== '') {
.css('background-color', $this.data('color')) this.$newLabelError.hide();
.parent() this.$newLabelCreateButton.enable();
.addClass('is-active'); } else {
this.$newLabelCreateButton.disable();
} }
}
enableLabelCreateButton () { resetForm () {
if (this.$newLabelField.val() !== '' && this.$newColorField.val() !== '') { this.$newLabelField
this.$newLabelError.hide(); .val('')
this.$newLabelCreateButton.enable(); .trigger('change');
} else {
this.$newLabelCreateButton.disable();
}
}
resetForm () { this.$newColorField
this.$newLabelField .val('')
.val('') .trigger('change');
.trigger('change');
this.$newColorField this.$colorPreview
.val('') .css('background-color', '')
.trigger('change'); .parent()
.removeClass('is-active');
}
this.$colorPreview saveLabel (e) {
.css('background-color', '') e.preventDefault();
.parent() e.stopPropagation();
.removeClass('is-active');
}
saveLabel (e) { Api.newLabel(this.namespacePath, this.projectPath, {
e.preventDefault(); title: this.$newLabelField.val(),
e.stopPropagation(); color: this.$newColorField.val()
}, (label) => {
this.$newLabelCreateButton.enable();
Api.newLabel(this.namespacePath, this.projectPath, { if (label.message) {
title: this.$newLabelField.val(), let errors;
color: this.$newColorField.val()
}, (label) => {
this.$newLabelCreateButton.enable();
if (label.message) {
let errors;
if (typeof label.message === 'string') {
errors = label.message;
} else {
errors = Object.keys(label.message).map(key =>
`${gl.text.humanize(key)} ${label.message[key].join(', ')}`
).join("<br/>");
}
this.$newLabelError
.html(errors)
.show();
} else {
this.$dropdownBack.trigger('click');
$(document).trigger('created.label', label); if (typeof label.message === 'string') {
errors = label.message;
} else {
errors = Object.keys(label.message).map(key =>
`${gl.text.humanize(key)} ${label.message[key].join(', ')}`
).join("<br/>");
} }
});
}
}
if (!w.gl) { this.$newLabelError
w.gl = {}; .html(errors)
.show();
} else {
this.$dropdownBack.trigger('click');
$(document).trigger('created.label', label);
}
});
} }
}
gl.CreateLabelDropdown = CreateLabelDropdown; window.gl = window.gl || {};
})(window); gl.CreateLabelDropdown = CreateLabelDropdown;
...@@ -2,129 +2,127 @@ ...@@ -2,129 +2,127 @@
require('./lib/utils/url_utility'); require('./lib/utils/url_utility');
(() => { const UNFOLD_COUNT = 20;
const UNFOLD_COUNT = 20; let isBound = false;
let isBound = false;
class Diff { class Diff {
constructor() { constructor() {
const $diffFile = $('.files .diff-file'); const $diffFile = $('.files .diff-file');
$diffFile.singleFileDiff(); $diffFile.singleFileDiff();
$diffFile.filesCommentButton(); $diffFile.filesCommentButton();
$diffFile.each((index, file) => new gl.ImageFile(file)); $diffFile.each((index, file) => new gl.ImageFile(file));
if (this.diffViewType() === 'parallel') { if (this.diffViewType() === 'parallel') {
$('.content-wrapper .container-fluid').removeClass('container-limited'); $('.content-wrapper .container-fluid').removeClass('container-limited');
} }
if (!isBound) {
$(document)
.on('click', '.js-unfold', this.handleClickUnfold.bind(this))
.on('click', '.diff-line-num a', this.handleClickLineNum.bind(this));
isBound = true;
}
if (gl.utils.getLocationHash()) { if (!isBound) {
this.highlightSelectedLine(); $(document)
} .on('click', '.js-unfold', this.handleClickUnfold.bind(this))
.on('click', '.diff-line-num a', this.handleClickLineNum.bind(this));
isBound = true;
}
this.openAnchoredDiff(); if (gl.utils.getLocationHash()) {
this.highlightSelectedLine();
} }
handleClickUnfold(e) { this.openAnchoredDiff();
const $target = $(e.target); }
// current babel config relies on iterators implementation, so we cannot simply do:
// const [oldLineNumber, newLineNumber] = this.lineNumbers($target.parent()); handleClickUnfold(e) {
const ref = this.lineNumbers($target.parent()); const $target = $(e.target);
const oldLineNumber = ref[0]; // current babel config relies on iterators implementation, so we cannot simply do:
const newLineNumber = ref[1]; // const [oldLineNumber, newLineNumber] = this.lineNumbers($target.parent());
const offset = newLineNumber - oldLineNumber; const ref = this.lineNumbers($target.parent());
const bottom = $target.hasClass('js-unfold-bottom'); const oldLineNumber = ref[0];
let since; const newLineNumber = ref[1];
let to; const offset = newLineNumber - oldLineNumber;
let unfold = true; const bottom = $target.hasClass('js-unfold-bottom');
let since;
if (bottom) { let to;
const lineNumber = newLineNumber + 1; let unfold = true;
since = lineNumber;
to = lineNumber + UNFOLD_COUNT; if (bottom) {
} else { const lineNumber = newLineNumber + 1;
const lineNumber = newLineNumber - 1; since = lineNumber;
since = lineNumber - UNFOLD_COUNT; to = lineNumber + UNFOLD_COUNT;
to = lineNumber; } else {
const lineNumber = newLineNumber - 1;
// make sure we aren't loading more than we need since = lineNumber - UNFOLD_COUNT;
const prevNewLine = this.lineNumbers($target.parent().prev())[1]; to = lineNumber;
if (since <= prevNewLine + 1) {
since = prevNewLine + 1; // make sure we aren't loading more than we need
unfold = false; const prevNewLine = this.lineNumbers($target.parent().prev())[1];
} if (since <= prevNewLine + 1) {
since = prevNewLine + 1;
unfold = false;
} }
}
const file = $target.parents('.diff-file'); const file = $target.parents('.diff-file');
const link = file.data('blob-diff-path'); const link = file.data('blob-diff-path');
const view = file.data('view'); const view = file.data('view');
const params = { since, to, bottom, offset, unfold, view }; const params = { since, to, bottom, offset, unfold, view };
$.get(link, params, response => $target.parent().replaceWith(response)); $.get(link, params, response => $target.parent().replaceWith(response));
} }
openAnchoredDiff(cb) { openAnchoredDiff(cb) {
const locationHash = gl.utils.getLocationHash(); const locationHash = gl.utils.getLocationHash();
const anchoredDiff = locationHash && locationHash.split('_')[0]; const anchoredDiff = locationHash && locationHash.split('_')[0];
if (!anchoredDiff) return;
const diffTitle = $(`#${anchoredDiff}`);
const diffFile = diffTitle.closest('.diff-file');
const nothingHereBlock = $('.nothing-here-block:visible', diffFile);
if (nothingHereBlock.length) {
const clickTarget = $('.js-file-title, .click-to-expand', diffFile);
diffFile.data('singleFileDiff').toggleDiff(clickTarget, () => {
this.highlightSelectedLine();
if (cb) cb();
});
} else if (cb) {
cb();
}
}
handleClickLineNum(e) { if (!anchoredDiff) return;
const hash = $(e.currentTarget).attr('href');
e.preventDefault(); const diffTitle = $(`#${anchoredDiff}`);
if (window.history.pushState) { const diffFile = diffTitle.closest('.diff-file');
window.history.pushState(null, null, hash); const nothingHereBlock = $('.nothing-here-block:visible', diffFile);
} else { if (nothingHereBlock.length) {
window.location.hash = hash; const clickTarget = $('.js-file-title, .click-to-expand', diffFile);
} diffFile.data('singleFileDiff').toggleDiff(clickTarget, () => {
this.highlightSelectedLine(); this.highlightSelectedLine();
if (cb) cb();
});
} else if (cb) {
cb();
} }
}
diffViewType() { handleClickLineNum(e) {
return $('.inline-parallel-buttons a.active').data('view-type'); const hash = $(e.currentTarget).attr('href');
e.preventDefault();
if (window.history.pushState) {
window.history.pushState(null, null, hash);
} else {
window.location.hash = hash;
} }
this.highlightSelectedLine();
}
lineNumbers(line) { diffViewType() {
if (!line.children().length) { return $('.inline-parallel-buttons a.active').data('view-type');
return [0, 0]; }
}
return line.find('.diff-line-num').map((i, elm) => parseInt($(elm).data('linenumber'), 10)); lineNumbers(line) {
if (!line.children().length) {
return [0, 0];
} }
return line.find('.diff-line-num').map((i, elm) => parseInt($(elm).data('linenumber'), 10));
}
highlightSelectedLine() { highlightSelectedLine() {
const hash = gl.utils.getLocationHash(); const hash = gl.utils.getLocationHash();
const $diffFiles = $('.diff-file'); const $diffFiles = $('.diff-file');
$diffFiles.find('.hll').removeClass('hll'); $diffFiles.find('.hll').removeClass('hll');
if (hash) { if (hash) {
$diffFiles $diffFiles
.find(`tr#${hash}:not(.match) td, td#${hash}, td[data-line-code="${hash}"]`) .find(`tr#${hash}:not(.match) td, td#${hash}, td[data-line-code="${hash}"]`)
.addClass('hll'); .addClass('hll');
}
} }
} }
}
window.gl = window.gl || {}; window.gl = window.gl || {};
window.gl.Diff = Diff; window.gl.Diff = Diff;
})();
This diff is collapsed.
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* Makes search request for content when user types a value in the search input. * Makes search request for content when user types a value in the search input.
* Updates the html content of the page with the received one. * Updates the html content of the page with the received one.
*/ */
export default class FilterableList { export default class FilterableList {
constructor(form, filter, holder) { constructor(form, filter, holder) {
this.filterForm = form; this.filterForm = form;
......
/* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, no-param-reassign, quotes, quote-props, prefer-template, comma-dangle, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, no-param-reassign, quotes, quote-props, prefer-template, comma-dangle, max-len */
(function() {
this.Flash = (function() {
var hideFlash;
hideFlash = function() { window.Flash = (function() {
return $(this).fadeOut(); var hideFlash;
};
function Flash(message, type, parent) { hideFlash = function() {
var flash, textDiv; return $(this).fadeOut();
if (type == null) { };
type = 'alert';
} function Flash(message, type, parent) {
if (parent == null) { var flash, textDiv;
parent = null; if (type == null) {
} type = 'alert';
if (parent) { }
this.flashContainer = parent.find('.flash-container'); if (parent == null) {
} else { parent = null;
this.flashContainer = $('.flash-container-page'); }
} if (parent) {
this.flashContainer.html(''); this.flashContainer = parent.find('.flash-container');
flash = $('<div/>', { } else {
"class": "flash-" + type this.flashContainer = $('.flash-container-page');
}); }
flash.on('click', hideFlash); this.flashContainer.html('');
textDiv = $('<div/>', { flash = $('<div/>', {
"class": 'flash-text', "class": "flash-" + type
text: message });
}); flash.on('click', hideFlash);
textDiv.appendTo(flash); textDiv = $('<div/>', {
if (this.flashContainer.parent().hasClass('content-wrapper')) { "class": 'flash-text',
textDiv.addClass('container-fluid container-limited'); text: message
} });
flash.appendTo(this.flashContainer); textDiv.appendTo(flash);
this.flashContainer.show(); if (this.flashContainer.parent().hasClass('content-wrapper')) {
textDiv.addClass('container-fluid container-limited');
} }
flash.appendTo(this.flashContainer);
this.flashContainer.show();
}
return Flash; return Flash;
})(); })();
}).call(window);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -2,47 +2,46 @@ ...@@ -2,47 +2,46 @@
require('./gl_field_error'); require('./gl_field_error');
((global) => { const customValidationFlag = 'gl-field-error-ignore';
const customValidationFlag = 'gl-field-error-ignore';
class GlFieldErrors {
class GlFieldErrors { constructor(form) {
constructor(form) { this.form = $(form);
this.form = $(form); this.state = {
this.state = { inputs: [],
inputs: [], valid: false
valid: false };
}; this.initValidators();
this.initValidators(); }
}
initValidators () { initValidators () {
// register selectors here as needed // register selectors here as needed
const validateSelectors = [':text', ':password', '[type=email]'] const validateSelectors = [':text', ':password', '[type=email]']
.map((selector) => `input${selector}`).join(','); .map((selector) => `input${selector}`).join(',');
this.state.inputs = this.form.find(validateSelectors).toArray() this.state.inputs = this.form.find(validateSelectors).toArray()
.filter((input) => !input.classList.contains(customValidationFlag)) .filter((input) => !input.classList.contains(customValidationFlag))
.map((input) => new global.GlFieldError({ input, formErrors: this })); .map((input) => new window.gl.GlFieldError({ input, formErrors: this }));
this.form.on('submit', this.catchInvalidFormSubmit); this.form.on('submit', this.catchInvalidFormSubmit);
} }
/* Neccessary to prevent intercept and override invalid form submit /* Neccessary to prevent intercept and override invalid form submit
* because Safari & iOS quietly allow form submission when form is invalid * because Safari & iOS quietly allow form submission when form is invalid
* and prevents disabling of invalid submit button by application.js */ * and prevents disabling of invalid submit button by application.js */
catchInvalidFormSubmit (event) { catchInvalidFormSubmit (event) {
if (!event.currentTarget.checkValidity()) { if (!event.currentTarget.checkValidity()) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
}
} }
}
focusOnFirstInvalid () { focusOnFirstInvalid () {
const firstInvalid = this.state.inputs.filter((input) => !input.inputDomElement.validity.valid)[0]; const firstInvalid = this.state.inputs.filter((input) => !input.inputDomElement.validity.valid)[0];
firstInvalid.inputElement.focus(); firstInvalid.inputElement.focus();
}
} }
}
global.GlFieldErrors = GlFieldErrors; window.gl = window.gl || {};
})(window.gl || (window.gl = {})); window.gl.GlFieldErrors = GlFieldErrors;
...@@ -3,90 +3,88 @@ ...@@ -3,90 +3,88 @@
/* global DropzoneInput */ /* global DropzoneInput */
/* global autosize */ /* global autosize */
(() => { window.gl = window.gl || {};
const global = window.gl || (window.gl = {});
function GLForm(form) { function GLForm(form) {
this.form = form; this.form = form;
this.textarea = this.form.find('textarea.js-gfm-input'); this.textarea = this.form.find('textarea.js-gfm-input');
// Before we start, we should clean up any previous data for this form // Before we start, we should clean up any previous data for this form
this.destroy(); this.destroy();
// Setup the form // Setup the form
this.setupForm(); this.setupForm();
this.form.data('gl-form', this); this.form.data('gl-form', this);
} }
GLForm.prototype.destroy = function() { GLForm.prototype.destroy = function() {
// Clean form listeners // Clean form listeners
this.clearEventListeners(); this.clearEventListeners();
return this.form.data('gl-form', null); return this.form.data('gl-form', null);
}; };
GLForm.prototype.setupForm = function() { GLForm.prototype.setupForm = function() {
var isNewForm; var isNewForm;
isNewForm = this.form.is(':not(.gfm-form)'); isNewForm = this.form.is(':not(.gfm-form)');
this.form.removeClass('js-new-note-form'); this.form.removeClass('js-new-note-form');
if (isNewForm) { if (isNewForm) {
this.form.find('.div-dropzone').remove(); this.form.find('.div-dropzone').remove();
this.form.addClass('gfm-form'); this.form.addClass('gfm-form');
// remove notify commit author checkbox for non-commit notes // remove notify commit author checkbox for non-commit notes
gl.utils.disableButtonIfEmptyField(this.form.find('.js-note-text'), this.form.find('.js-comment-button')); gl.utils.disableButtonIfEmptyField(this.form.find('.js-note-text'), this.form.find('.js-comment-button'));
gl.GfmAutoComplete.setup(this.form.find('.js-gfm-input')); gl.GfmAutoComplete.setup(this.form.find('.js-gfm-input'));
new DropzoneInput(this.form); new DropzoneInput(this.form);
autosize(this.textarea); autosize(this.textarea);
// form and textarea event listeners // form and textarea event listeners
this.addEventListeners(); this.addEventListeners();
} }
gl.text.init(this.form); gl.text.init(this.form);
// hide discard button // hide discard button
this.form.find('.js-note-discard').hide(); this.form.find('.js-note-discard').hide();
this.form.show(); this.form.show();
if (this.isAutosizeable) this.setupAutosize(); if (this.isAutosizeable) this.setupAutosize();
}; };
GLForm.prototype.setupAutosize = function () { GLForm.prototype.setupAutosize = function () {
this.textarea.off('autosize:resized') this.textarea.off('autosize:resized')
.on('autosize:resized', this.setHeightData.bind(this)); .on('autosize:resized', this.setHeightData.bind(this));
this.textarea.off('mouseup.autosize') this.textarea.off('mouseup.autosize')
.on('mouseup.autosize', this.destroyAutosize.bind(this)); .on('mouseup.autosize', this.destroyAutosize.bind(this));
setTimeout(() => { setTimeout(() => {
autosize(this.textarea); autosize(this.textarea);
this.textarea.css('resize', 'vertical'); this.textarea.css('resize', 'vertical');
}, 0); }, 0);
}; };
GLForm.prototype.setHeightData = function () { GLForm.prototype.setHeightData = function () {
this.textarea.data('height', this.textarea.outerHeight()); this.textarea.data('height', this.textarea.outerHeight());
}; };
GLForm.prototype.destroyAutosize = function () { GLForm.prototype.destroyAutosize = function () {
const outerHeight = this.textarea.outerHeight(); const outerHeight = this.textarea.outerHeight();
if (this.textarea.data('height') === outerHeight) return; if (this.textarea.data('height') === outerHeight) return;
autosize.destroy(this.textarea); autosize.destroy(this.textarea);
this.textarea.data('height', outerHeight); this.textarea.data('height', outerHeight);
this.textarea.outerHeight(outerHeight); this.textarea.outerHeight(outerHeight);
this.textarea.css('max-height', window.outerHeight); this.textarea.css('max-height', window.outerHeight);
}; };
GLForm.prototype.clearEventListeners = function() { GLForm.prototype.clearEventListeners = function() {
this.textarea.off('focus'); this.textarea.off('focus');
this.textarea.off('blur'); this.textarea.off('blur');
return gl.text.removeListeners(this.form); return gl.text.removeListeners(this.form);
}; };
GLForm.prototype.addEventListeners = function() { GLForm.prototype.addEventListeners = function() {
this.textarea.on('focus', function() { this.textarea.on('focus', function() {
return $(this).closest('.md-area').addClass('is-focused'); return $(this).closest('.md-area').addClass('is-focused');
}); });
return this.textarea.on('blur', function() { return this.textarea.on('blur', function() {
return $(this).closest('.md-area').removeClass('is-focused'); return $(this).closest('.md-area').removeClass('is-focused');
}); });
}; };
global.GLForm = GLForm; window.gl.GLForm = GLForm;
})();
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, one-var, one-var-declaration-per-line, no-useless-escape, max-len */ /* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, no-var, one-var, one-var-declaration-per-line, no-useless-escape, max-len */
(function() {
this.GroupAvatar = (function() {
function GroupAvatar() {
$('.js-choose-group-avatar-button').on("click", function() {
var form;
form = $(this).closest("form");
return form.find(".js-group-avatar-input").click();
});
$('.js-group-avatar-input').on("change", function() {
var filename, form;
form = $(this).closest("form");
filename = $(this).val().replace(/^.*[\\\/]/, '');
return form.find(".js-avatar-filename").text(filename);
});
}
return GroupAvatar; window.GroupAvatar = (function() {
})(); function GroupAvatar() {
}).call(window); $('.js-choose-group-avatar-button').on("click", function() {
var form;
form = $(this).closest("form");
return form.find(".js-group-avatar-input").click();
});
$('.js-group-avatar-input').on("change", function() {
var filename, form;
form = $(this).closest("form");
filename = $(this).val().replace(/^.*[\\\/]/, '');
return form.find(".js-avatar-filename").text(filename);
});
}
return GroupAvatar;
})();
This diff is collapsed.
/* eslint-disable wrap-iife, func-names, space-before-function-paren, prefer-arrow-callback, no-var, max-len */ /* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var */
(function() {
$(document).on('todo:toggle', function(e, count) { $(document).on('todo:toggle', function(e, count) {
var $todoPendingCount = $('.todos-pending-count'); var $todoPendingCount = $('.todos-pending-count');
$todoPendingCount.text(gl.text.highCountTrim(count)); $todoPendingCount.text(gl.text.highCountTrim(count));
$todoPendingCount.toggleClass('hidden', count === 0); $todoPendingCount.toggleClass('hidden', count === 0);
}); });
})();
This diff is collapsed.
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