mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
feat: on category search reveal children and parents
This commit is contained in:
@@ -13,16 +13,42 @@ define('categorySearch', function () {
|
|||||||
}
|
}
|
||||||
var categoryEls = el.find('[component="category/list"] [data-cid]');
|
var categoryEls = el.find('[component="category/list"] [data-cid]');
|
||||||
el.on('show.bs.dropdown', function () {
|
el.on('show.bs.dropdown', function () {
|
||||||
|
function revealParents(cid) {
|
||||||
|
var parentCid = el.find('[component="category/list"] [data-cid="' + cid + '"]').attr('data-parentCid');
|
||||||
|
if (parentCid) {
|
||||||
|
el.find('[component="category/list"] [data-cid="' + parentCid + '"]').removeClass('hidden');
|
||||||
|
revealParents(parentCid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function revealChildren(cid) {
|
||||||
|
var els = el.find('[component="category/list"] [data-parentCid="' + cid + '"]');
|
||||||
|
els.each(function (index, el) {
|
||||||
|
var $el = $(el);
|
||||||
|
$el.removeClass('hidden');
|
||||||
|
revealChildren($el.attr('data-cid'));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateList() {
|
function updateList() {
|
||||||
var val = searchEl.find('input').val().toLowerCase();
|
var val = searchEl.find('input').val().toLowerCase();
|
||||||
var noMatch = true;
|
var noMatch = true;
|
||||||
|
var cids = [];
|
||||||
categoryEls.each(function () {
|
categoryEls.each(function () {
|
||||||
var liEl = $(this);
|
var liEl = $(this);
|
||||||
var isMatch = liEl.attr('data-name').toLowerCase().indexOf(val) !== -1;
|
var isMatch = liEl.attr('data-name').toLowerCase().indexOf(val) !== -1;
|
||||||
if (noMatch && isMatch) {
|
if (noMatch && isMatch) {
|
||||||
noMatch = false;
|
noMatch = false;
|
||||||
}
|
}
|
||||||
liEl.toggleClass('hidden', !isMatch);
|
if (isMatch && val) {
|
||||||
|
cids.push(liEl.attr('data-cid'));
|
||||||
|
}
|
||||||
|
liEl.toggleClass('hidden', !isMatch).find('[component="category-markup"]').css({ 'font-weight': val && isMatch ? 'bold' : 'normal' });
|
||||||
|
});
|
||||||
|
|
||||||
|
cids.forEach(function (cid) {
|
||||||
|
revealParents(cid);
|
||||||
|
revealChildren(cid);
|
||||||
});
|
});
|
||||||
|
|
||||||
el.find('[component="category/list"] [component="category/no-matches"]').toggleClass('hidden', !noMatch);
|
el.find('[component="category/list"] [component="category/no-matches"]').toggleClass('hidden', !noMatch);
|
||||||
|
|||||||
Reference in New Issue
Block a user