Commit 2cea0224 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'tz-reduce-js-bundle-select2' into 'master'

Reduce Bundle Size by making select2 loading optional

Closes #56988

See merge request gitlab-org/gitlab-ce!24727
parents 6429dc94 40a04bc7
......@@ -7,4 +7,3 @@ import 'vendor/jquery.caret';
import 'vendor/jquery.atwho';
import 'vendor/jquery.scrollTo';
import 'jquery.waitforimages';
import 'select2/select2';
......@@ -4,6 +4,8 @@ import Api from './api';
import { normalizeHeaders } from './lib/utils/common_utils';
export default function groupsSelect() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
// Needs to be accessible in rspec
window.GROUP_SELECT_PER_PAGE = 20;
$('.ajax-groups-select').each(function setAjaxGroupsSelect2() {
......@@ -93,4 +95,6 @@ export default function groupsSelect() {
dropdown.style.height = `${Math.floor(dropdown.scrollHeight)}px`;
});
});
})
.catch(() => {});
}
......@@ -11,10 +11,14 @@ class AutoWidthDropdownSelect {
init() {
const { dropdownClass } = this;
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
this.$selectElement.select2({
dropdownCssClass: dropdownClass,
...AutoWidthDropdownSelect.selectOptions(this.dropdownClass),
});
})
.catch(() => {});
return this;
}
......
......@@ -7,10 +7,14 @@ export default class IssuableContext {
constructor(currentUser) {
this.userSelect = new UsersSelect(currentUser);
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('select.select2').select2({
width: 'resolve',
dropdownAutoWidth: true,
});
})
.catch(() => {});
$('.issuable-sidebar .inline-update').on('change', 'select', function onClickSelect() {
return $(this).submit();
......
......@@ -120,6 +120,8 @@ export default class IssuableForm {
}
initTargetBranchDropdown() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
this.$targetBranchSelect.select2({
...AutoWidthDropdownSelect.selectOptions('js-target-branch-select'),
ajax: {
......@@ -150,5 +152,7 @@ export default class IssuableForm {
});
},
});
})
.catch(() => {});
}
}
......@@ -100,6 +100,9 @@ function deferredInitialisation() {
});
// Initialize select2 selects
if ($('select.select2').length) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('select.select2').select2({
width: 'resolve',
dropdownAutoWidth: true,
......@@ -112,6 +115,9 @@ function deferredInitialisation() {
$(':focus').blur();
}, 1);
});
})
.catch(() => {});
}
// Initialize tooltips
$body.tooltip({
......
......@@ -5,6 +5,8 @@ import Api from './api';
import ProjectSelectComboButton from './project_select_combo_button';
export default function projectSelect() {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-project-select').each(function(i, select) {
var placeholder;
const simpleFilter = $(select).data('simpleFilter') || false;
......@@ -98,4 +100,6 @@ export default function projectSelect() {
if (simpleFilter) return select;
return new ProjectSelectComboButton(select);
});
})
.catch(() => {});
}
......@@ -44,9 +44,13 @@ export default class ProjectSelectComboButton {
// eslint-disable-next-line class-methods-use-this
openDropdown(event) {
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$(event.currentTarget)
.siblings('.project-item-select')
.select2('open');
})
.catch(() => {});
}
selectProject() {
......
......@@ -579,6 +579,8 @@ function UsersSelect(currentUser, els, options = {}) {
};
})(this),
);
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
$('.ajax-users-select').each(
(function(_this) {
return function(i, select) {
......@@ -637,7 +639,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(/^[^@]+@[^@]+$/)
) {
var trimmed = query.term.trim();
emailUser = {
name: 'Invite "' + trimmed + '" by email',
......@@ -674,6 +680,8 @@ function UsersSelect(currentUser, els, options = {}) {
};
})(this),
);
})
.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