debian-mirror-gitlab/app/assets/javascripts/behaviors/select2.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
937 B
JavaScript
Raw Normal View History

2020-07-28 23:09:34 +05:30
import $ from 'jquery';
2021-02-22 17:27:13 +05:30
import { loadCSSFile } from '../lib/utils/css_utils';
2020-07-28 23:09:34 +05:30
export default () => {
2021-02-22 17:27:13 +05:30
const $select2Elements = $('select.select2');
if ($select2Elements.length) {
2020-07-28 23:09:34 +05:30
import(/* webpackChunkName: 'select2' */ 'select2/select2')
.then(() => {
2021-02-22 17:27:13 +05:30
// eslint-disable-next-line promise/no-nesting
loadCSSFile(gon.select2_css_path)
.then(() => {
$select2Elements.select2({
width: 'resolve',
minimumResultsForSearch: 10,
dropdownAutoWidth: true,
});
2020-07-28 23:09:34 +05:30
2021-02-22 17:27:13 +05:30
// Close select2 on escape
$('.js-select2').on('select2-close', () => {
requestAnimationFrame(() => {
$('.select2-container-active').removeClass('select2-container-active');
$(':focus').blur();
});
});
})
.catch(() => {});
2020-07-28 23:09:34 +05:30
})
.catch(() => {});
}
};