debian-mirror-gitlab/app/assets/javascripts/ref_select_dropdown.js

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

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2020-11-24 15:15:51 +05:30
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
2018-05-09 12:01:36 +05:30
2017-08-17 22:00:37 +05:30
class RefSelectDropdown {
constructor($dropdownButton, availableRefs) {
2018-12-13 13:39:08 +05:30
const availableRefsValue =
availableRefs || JSON.parse(document.getElementById('availableRefs').innerHTML);
2020-11-24 15:15:51 +05:30
initDeprecatedJQueryDropdown($dropdownButton, {
2017-09-10 17:25:29 +05:30
data: availableRefsValue,
2017-08-17 22:00:37 +05:30
filterable: true,
filterByText: true,
remote: false,
2018-03-27 19:54:05 +05:30
fieldName: $dropdownButton.data('fieldName'),
2017-08-17 22:00:37 +05:30
filterInput: 'input[type="search"]',
selectable: true,
isSelectable(branch, $el) {
return !$el.hasClass('is-active');
},
text(branch) {
return branch;
},
id(branch) {
return branch;
},
toggleLabel(branch) {
return branch;
},
});
const $dropdownContainer = $dropdownButton.closest('.dropdown');
2018-03-27 19:54:05 +05:30
const $fieldInput = $(`input[name="${$dropdownButton.data('fieldName')}"]`, $dropdownContainer);
2017-08-17 22:00:37 +05:30
const $filterInput = $('input[type="search"]', $dropdownContainer);
2021-03-08 18:12:59 +05:30
$filterInput.on('keyup', (e) => {
2017-08-17 22:00:37 +05:30
const keyCode = e.keyCode || e.which;
if (keyCode !== 13) return;
const ref = $filterInput.val().trim();
if (ref === '') {
return;
}
$fieldInput.val(ref);
$('.dropdown-toggle-text', $dropdownButton).text(ref);
$dropdownContainer.removeClass('open');
});
}
}
export default RefSelectDropdown;