OP Primary links - how to add target blanck to an item

Events happening in the community are now at Drupal community events on www.drupal.org.
betovarg's picture

Hi all,

Im currently using openpublish with its own menu system. I know it loads openpublishmenu.js and you have to add it to the template as it comes, which is something like:

<?php
print theme('openpublish_menu', $expanded_primary_links);
?>

(I wont paste the entire code, you can see it in the page-header.tpl.php) Anyway, Im trying to add target _blank to several items, so i installed the menu attributes module (http://drupal.org/project/menu_attributes) but since openpublish prints the menu with its own method, it does not work, the target _blank does not appear.

I was wondering if someone could shed light into the issue and let me know if there is a workaround. I wouldnt want to change openpublish's core, it would loose the point.

Thanx!

Comments

jQuery solutions for links to open in new window

GreenSkunk's picture

Some solutions using jQuery:

Option 1

$(document).ready(function() {
  $("li.classNameHere a").click(function(event)
    window.open($(this).attr('href'));
    event.preventDefault();
  });
});

Option 2

$(document).ready(function() {
  $("li#idNameHere a").attr('target', '_blank');
});

Note: This is from my phone and there may be typos.
I believe that you'll need to override OpenPublish template functions to have unique ids on your menu items ....... see http://groups.drupal.org/node/114894#comment-368689 you could write some logic in there to check if the menu items class (or ID) matched and add the deprecated anchor attribute TARGET to the array

In PHP, this may have to be done in a template override function but I haven't looked into a what would be involved per your case yet.

Similar post http://groups.drupal.org/node/121019 recoomends using another specific hook

It is a damn poor day when you don't learn something.

Thanx for your described

betovarg's picture

Thanx for your described solution above. Here are my thoughts on this issue, which I think is something that should be taken care from the openpublish team:

While I think that might work ok, why not work with the default menu system that drupal has? The module i'm trying to use in conjunction with the menu (menu attributes) has worked well in many sites, and does the trick. As far as i'm concerned, the openpublishmenu.js file that loads with their system is there only to give support for IE6 giving the < li > a class when the mouse is over it. I'm not concerned about IE6 at this moment, it is time for us to let it just die.

I believe that the best way to create a menu system, if you want to create one apart from the default, is to create a module. Why? because then you can create this other functionality that you want. A check for IE6 support (if wanted), add menu attributes (rel, class, id, target) to items (< li > or < a >, one or the other is needed in different situations), or maybe even being able to use this another module for the attributes. I'm not in favor of modding the code from the distro because this looses the whole idea of using something out of the box (or at least, not that DEEP in the box).

My main concern is that you might end up working more when the idea is to speed up the process. But well, that might just be me.

Thanx!

Edit: I ended up using drupal's default menu system. I placed my menu block with contexts, and added the attributes via the mentioned module. Now i have the openpublishmenu.js loading while doing nothing, another unnecesary mod has to be done. Besides, I also had to write my own css from scratch for the menu to achieve the same functionality as the one from openpublish, which took like an hour. That is all.

Simpler way

sher1's picture

You could use the Menu attributes module:
http://drupal.org/project/menu_attributes
I haven't used it for OpenPublish but since it extends the existing menu system, it should work nicely.

Thank you, but as i wrote in

betovarg's picture

Thank you, but as i wrote in the first post, i'm trying to use this module you said, it just wont work with openpublish's method of calling the menu.

Thanx!

OpenPublish

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: