Skip to content

Instantly share code, notes, and snippets.

@doulmi
Created August 14, 2017 07:29
Show Gist options
  • Save doulmi/d5ef035c04a09b426a30aac3524fc871 to your computer and use it in GitHub Desktop.
Save doulmi/d5ef035c04a09b426a30aac3524fc871 to your computer and use it in GitHub Desktop.
Laravel Active menubar js
// Set active state on menu element
var current_url = "{{ Request::fullUrl() }}";
var full_url = current_url+window.location.search;
var $navLinks = $("ul.sidebar-menu li a");
// First look for an exact match including the search string
var $curentPageLink = $navLinks.filter(
function() { return $(this).attr('href') === full_url; }
);
// If not found, look for the link that starts with the url
if(!$curentPageLink.length > 0){
$curentPageLink = $navLinks.filter(
function() { return $(this).attr('href').startsWith(current_url) || current_url.startsWith($(this).attr('href')); }
);
}
$curentPageLink.parents('li').addClass('active');
{{-- Enable deep link to tab --}}
var activeTab = $('[href="' + location.hash.replace("#", "#tab_") + '"]');
activeTab && activeTab.tab('show');
$('.nav-tabs a').on('shown.bs.tab', function (e) {
location.hash = e.target.hash.replace("#tab_", "#");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment