From d45685f230018acb6d79de0bf33c568497bb27a9 Mon Sep 17 00:00:00 2001 From: Ian James Date: Tue, 20 Apr 2021 19:38:48 +0100 Subject: [PATCH] Add helper for hiding global bar 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. --- app/helpers/application_helper.rb | 14 ++++++++++++++ app/views/layouts/application.html.erb | 11 +++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 48a75ca12..f81c6c4c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -65,4 +65,18 @@ def render_govspeak(content) 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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 0ebe3f3ab..e8e628eeb 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -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? +%> + @@ -11,7 +18,7 @@ <%= stylesheet_link_tag "print.css", :media => "print", integrity: false %> -class="full-width"<% end %>> +<%= content_tag(:body, class: body_classes) do %>
<%= yield :back_link %> <% unless (content_for(:is_full_width_header) || content_for(:back_link)) %> @@ -37,5 +44,5 @@ <%= render 'govuk_publishing_components/components/feedback' %> <% end %>
- +<% end %>