David Jean Louis avatar David Jean Louis committed c55fbbc

Better display of selected menu items

Comments (0)

Files changed (4)

admin_tools/media/admin_tools/css/menu.css

 
 #header ul#navigation-menu li:hover,
 #header ul#navigation-menu li.over,
-#header ul#navigation-menu li.active {
+#header ul#navigation-menu li.selected {
     background: url(../images/admin-tools.png) repeat-x 0 -245px;
 }
 
 }
 
 #header ul#navigation-menu li.disabled:hover,
-#header ul#navigation-menu li.disabled .hover {
+#header ul#navigation-menu li.disabled .over {
     background: none;
 }

admin_tools/menu/models.py

         """
         pass
 
+    def is_selected(self, request):
+        """
+        Helper method that returns ``True`` if the menu item is active. 
+        A menu item is considered as active if it's URL or one of its 
+        descendants URL is equals to the current URL.
+        """
+        current_url = request.get_full_path()
+        return self.url == current_url or \
+            len([c for c in self.children if c.is_selected(request)]) > 0
+
 
 class AppListMenuItem(MenuItem, AppListElementMixin):
     """
         if not len(self.children):
             self.enabled = False
 
+    def is_selected(self, request):
+        """
+        A bookmark menu item is never considered as active, the real item is.
+        """
+        return False
+
 
 class DefaultMenu(Menu):
     """

admin_tools/menu/templates/admin_tools/menu/item.html

 {% load admin_tools_menu_tags %}
 {% spaceless %}
-<li class="menu-item{% ifequal index 1 %} first{% endifequal %}{% if not item.enabled %} disabled{% endif %}{% if item.css_classes %} {{ item.css_classes|join:' ' }}{% endif %}">
-    <a{% if item.url and item.enabled %} href="{{ item.url }}"{% endif %}{% if item.description %} title="{{ item.description }}"{% endif %}{% if item.accesskey %} accesskey="{{ item.accesskey }}"{% endif %}>{% if item.children %}<span class="icon"></span>{% endif %}{{ item.title }}</a>
+<li class="menu-item{% ifequal index 1 %} first{% endifequal %}{% if not item.enabled %} disabled{% endif %}{% if selected %} selected{% endif %}{% if item.css_classes %} {{ item.css_classes|join:' ' }}{% endif %}">
+<a href="{% if item.url and item.enabled %}{{ item.url }}{% else %}#{% endif %}"{% if item.description %} title="{{ item.description }}"{% endif %}{% if item.accesskey %} accesskey="{{ item.accesskey }}"{% endif %}>{% if item.children %}<span class="icon"></span>{% endif %}{{ item.title }}</a>
     {% if item.children %}
     <ul>
         {% for child_item in item.children %}

admin_tools/menu/templatetags/admin_tools_menu_tags.py

         'template': item.template,
         'item': item,
         'index': index,
+        'selected': item.is_selected(context['request'])
     })
     return context
 admin_tools_render_menu_item = tag_func(admin_tools_render_menu_item)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.