expand side navigation only when in current in path
authorelijah <elijah@riseup.net>
Tue, 5 Nov 2013 23:56:47 +0000 (15:56 -0800)
committerelijah <elijah@riseup.net>
Tue, 5 Nov 2013 23:56:47 +0000 (15:56 -0800)
app/helpers/navigation_helper.rb

index 48b57e4..54a52ff 100644 (file)
@@ -76,15 +76,17 @@ module NavigationHelper
     menu.each do |item|
       title = menu_item_title(item)
       if title
-        haml 'li', :class => path_active(current_page_path, item) do
+        haml 'li', :class => path_active_class(current_page_path, item) do
           haml 'a', menu_item_title(item), :href => menu_item_path(item), :class => "level#{level}"
         end
-        display_menu(item.submenu, level+1)
+        if path_open?(current_page_path, item)
+          display_menu(item.submenu, level+1)
+        end
       end
     end
   end
 
-  def path_active(page_path, menu_item)
+  def path_active_class(page_path, menu_item)
     active = ''
     if menu_item.path == page_path
       active = 'active'
@@ -98,6 +100,10 @@ module NavigationHelper
     active
   end
 
+  def path_open?(page_path, menu_item)
+    menu_item.path == page_path || menu_item.path_prefix_of?(page_path)
+  end
+
   def current_page_path
     @current_page_path ||= begin
       if @page