CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Bug and patch: playing nice with menu items containing "CiviCRM"
Pages: [1]

Author Topic: Bug and patch: playing nice with menu items containing "CiviCRM"  (Read 3018 times)

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Bug and patch: playing nice with menu items containing "CiviCRM"
October 24, 2010, 05:28:49 pm
Hi,

Currently, Civi is attaching an onClick handler to any item in the Drupal admin menu that contains the text "CiviCRM".  The purpose is to allow the "CiviCRM" menu item to display the CiviCRM navigation menu.  Unfortunately, the jQuery selector in use also adds this onClick handler to any item in the menu that contains "CiviCRM" anywhere, and this includes items named, for example, "foo CiviCRM bar", plus any of their parent items, since the parent items are also containers of that text.

An example of the problem in real life: the "CiviCRM congressional district" module ads a menu item labeled "CiviCRM congressional district" under "Site configuration," thus rendering the whole "Site configuration" menu un-clickable.

There's a comment in the code for this that says, "Need to fix this properly."  Here is a "relatively more proper" fix.  This uses child selector syntax to make sure only top-level menu items are checked for the "CiviCRM" string.  Then the onClick handler checks that the full string of the link text really is exactly 'CiviCRM', before executing the $.toggle() call.

The patch is:
Index: templates/CRM/common/Navigation.tpl
===================================================================
--- templates/CRM/common/Navigation.tpl   (revision 30326)
+++ templates/CRM/common/Navigation.tpl   (working copy)
@@ -84,9 +84,11 @@
 
 /* Need to fix this properly*/
 cj( function() {
-    cj("#admin-menu").find("li :contains('CiviCRM')").click(function() {
-        cj("#civicrm-menu").toggle();
-        return false;
+    cj("#admin-menu>ul>li>a:contains('CiviCRM')").click(function() {
+        if (cj(this).html() == 'CiviCRM' ) {
+            cj("#civicrm-menu").toggle();
+            return false;
+        }
     });
 
     var contactUrl = {/literal}"{crmURL p='civicrm/ajax/rest' q='className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=navigation' h=0 }"{literal};



This patch works for me and seems sound, but I have not tested it much. But there it is, in case it's useful.

- TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Bug and patch: playing nice with menu items containing "CiviCRM"
October 25, 2010, 01:14:24 am
Hi,

Looks like you are fetching every a that contains CiviCRM, but process only on the one that is exactly CiviCRM.

Completely untested, but should be faster to:
Code: [Select]
    cj("#admin-menu>ul>li>a").each(function() {
        if (cj(this).html() == 'CiviCRM' ) {
            cj(this).click (function() {cj("#civicrm-menu").toggle();  return false;}
        }
     });
 

Wouldn't it ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Bug and patch: playing nice with menu items containing "CiviCRM"
October 25, 2010, 07:26:04 am
Yeah, good call X+, I don't know why I didn't think of it that way.  You're probably right.

Probably to know which one is really the most efficient, we'd have to know more about the internal workings of  jQuery's :contains selector.  But considering that the admin menu is only going to have a limited number of top-level menu items, it may not be worth figuring out.

BTW, this is probably worth submitting an issue with patch, right?

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Rahul Bile

  • I post occasionally
  • **
  • Posts: 112
  • Karma: 16
  • impossible says, I M Possible
    • I AM POSSIBLE
Re: Bug and patch: playing nice with menu items containing "CiviCRM"
October 25, 2010, 09:02:27 am

Quote
BTW, this is probably worth submitting an issue with patch, right?

- Yes , you should create a issue with patch, it needs to be addressed.


Rahul.
Consider donating to CiviCRM if you use it. http://civicrm.org/donate

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Bug and patch: playing nice with menu items containing "CiviCRM"
October 25, 2010, 09:30:15 am
Quote from: TwoMice on October 25, 2010, 07:26:04 am

Probably to know which one is really the most efficient, we'd have to know more about the internal workings of  jQuery's :contains selector.  But considering that the admin menu is only going to have a limited number of top-level menu items, it may not be worth figuring out.

I'm pretty sure that doing a contains + adding a event click on each + doing a test on == is longer than simply doing a == and only add the events on the right
(:contains is an expensive selector, at least more expensive than nothing ;)

This being said, as you mention it, that's about 2,5 dom node anyway, so no big deal;

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

TwoMice

  • I post frequently
  • ***
  • Posts: 214
  • Karma: 16
    • Emphanos
  • CiviCRM version: Always current stable version
  • CMS version: Drupal 7
Re: Bug and patch: playing nice with menu items containing "CiviCRM"
October 25, 2010, 09:58:21 am
Issue created with patch: http://issues.civicrm.org/jira/browse/CRM-6990

Thanks to Xavier for improving the patch.  Right on all counts.   :)

-TM
Please consider contributing to help improve CiviCRM with the Make it Happen! initiative.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Bug and patch: playing nice with menu items containing "CiviCRM"

This forum was archived on 2017-11-26.