mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 11:23:48 -05:00
If you’ve searched to select an item and then you want to perform an action on it it’s confusing when it goes away if you change your search. It should always be clear which items you’re performing an action on. This means that checked items should always be visible, no matter what your search term is.
55 lines
973 B
JavaScript
55 lines
973 B
JavaScript
(function(Modules) {
|
|
"use strict";
|
|
|
|
let normalize = (string) => string.toLowerCase().replace(/ /g,'');
|
|
|
|
let filter = ($searchBox, $targets) => () => {
|
|
|
|
let query = normalize($searchBox.val());
|
|
|
|
$targets.each(function() {
|
|
|
|
let content = $('.live-search-relevant', this).text() || $(this).text();
|
|
|
|
if ($(this).has(':checked').length) {
|
|
$(this).show();
|
|
return;
|
|
}
|
|
|
|
if (query == '') {
|
|
$(this).css('display', '');
|
|
return;
|
|
}
|
|
|
|
$(this).toggle(
|
|
normalize(content).indexOf(normalize(query)) > -1
|
|
);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
Modules.LiveSearch = function() {
|
|
|
|
this.start = function(component) {
|
|
|
|
let $component = $(component);
|
|
|
|
let $searchBox = $('input', $component);
|
|
|
|
let filterFunc = filter(
|
|
$searchBox,
|
|
$($component.data('targets'))
|
|
);
|
|
|
|
$searchBox.on('keyup input', filterFunc);
|
|
|
|
filterFunc();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
})(window.GOVUK.Modules);
|