Skip to content

Commit

Permalink
Add helper for hiding global bar
Browse files Browse the repository at this point in the history
Currently the global bar is initially hidden, then shown using JavaScript - this
causes a shift in the layout of the page (aka jank) and means that the global
bar is not available for users without JavaScript.

To avoid this, a change will need to be made in Static to the make the global
bar be initially shown by default. The bar can then be hidden on pages that
don't need it - and doing this using CSS will avoid jank.

This change adds a helper that checks whether a page should hide the global bar;
the view can then add a class to the body element that will hide the global bar.

These changes won't have any effect until Static has been updated.
  • Loading branch information
injms committed Oct 18, 2021
1 parent fd2db83 commit fe9ccc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
14 changes: 14 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,18 @@ def render_govspeak(content, inverse: false)
raw(Govspeak::Document.new(content, sanitize: false).to_html)
end
end

def hide_global_bar?
paths_to_hide_global_bar_on = [
"^/coronavirus$",
"^/coronavirus/.*$",
"^/transition(.cy)?$",
"^/transition-check/.*$",
"^/eubusiness(\\..*)?$",
]

concatenated_regexes = Regexp.new(paths_to_hide_global_bar_on.join("|"))

request.path.match(concatenated_regexes).present?
end
end
11 changes: 9 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<%
body_classes = %w[]
body_classes << content_for(:body_classes) if content_for(:body_classes)
body_classes << "full-width" if content_for(:is_full_width_header)
body_classes << "hide-global-bar" if hide_global_bar?
%>

<!DOCTYPE html>
<html>
<head>
Expand All @@ -11,7 +18,7 @@
<%= stylesheet_link_tag "print.css", :media => "print", integrity: false %>
</head>

<body>
<%= content_tag(:body, class: body_classes) do %>
<div class="wrapper" id="wrapper">
<%= yield :back_link %>
<% unless (content_for(:is_full_width_header) || content_for(:back_link)) %>
Expand All @@ -29,5 +36,5 @@
<%= yield %>
</main>
</div>
</body>
<% end %>
</html>

0 comments on commit fe9ccc3

Please sign in to comment.