From 05e373614efea3858e4e01cfc67be8ab15630238 Mon Sep 17 00:00:00 2001 From: Akinori MUSHA Date: Tue, 12 Aug 2014 19:33:12 +0900 Subject: [PATCH] Add a hover menu to the "Agents" nav link. --- .../stylesheets/application.css.scss.erb | 6 +++++ app/helpers/application_helper.rb | 26 +++++++++++++++++-- app/views/layouts/_navigation.html.erb | 8 +++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/application.css.scss.erb b/app/assets/stylesheets/application.css.scss.erb index 866b0b17..2cbff3e3 100644 --- a/app/assets/stylesheets/application.css.scss.erb +++ b/app/assets/stylesheets/application.css.scss.erb @@ -98,6 +98,12 @@ span.not-applicable:after { right: 1px; } +.navbar { + .dropdown.dropdown-hover:hover .dropdown-menu { + display: block; + } +} + // Flash .flash { diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a76dea97..87de4b8e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,28 @@ module ApplicationHelper - def nav_link(name, path, options = {}) - content_tag :li, link_to(name, path), class: current_page?(path) ? 'active' : '' + def nav_link(name, path, options = {}, &block) + if glyphicon = options[:glyphicon] + name = " ".html_safe + name + end + content = link_to(name, path) + active = current_page?(path) + if block + # Passing a block signifies that the link is a header of a hover + # menu which contains what's in the block. + begin + @nav_in_menu = true + @nav_link_active = active + content += capture(&block) + class_name = "dropdown dropdown-hover #{@nav_link_active ? 'active' : ''}" + ensure + @nav_in_menu = @nav_link_active = false + end + else + # Mark the menu header active if it contains the current page + @nav_link_active ||= active if @nav_in_menu + # An "active" menu item may be an eyesore, hence `!@nav_in_menu &&`. + class_name = !@nav_in_menu && active ? 'active' : '' + end + content_tag :li, content, class: class_name end def yes_no(bool) diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index 8a7d8915..f33d8981 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -12,7 +12,13 @@ <% if user_signed_in? %>