-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathmodalSearch.js
More file actions
39 lines (33 loc) · 1.28 KB
/
modalSearch.js
File metadata and controls
39 lines (33 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
$(() => {
// Add the selected item to the selections section
$('body').on('click', 'a.modal-search-result-selector', (e) => {
e.preventDefault();
const link = $(e.target);
if (link.length > 0) {
const selectedBlock = $(e.target).closest('.modal-search-result');
const resultsBlock = $(e.target).closest('.modal-search-results');
if (resultsBlock.length > 0 && selectedBlock.length > 0) {
const selectionsBlockId = resultsBlock.attr('id').replace('-results', '-selections');
if (selectionsBlockId !== undefined) {
const selectionsBlock = $(`#${selectionsBlockId}`);
if (selectionsBlock.length > 0) {
const clone = selectedBlock.clone();
clone.find('.modal-search-result-selector').addClass('d-none');
clone.find('.modal-search-result-unselector').removeClass('d-none');
clone.find('.tags').remove();
selectionsBlock.append(clone);
selectedBlock.remove();
}
}
}
}
});
// Remove the selected item
$('body').on('click', 'a.modal-search-result-unselector', (e) => {
e.preventDefault();
const selection = $(e.target).closest('.modal-search-result');
if (selection.length > 0) {
selection.remove();
}
});
});