Skip to content

Commit

Permalink
Merge pull request #440 from knu/agents_hover_menu
Browse files Browse the repository at this point in the history
Add a hover menu to the "Agents" nav link.
  • Loading branch information
knu committed Aug 13, 2014
2 parents a224a0b + 05e3736 commit 450e5a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ span.not-applicable:after {
right: 1px;
}

.navbar {
.dropdown.dropdown-hover:hover .dropdown-menu {
display: block;
}
}

// Flash

.flash {
Expand Down
26 changes: 24 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -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 = "<span class='glyphicon glyphicon-#{glyphicon}'></span> ".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)
Expand Down
8 changes: 7 additions & 1 deletion app/views/layouts/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

<% if user_signed_in? %>
<ul class='nav navbar-nav'>
<%= nav_link "Agents", agents_path %>
<%= nav_link "Agents", agents_path do %>
<ul class='dropdown-menu' role='menu'>
<%= nav_link "New Agent", new_agent_path, glyphicon: "plus" %>
<%= nav_link "Run event propagation", propagate_agents_path, glyphicon: "refresh" %>
<%= nav_link "View Diagram", diagram_path, glyphicon: 'random' %>
</ul>
<% end %>
<%= nav_link "Scenarios", scenarios_path %>
<%= nav_link "Events", events_path %>
<%= nav_link "Credentials", user_credentials_path %>
Expand Down

0 comments on commit 450e5a3

Please sign in to comment.