2020-06-18 20:09:12 -04:00
|
|
|
import $ from 'jquery';
|
2020-11-18 04:09:02 -05:00
|
|
|
import { loadCSSFile } from '../lib/utils/css_utils';
|
2020-06-18 20:09:12 -04:00
|
|
|
|
|
|
|
export default () => {
|
2020-11-18 04:09:02 -05:00
|
|
|
const $select2Elements = $('select.select2');
|
|
|
|
if ($select2Elements.length) {
|
2020-06-18 20:09:12 -04:00
|
|
|
import(/* webpackChunkName: 'select2' */ 'select2/select2')
|
|
|
|
.then(() => {
|
2020-11-18 04:09:02 -05:00
|
|
|
// eslint-disable-next-line promise/no-nesting
|
|
|
|
loadCSSFile(gon.select2_css_path)
|
|
|
|
.then(() => {
|
|
|
|
$select2Elements.select2({
|
|
|
|
width: 'resolve',
|
|
|
|
minimumResultsForSearch: 10,
|
|
|
|
dropdownAutoWidth: true,
|
|
|
|
});
|
2020-06-18 20:09:12 -04:00
|
|
|
|
2020-11-18 04:09:02 -05:00
|
|
|
// Close select2 on escape
|
|
|
|
$('.js-select2').on('select2-close', () => {
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
$('.select2-container-active').removeClass('select2-container-active');
|
|
|
|
$(':focus').blur();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2020-06-18 20:09:12 -04:00
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
}
|
|
|
|
};
|