special menu items is designed right now so that it renders a "nolink" as a <span>.

this causes other modules that rely on an <a href="..."> menu item to break.
like:
* menu attributes
* megamenu
* superfish
...

so i propose to render "nolink" items as <a href="#" class="nolink">
so other modules see what they expect.
this "nolink" can then be altered by a onload javascript oneliner which makes it a span.

the downside of this is that users without javascript see a nolink as a link (which does nothing) when hovering over it - but i think this is neglegible against a flood of issues like "special menu items does not play well with module XYZ".

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

geek-merlin’s picture

Title: user <a href="#"> for "nolink" items » user <a href="#"> for "nolink" items to not break other modules
gagarine’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

I'm not to add links than is not. They are perhaps an other way to fix the issue.

Someone can confirm is still breaking in D7?

geek-merlin’s picture

Title: user <a href="#"> for "nolink" items to not break other modules » option to use <a href="#"> for "nolink" items to not break other modules

right, this may cause issues so should be an option.

geek-merlin’s picture

gagarine’s picture

Status: Postponed (maintainer needs more info) » Active

Ok for an option. Patch welcome.

gagarine’s picture

Priority: Normal » Major
candelas’s picture

any news?

gagarine’s picture

I just raise the issue to major.

If you absolutely need the feature make a patch or consider sponsoring it (money make everything faster).

erok415’s picture

sub

aburnsni’s picture

subscribe

3dinfluence’s picture

I've worked around this issue for the time being by adding the following javascript to my theme template. It's a hack at best but gets me past my last remaining issue preventing me from migrating a site to D7 until a real fix is released.

Here's the work around.
In your html.tpl.php for your theme find the line that says

 <?php print $scripts; ?>

And add the following just after it.

    <script type="text/javascript">
        (function ($) {
                $(document).ready(function() {
                        // replace nolinks
                        $("[href='/%3Cnolink%3E']").each(function(index) {
                                $(this).replaceWith("<span class='nolink'>" + $(this).text() + "</span>");
                        });
                        // replace separators
                        $("[href='/%3Cseparator%3E']").each(function(index) {
                                $(this).replaceWith("<span class='separator'><hr></span>");
                        });
                });
        })(jQuery);
    </script>

Then you need to flush your sites caches for the change to take effect. This only works for the nolink menu items. With a few tweaks it shouldn't be difficult to extend this to work for separators.

EDIT: I modified the script to support separators. Note that this will only work if javascript is enabled by the client. It replaces nolink menu items with span tags and the separators with hr tags.

Yaazkal’s picture

Hi, the code on #11 should be:

<script type="text/javascript">
        (function ($) {
                $(document).ready(function() {
                        // replace nolinks
                        $("a[href$='/%3Cnolink%3E']").each(function(index) {
                                $(this).replaceWith("<span class='nolink'>" + $(this).text() + "</span>");
                        });
                        // replace separators
                        $("a[href$='/%3Cseparator%3E']").each(function(index) {
                                $(this).replaceWith("<span class='separator'><hr></span>");
                        });
                });
        })(jQuery);
    </script>

Just replace
<$("[href=
with
$("a[href$=
that's the way it works.

Thanks 3dinfluence

Regards !

PS: This solution should be on the module and no as a JS. But if you need it urgent (as I) this JS is just fine. This must be a feature on this module.

3dinfluence’s picture

It seems to work fine without specifying the a tag in the selector here. Although I'll agree that it's probably more efficient this way as jQuery doesn't have to look for href attributes for every object in the DOM.

I also agree this is just a hack. The real solution will have to be integrated into the module.

3dinfluence’s picture

Alternatively if you don't want to modify your templates you can add this script by saving it without the

tags to a .js file and add it to your theme by adding a line like this example to your themes.info file.

scripts[] = js/nolink_fix.js

Yucom’s picture

Thanks for the JS. It was really helpful, and did what I needed. I am using the superfish-module, so I did a few changes to the script, not much, and not that I know what I am doing here, as I am not skilled with JS. I changed the "span" into an "a" again, as if you use a span, the superfish css doesn't fit anymore. Yes you can change the whole css, but for what?

Important - I am using this only for the very first parent item of a menu, the visible part. Please stick to the solution Yaazkal if you want to be on the save side!

        (function ($) {
                $(document).ready(function() {
                        // replace nolinks
                        $("a[href$='/%3Cnolink%3E']").each(function(index) {
                                $(this).replaceWith("<a class='sf-depth-1 menuparent sf-with-ul' style='cursor:pointer'>" + $(this).text() + "</a>");
                        });
                        // replace separators
                        $("a[href$='/%3Cseparator%3E']").each(function(index) {
                                $(this).replaceWith("<span class='separator'><hr></span>");
                        });
                });
        })(jQuery);
fahadurrehman’s picture

I am using special menu item since drupal 6. it allows you to simply put nolink as a path into menu items. I cant understand why drupal don't allows # to be entered as a link. To over come this problem and some other similar problems I usually add a Jquery file in my theme named findandreplace.js and simply add the following line into that

jQuery("[href='/%3Cnolink%3E']").attr("href", "#");

so it simply replaces the nolink into # and it worked fine with special menu and nice menu.

May be this can help some one like me who needs simple solutions for the typical problems.

3rdLOF’s picture

This one to be inserted in current jQuery function.

$("a[href='/%3Cnolink%3E']").attr('href', '#');

I think yours is also missing the "a" selector:

jQuery("a[href='/%3Cnolink%3E']").attr("href", "#");

gagarine’s picture

Assigned: Unassigned » gagarine

Ok apparently I will have to work on this one...

markwk’s picture

I can confirm http://drupal.org/node/1221294#comment-5212154 fixes issue with superfish.

geek-merlin’s picture

my 5 cent here: this must be done in php, not js, to work in any case.

geek-merlin’s picture

Issue summary: View changes

escaped <

geek-merlin’s picture

hey, just looked and it seems to be already something in the dev source.
http://drupalcode.org/project/special_menu_items.git/blob/refs/heads/7.x...

i don't use this module right now but who is interested might try a

drush vset special_menu_items_nolink_tag '<a href="#">'

(don't forget angle brackets...)
i supose there will be still issues with it but it's clear from the source where to fix this.

patoshi’s picture

so the issue relies on lines 49 - 57 in the .module file... Currently there is no condition where it sets the nolink or seperator tags as chosen in the config page. I modified the return value:

http://img210.imageshack.us/img210/39/croppercapture90.jpg

by replacing the span with : a href="javascript:void(0)

since its temp fix for me. I didnt have time to make a patch and actually fix it. but all the pieces are there for anyone up for the task in making a patch for it... you'll just have to do a variable_get(...) to retreive the stored

DuaelFr’s picture

Status: Active » Needs review
FileSize
3.3 KB

Hi !

Here is a two-in-one patch which :
- improves the usage of the "special_menu_items_nolink_tag" variable by including it in the "special_menu_items_link" function
- interfaces this module with core attributes system allowing to play with other modules like Menu Attributes
It applies well on the last dev version.

I hope you will enjoy it.
Regards.

PS : first point is related to comment #21

renard007’s picture

For good compatibility with all configuration of superfish & special menu items :
Use comment of Yaazkal (#12) & Yucom(#15)

  <script type="text/javascript">
  (function ($) {
                $(document).ready(function() {
                        // replace nolinks
                        $("a[href$='/?q=%3Cnolink%3E']").each(function(index) {
                                $(this).replaceWith("<a class='sf-depth-1 menuparent sf-with-ul' style='cursor:pointer'>" + $(this).text() + "</a>");
                        });
						$("a[href$='/%3Cnolink%3E']").each(function(index) {
                                $(this).replaceWith("<a class='sf-depth-1 menuparent sf-with-ul' style='cursor:pointer'>" + $(this).text() + "</a>");
                        });
                        // replace separators
                        $("a[href$='/?q=%3Cseparator%3E']").each(function(index) {
                                $(this).replaceWith("<span class='separator'><hr></span>");
                        });
						$("a[href$='/%3Cseparator%3E']").each(function(index) {
                                $(this).replaceWith("<span class='separator'><hr></span>");
                        });
                });
        })(jQuery);
  </script>
gagarine’s picture

Status: Needs review » Fixed

I commit the patch #24 #23 http://drupal.org/commitlog/commit/9840/a9dc66db0255b11b854572546e3a55e3... .

Please try the 7.x-1.x-dev and see if it doesn't break anything ;).

netdreamer’s picture

After trying dev version (that includes patch #1221294-23: option to use <a href="#"> for "nolink" items to not break other modules), I noticed that things were not working as expected, because a lot of informations/hooks were lost by manually creating the url.

So, I tried a specific approach for A links, so that they can use standard theming functions instead of recreating them.

The logic behind is that if the tag type is <a> (remember to set it in the configuration!) and the path is 'nolink', final destination should be an anchor.
BUT, url() function have some restrictions: valid path and valid anchor...

  1. I forced path to the same page (through current_path() function)
  2. I cheated a bit with the anchor by including a space (because url() function doesn't accept '#' anchors, but only '#someanchorname' anchors)

The url is now "same-path-as-this-page# ".
It works for me... does anyone have a better approach?

There was also a small validation error on PHP 5.2 due to ternary comparison operator short syntax, allowed only on PHP 5.3. I think that compatibility should be maintained if possibile as long as D7 still supports PHP 5.2, so I fixed the code.

gagarine’s picture

Status: Fixed » Needs review

Sorry I patch with #23 not 24... I will test that when I got some time (not this week). But I really want to push a new stable version next week. So thank for testing it this help a lot.

gagarine’s picture

Status: Needs review » Needs work

There was also a small validation error on PHP 5.2 due to ternary comparison operator short syntax, allowed only on PHP 5.3. I think that compatibility should be maintained if possible as long as D7 still supports PHP 5.2, so I fixed the code.

This had already be fixed. Patch need to be rerolled.

I want also to know witch module still break (so I can test) because now the class injection works better so some will perhaps works out of the box...

tchopshop’s picture

Tried patch from #26 and got an error.

Tried javascript above and it doesn't work because in my case because the nolink class appears on the li, not the a or the span.

Also, previously the a link was appearing above (not wrapping around) the ul submenu now the span is wrapping around the ul submenu.

I really need it to be a href="#" instead of a span...

gagarine’s picture

Patch 26 is in dev, just download the dev version. If you get an error.. write the error message in the comment please.

tchopshop’s picture

I missed the module configuration page -- so I put in 'a' instead of 'span' and now it works. However the href="#" is not showing up, so it's an 'a' tag without an href, is that what's intended?

DuaelFr’s picture

I use <a href="javascript:void();"> in my configuration and it is working very well.

Using an "a" tag without href attribute is not standard compliant, so certain old browsers could misinterpret it.

elBradford’s picture

@DuaelFr

I used <a href="javascript:void();"> and I get the following code spit out:

<a href="void();" title="" class="sf-depth-1  menuparent sf-with-ul">Resources<span class="sf-sub-indicator"> »</span></a>
 href="javascript:void();"

In fact, any sort of attribute i put on the anchor tag is popped outside the anchor tag as its sibling. Maybe it's my superfish menus.

DuaelFr’s picture

Sorry I just seen there was another patch since mine.
I don't know what differs exactly but mine allowed and managed attributes like this.

netdreamer’s picture

Rerolled patch #26 to remove already fixed code.
I needed this patch to make menu_minipanels module work, because it required standard theming hooks to work...

netdreamer’s picture

Sorry, wrong call to the theme hook... patch #35 rerolled
UPDATE: Ignore this patch. Something wrong with CR/LF...

netdreamer’s picture

Rerolled... last time, hopefully!

khiminrm’s picture

#37 Works for me with Menu Minipanels module. Thanks for a patch!

gagarine’s picture

Status: Needs work » Fixed

We don't use theme_menu_link anymore #1447988: Override theme_link instead of the theme_menu_link.

Please open a new issue if it's still buggy.

netdreamer’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Category: task » bug
Status: Fixed » Needs review
FileSize
647 bytes

Bug is still there, also on 2.x-dev, because "a" nolinks doesn't contain valid data for standard link rendering.

But, with the use of theme_link instead of theme_menu_link made in #1447988: Override theme_link instead of the theme_menu_link, patch was easy to made and it is also cleaner...
I also found a better way of creating the anchor link: by using url() "external" option, the null path problem with anchors explained in #1221294-37: option to use <a href="#"> for "nolink" items to not break other modules is solved.

Patch attached!
(I didn't open a separate issue, because it's exactly the same situation but handled with a different kind of patch...)

gagarine’s picture

Category: bug » support
Status: Needs review » Fixed

in admin/config/system/special_menu_items you can now write <a href="#"> for the nolink's tag and it will works. I don't want to encourage peoples without problem to create fake link. So I think this is a good enough solution.

Status: Fixed » Closed (fixed)

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

FrancoisL’s picture

Status: Closed (fixed) » Active

Hello

I try to make it work with Jquery Menu. I updated this module to be able to add <a href="#"> for nolink elements and it work fine first. But I'm using Jquery Menu and it does not consider the "#" as a link. I don't know if I have to post this on this module sizde or on Jquery Menu side but looking at this thread perhaps someone experienced something that is working with JQuery Menu?

Thanks in advance

FrancoisL’s picture

Status: Active » Closed (fixed)

I finally closed this by using this resource: http://drupal.org/node/143322

FrancoisL’s picture

Issue summary: View changes

escaped <

kobb’s picture

Issue summary: View changes

Or you could target the link with this selector:
a[href^="#"].some-class

or

li.some-class a[href^="#"]