bootstrap-hover-dropdown
bootstrap-hover-dropdown copied to clipboard
Can't seelct the top level nav item
I have used the file in a similar way to http://www.balibaytradingcompany.com/ at www.plymouthdevils.co, but can't select the top level nav item
Yep, that's the problem! Also parent level inaccessible on mobile devices
fix
//dropdown fix, motherfuckers
function isTouchDevice(){
if ('ontouchstart' in window || navigator.msMaxTouchPoints) {
$('html').addClass('touch');
}
}
//run touch test
isTouchDevice(); //touch detedt
$("html:not(.touch) li.dropdown>a.dropdown-toggle").on("click",function(){
window.location = $(this).attr("href"); //click parent non-touch
});
$("html.touch li.dropdown>a.dropdown-toggle").on("click",function(){
//if already clicked once - go to link(submenu is already opened)
if($(this).hasClass("oneTouch")){
$(this).removeClass("oneTouch");
window.location = $(this).attr("href");
}
else{
$(this).addClass("oneTouch"); //add click counter
$(".navbar-nav li ul").hide(); //<---- hide all submenus, use your own menu selector
$(this).parent().find(".dropdown-menu").show();
}
});
I had to add the e.PreventDefault();
before adding the class in the else
for this to work for me, but thanks so much!
$("html.touch li.dropdown>a.dropdown-toggle").on("click",function(e){
//if already clicked once - go to link(submenu is already opened)
if($(this).hasClass("oneTouch")){
$(this).removeClass("oneTouch");
window.location = $(this).attr("href");
}
else{
e.PreventDefault(); // Don't do the default click action without the click counter class.
$(this).addClass("oneTouch"); //add click counter
$(".navbar-nav li ul").hide(); //<---- hide all submenus, use your own menu selector
$(this).parent().find(".dropdown-menu").show();
}
});