summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/main.js
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2019-01-29 10:35:53 +0100
committerTim Zallmann <tzallmann@gitlab.com>2019-01-29 12:48:39 +0100
commit40a04bc7e6a8d99e837938ff984e4bf4036dae3b (patch)
treea6d051a749314ccb9559b67dfaff9992fd0a4ae7 /app/assets/javascripts/main.js
parent2bb0d089ad70bf633071fc79dda0cc745a1c02a3 (diff)
downloadgitlab-ce-40a04bc7e6a8d99e837938ff984e4bf4036dae3b.tar.gz
Wraps Select 2 Import into its own webpack bundle
Wraps all imports for select 2 to deferred imports, especially in the main.js we are actually checking if there is any select 2 element on the page or not.
Diffstat (limited to 'app/assets/javascripts/main.js')
-rw-r--r--app/assets/javascripts/main.js30
1 files changed, 18 insertions, 12 deletions
diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js
index 4ba3543f9b2..8e10b3ad912 100644
--- a/app/assets/javascripts/main.js
+++ b/app/assets/javascripts/main.js
@@ -100,18 +100,24 @@ function deferredInitialisation() {
});
// Initialize select2 selects
- $('select.select2').select2({
- width: 'resolve',
- dropdownAutoWidth: true,
- });
-
- // Close select2 on escape
- $('.js-select2').on('select2-close', () => {
- setTimeout(() => {
- $('.select2-container-active').removeClass('select2-container-active');
- $(':focus').blur();
- }, 1);
- });
+ if ($('select.select2').length) {
+ import(/* webpackChunkName: 'select2' */ 'select2/select2')
+ .then(() => {
+ $('select.select2').select2({
+ width: 'resolve',
+ dropdownAutoWidth: true,
+ });
+
+ // Close select2 on escape
+ $('.js-select2').on('select2-close', () => {
+ setTimeout(() => {
+ $('.select2-container-active').removeClass('select2-container-active');
+ $(':focus').blur();
+ }, 1);
+ });
+ })
+ .catch(() => {});
+ }
// Initialize tooltips
$body.tooltip({