Use direct links for sidebar elements with only a single subitem
If a sidebar toggler contains only a single item with a link, there is no need to create a toggler with subnav at all. Let's just remove the subnav and link to the target directly. Signed-off-by: Frieder Schrempf <dev@fris.de>
This commit is contained in:
parent
58332e8afb
commit
11b00783f8
1 changed files with 24 additions and 14 deletions
|
@ -124,7 +124,6 @@ jQuery(function () {
|
||||||
;
|
;
|
||||||
$toggler = jQuery('<div class="nav">').prepend($toggler);
|
$toggler = jQuery('<div class="nav">').prepend($toggler);
|
||||||
|
|
||||||
|
|
||||||
// wrap all following siblings til the next element in a wrapper
|
// wrap all following siblings til the next element in a wrapper
|
||||||
var $wrap = jQuery('<div>')
|
var $wrap = jQuery('<div>')
|
||||||
.addClass('nav-panel');
|
.addClass('nav-panel');
|
||||||
|
@ -136,10 +135,16 @@ jQuery(function () {
|
||||||
$sib.detach().appendTo($wrap);
|
$sib.detach().appendTo($wrap);
|
||||||
addContentMenuCurrentStates($sib, $toggler);
|
addContentMenuCurrentStates($sib, $toggler);
|
||||||
}
|
}
|
||||||
$wrap.insertAfter($me);
|
|
||||||
|
|
||||||
// replace element with toggler
|
/*
|
||||||
$me.replaceWith($toggler);
|
* if there is only one subitem with a link, disable toggling
|
||||||
|
* and use a direct link.
|
||||||
|
*/
|
||||||
|
var $links = jQuery($wrap[0]).find('a');
|
||||||
|
if ($links.length == 1) {
|
||||||
|
$toggler.children().first().attr('href', jQuery($links[0]).attr('href'));
|
||||||
|
} else {
|
||||||
|
$wrap.insertAfter($me);
|
||||||
|
|
||||||
if ($toggler.parent('li').length) {
|
if ($toggler.parent('li').length) {
|
||||||
$toggler.parent('li').addClass('toggler');
|
$toggler.parent('li').addClass('toggler');
|
||||||
|
@ -149,7 +154,10 @@ jQuery(function () {
|
||||||
$wrap.css('display', 'block');
|
$wrap.css('display', 'block');
|
||||||
setTogglerClass($toggler,'is-open');
|
setTogglerClass($toggler,'is-open');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// replace element with toggler
|
||||||
|
$me.replaceWith($toggler);
|
||||||
});
|
});
|
||||||
|
|
||||||
// fade in the navigation (was hidden until now
|
// fade in the navigation (was hidden until now
|
||||||
|
@ -161,8 +169,10 @@ jQuery(function () {
|
||||||
*/
|
*/
|
||||||
initMenuHandling = function () {
|
initMenuHandling = function () {
|
||||||
$nav.on('click', 'div.nav a', function (e) {
|
$nav.on('click', 'div.nav a', function (e) {
|
||||||
|
if (jQuery(this).attr('href').startsWith('#')) {
|
||||||
toggleNav(jQuery(this));
|
toggleNav(jQuery(this));
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue