question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature : I made a live menu search

See original GitHub issue

My menu end up with long list so I thought I shall use that search box to search menu. And may be someone find this useful too.

    1. I added a class to the search box

<input type="text" name="q" class="form-control search-menu-box" placeholder="Search...">

    1. Added this jQuery script
$(".search-menu-box").on('input', function() {
    var filter = $(this).val();
    $(".sidebar-menu > li").each(function(){
        if ($(this).text().search(new RegExp(filter, "i")) < 0) {
            $(this).hide();
        } else {
            $(this).show();
        }
    });
});

Based on the codes from this link http://www.designchemical.com/blog/index.php/jquery/live-text-search-function-using-jquery/

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
surferxo3commented, Sep 19, 2019
`$.fn.openMenu = function () {
	var className = $(this).attr('class');

	if (className == 'treeview') {
		$(this).addClass('active');
	} else if (className == 'treeview-menu') {
		$(this).addClass('menu-open');
		$(this).css({display: 'block'});
	}
};

$.fn.closeMenu = function () {
	var className = $(this).attr('class');
	var count = $(this).length;

	if (count > 1) {
		$.each($(this), function(key, element) {
			className = $(element).attr('class');

			if (className == 'treeview active') {
				$(element).removeClass('active');
			} else if (className == 'treeview-menu menu-open') {
				$(element).removeClass('menu-open');
				$(element).css({display: 'none'});
			}
		});
	} else {
		if (className == 'treeview active') {
			$(this).removeClass('active');
		} else if (className == 'treeview-menu menu-open') {
			$(this).removeClass('menu-open');
			$(this).css({display: 'none'});
		}
	}
};

$('.search-menu-box').on('input', function() {
	var filter = $(this).val();

	$('.sidebar-menu li').each(function() {
		if ($(this).text().search(new RegExp(filter, 'i')) < 0) {
			$(this).hide();
		} else {
			$(this).show();
			$(this).parentsUntil('.treeview').openMenu();
		}
	});
});`

The code snippet seems to have problem when making search box empty i.e. all multi-level menu items remain open. In addition the rightmost arrows are not working as expected. Can anyone if possible provide the rectified solution to this?

1reaction
iprasthacommented, Jun 23, 2018

If you would like the search to include child items, simply replace

...
$(".sidebar-menu > li").each(function(){
...

to

...
$(".sidebar-menu li").each(function(){
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Search from the iPhone Home Screen or Lock Screen
On iPhone, you can search for apps and contacts, content in apps like Mail, Messages, and Photos, and even text in your photos...
Read more >
Google rolls out new features across Maps, Search and ...
Google rolls out new features across Maps, Search and Shopping · Google's dish search feature · Google's search with live view feature.
Read more >
See what's on the Start menu - Microsoft Support
Learn more about the Start menu, including how to find your files and get to your apps and programs. ... Next, make it...
Read more >
Customize YouTube channel layout - Google Support
Under Video spotlight, click ADD and select a video to feature. Click Publish. ... Search Help Center ... Search. Clear search. Close search....
Read more >
How to find movies and TV shows using Roku® Search
From the latest blockbusters and trending shows to your favorite cult classics, Roku Search includes 500000+ movies and TV episodes across a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found