I noticed that when viewing a child page, parents of that page in the menu (navigation or menu_block module) had a blank href. (the current page is linked correctly, as are other non-parent items.. i think)

in menu.inc i noticed

function twitter_bootstrap_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  
  // Sanitize title
  $element['#title'] = check_plain($element['#title']);
  
  if ($element['#below']) {
	// Ad our own wrapper
	unset($element['#below']['#theme_wrappers']);
    $sub_menu = '<ul>' . drupal_render($element['#below']) . '</ul>';

    //$element['#localized_options']['attributes']['class'][] = 'dropdown-toggle';
	//$element['#localized_options']['attributes']['data-toggle'] = 'dropdown';
	//$element['#attributes']['class'][] = 'dropdown';
	$element['#localized_options']['html'] = TRUE;
	//$element['#title'] .= '<b class="caret"></b>';
	
	// auch
	$element['#href'] = "";
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

specifically

	// auch
	$element['#href'] = "";

commenting that out gives normal functionality as far as i can see - is it doing something i'm missing?

Comments

frankbaele’s picture

Assigned: Unassigned » frankbaele

i will look in to it

zcrow’s picture

Same thing here. Glad I found this. Was driving me a bit nuts trying to figure it out. I also commented out that line and it is working fine now.

duncan.moo’s picture

I switched to another theme to confirm that it was in fact twitter_bootstrap causing the issue, took me ages to find that line, and removing it sorts out the issue.

Michsk’s picture

That line should make $element['#href'] = '#'; but then # is converted to %23 when rendered.

The twitter_bootstrap_menu_link function takes care of the dropdown's from menus which have children. So the problem is that a blank path wont work and a # doesnt rendere correct. But twitter bootstrap needs the parent <a> to have href='#' for the dropdowns to work.

I'm looking in to this for some time now but really can't figure out how to set the # in the href.

Michsk’s picture

Actually i would suggest a js fix for this:

// Menu dropdown's href=#
Drupal.behaviors.twitterBootstrapMenu = {
attach: function (context, settings) {
$('.dropdown-toggle', context).attr('href', '#');
}
};

This way we can drop the #href.

duncan.moo’s picture

On my subtheme of twitter_bootstrap I did the following to keep the top level menu items while having the dropdown menu appear on click/touch of the down arrow.

function sub_twitter_bootstrap_menu_link(array $variables) {
  $element = $variables['element'];
  $sub_menu = '';
  $output_append = '';
  
  // Sanitize title
  //$element['#title'] = check_plain($element['#title']); // This double escaped &

  if ($element['#below']) {
	// Ad our own wrapper
	unset($element['#below']['#theme_wrappers']);
	    
	$element['#localized_options']['html'] = TRUE;
	if($element['#original_link']['depth'] == 1){
		
		$sub_menu = '<ul class="dropdown-menu">' . drupal_render($element['#below']) . '</ul>';
		$output_append = '<span class="dropdown-toggle" data-toggle="dropdown"><b class="caret"></b></span>';
	
	} else {
	
		$sub_menu = '<ul>' . drupal_render($element['#below']) . '</ul>';
		
	}
	// auch
	//$element['#href'] = "";
  }

  $output = l($element['#title'], $element['#href'], $element['#localized_options']);
  return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $output_append . $sub_menu . "</li>\n";
}
andregriffin’s picture

Unfortunately the function provided by duncan.moo turns normal menu-trees into dropdowns (sort of).

natted’s picture

Assigned: frankbaele » Unassigned
Status: Active » Needs review
StatusFileSize
new1.38 KB

As far as I can tell, the data-target has not been set correctly.

It is pretty much one line which allows you to remove $element['#href'] = "";

$element['#localized_options']['attributes']['data-target'] = '#';

Patch attached.

andregriffin’s picture

Status: Needs review » Fixed

Seems alright to me. Committed to dev

zmove’s picture

Status: Fixed » Active

I reopen the issue, cause I encounter some problems with that function too and I wonder what is the interests to change the parent href to #.

For what I tested, letting the parent href don't change any behavior (correct me if I'm wrong). Even if the click on the link open the dropdown and don't put the user to the new page, it doesn't break anything.

On the other side, all modules that add some custom dropdown with their own logic will be broken. For example I'm testing Commerce Kickstart that provide his own dropdown toolbar management and all parent links, that normally drive the user to a specific page are broken.

So, for compatibility issues, it sounds me more logical to always let the href property as it is.

Other solution (more complex) would be to add some settings for the theme where you can check the menu you want to override, and let the others.

Regards,

Alex

natted’s picture

Status: Active » Fixed

Hi @zmove

I don't see what you are saying at all.

The change we made was to add the data-target="#" (which is required for by bootstrap) to menu links, which as far as I can tell is not used by the Commerce Kickstart in their dropdown menus.

I installed kickstart, changed to twitter bootstrap (latest dev version) and the kickstart dropdown menus still work. You sure you didn't forget to install jquery_update and change to 1.7+?

Maybe for these issues, if it's not related to twitter_bootstrap theme + core drupal functionality, then it's better to just open a new issue.

zmove’s picture

Hello,

Thank you for the answer.

I use the recommended version of twitter boostrap, released before the commit. It's probably why I encounter some old problems.

I made my own sauce to fix the problem temporarly by waiting a future recommended release.

Regards,

Alex

andregriffin’s picture

Project: Twitter's Bootstrap » Bootstrap Framework
andregriffin’s picture

Project: Bootstrap Framework » Twitter's Bootstrap
natted’s picture

Project: Twitter's Bootstrap » Bootstrap

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.