Download & Extend

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

Project:Special menu items module
Version:7.x-1.x-dev
Component:Code
Category:task
Priority:major
Assigned:gagarine
Status:needs review

Issue Summary

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".

Comments

#1

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

#2

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?

#3

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.

#4

#5

Status:postponed (maintainer needs more info)» active

Ok for an option. Patch welcome.

#6

Priority:normal» major

#7

any news?

#8

I just raise the issue to major.

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

#9

sub

#10

subscribe

#11

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.

#12

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.

#13

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.

#14

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

#15

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);

#16

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.

#17

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", "#");

#18

Assigned to:Anonymous» gagarine

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

#19

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

#20

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

#21

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.

#22

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

#23

Status:active» needs review

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

AttachmentSize
use-vars-and-attributes-1221294-23.patch 3.3 KB