I have been working on a fork of this fiddle - all props go to the original author.
It is designed to work with ImageMapster to highlight an html list item when hovering over the image map, and vice-versa, highlight the appropriate image map when hovering the list item. As you would expect it works by adding and removing a class to and from the appropriate places.
I have been trying to use that code (and variations of) with Drupal 7 which adds plenty of classes of it's own to both the anchor of a menu item and its list item wrapper. That extra markup is causing issues with the above script, leaving me scratching my head.
Through a whole bunch of trial and error (I'm not very good at JS!) I have realised that specifically when Drupal adds a class of 'menu-depth-1' to the li, the script gets lost, and throws an error (from Chrome):
Uncaught Error: Syntax error, unrecognized expression: area[name=part-1 menu]
In this fork of the above script, all I have added is the markup which Drupal adds.
http://jsfiddle.net/PUncle/Tr4hE/32/
Changing the original script from:
<li class="menu-item-a"><a href="#">Part A</a></li>
To:
<li class="leaf menu-depth-1 menu-item-a"><a href="#">Part A</a></li
As far as I understand, the script is looking for a hyphenated selector, and when it encounters 'menu-depth-1' before it gets to the desired 'menu-item-a', its fails.
I think that it is specifically this part of the script which is at fault, but no matter what I try, I can't work out how to fix it.
function highlightArea(key) {
$('area[name=part-' + key + ']').mouseenter();
$('a').removeClass('hover');
$('li.menu-item-' + key + ' a').addClass('hover');
}
What I need to do is 'harden' the script to make it very specifically target a particular selector and ignore anything else.
I did start going down the route of cleaning up Drupals excessive menu markup, but decided that clearing the way for 'blunt' code is probably not as effective as sharpening that code so that nothing else can affect it!
Any pointers would be greatly appreciated.