Commit eacdaa70 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'tz-improve-project-js' into 'master'

Improved project.js and select2 loading

See merge request gitlab-org/gitlab!42355
parents 722f3e63 57214375
......@@ -97,7 +97,10 @@ const groupsSelect = () => {
});
};
export default () =>
export default () => {
if ($('.ajax-groups-select').length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(groupsSelect)
.catch(() => {});
}
};
......@@ -13,6 +13,7 @@ import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
export default class Project {
constructor() {
const $cloneOptions = $('ul.clone-options-dropdown');
if ($cloneOptions.length) {
const $projectCloneField = $('#project_clone');
const $cloneBtnLabel = $('.js-git-clone-holder .js-clone-dropdown-label');
const mobileCloneField = document.querySelector(
......@@ -48,13 +49,18 @@ export default class Project {
}
$('.js-git-empty .js-clone').text(url);
});
}
// Ref switcher
if (document.querySelector('.js-project-refs-dropdown')) {
Project.initRefSwitcher();
$('.project-refs-select').on('change', function() {
return $(this)
.parents('form')
.submit();
});
}
$('.hide-no-ssh-message').on('click', function(e) {
Cookies.set('hide_no_ssh_message', 'false');
$(this)
......@@ -78,6 +84,7 @@ export default class Project {
.remove();
return e.preventDefault();
});
Project.projectSelectDropdown();
}
......
......@@ -110,7 +110,10 @@ const projectSelect = () => {
});
};
export default () =>
export default () => {
if ($('.ajax-project-select').length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(projectSelect)
.catch(() => {});
}
};
......@@ -561,6 +561,8 @@ function UsersSelect(currentUser, els, options = {}) {
},
});
});
if ($('.ajax-users-select').length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-users-select').each((i, select) => {
......@@ -613,7 +615,11 @@ function UsersSelect(currentUser, els, options = {}) {
data.results.unshift(anyUser);
}
}
if (showEmailUser && data.results.length === 0 && query.term.match(/^[^@]+@[^@]+$/)) {
if (
showEmailUser &&
data.results.length === 0 &&
query.term.match(/^[^@]+@[^@]+$/)
) {
const trimmed = query.term.trim();
const emailUser = {
name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
......@@ -647,6 +653,7 @@ function UsersSelect(currentUser, els, options = {}) {
});
})
.catch(() => {});
}
}
UsersSelect.prototype.initSelection = function(element, callback) {
......
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