1 | // this code improves bootstrap menus and adds dropdown support |
---|
2 | jQuery(function(){ |
---|
3 | jQuery('.nav>li>a').each(function(){ |
---|
4 | if(jQuery(this).parent().find('ul').length) |
---|
5 | jQuery(this).attr({'class':'dropdown-toggle','data-toggle':'dropdown'}).append('<b class="caret"></b>'); |
---|
6 | }); |
---|
7 | jQuery('.nav li li').each(function(){ |
---|
8 | if(jQuery(this).find('ul').length) |
---|
9 | jQuery(this).addClass('dropdown-submenu'); |
---|
10 | }); |
---|
11 | function adjust_height_of_collapsed_nav() { |
---|
12 | var cn = jQuery('div.collapse'); |
---|
13 | if (cn.get(0)) { |
---|
14 | var cnh = cn.get(0).style.height; |
---|
15 | if (cnh>'0px'){ |
---|
16 | cn.css('height','auto'); |
---|
17 | } |
---|
18 | } |
---|
19 | } |
---|
20 | function hoverMenu(){ |
---|
21 | jQuery('ul.nav a.dropdown-toggle').parent().hover(function(){ |
---|
22 | adjust_height_of_collapsed_nav(); |
---|
23 | var mi = jQuery(this).addClass('open'); |
---|
24 | mi.children('.dropdown-menu').stop(true, true).delay(200).fadeIn(400); |
---|
25 | }, function(){ |
---|
26 | var mi = jQuery(this); |
---|
27 | mi.children('.dropdown-menu').stop(true, true).delay(200).fadeOut(function(){mi.removeClass('open')}); |
---|
28 | }); |
---|
29 | } |
---|
30 | hoverMenu(); // first page load |
---|
31 | jQuery(window).resize(hoverMenu); // on resize event |
---|
32 | jQuery('ul.nav li.dropdown a').click(function(){ |
---|
33 | if(jQuery(this).attr("target")){ |
---|
34 | window.open( |
---|
35 | jQuery(this).attr('href'), |
---|
36 | jQuery(this).attr('target') // <- This is what makes it open in a new window. |
---|
37 | ); |
---|
38 | } else { |
---|
39 | window.location=jQuery(this).attr('href'); |
---|
40 | } |
---|
41 | }); |
---|
42 | }); |
---|