Skip to content

Commit

Permalink
Merge branch 'hotfix/4494-safari-menu-bug' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rfultz committed Mar 19, 2021
2 parents c3ee590 + 743f970 commit b85db8a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
28 changes: 4 additions & 24 deletions fec/fec/templates/partials/navigation/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,33 @@
<button class="js-nav-toggle site-nav__button" aria-controls="site-menu">Menu</button>
<div id="site-menu" class="site-nav__container">
<ul class="site-nav__panel site-nav__panel--main">
<!-- <li class="mobile-search utility-nav__search">
<form accept-charset="UTF-8" action="/search" id="search_form" class="combo" method="get" role="search">
<input type="hidden" name="type" value="candidates">
<input type="hidden" name="type" value="committees">
<input type="hidden" name="type" value="site">
<label class="u-visually-hidden" for="query">Search</label>
<div class="combo combo--search combo--search--mini">
<input
class="js-site-search combo__input"
autocomplete="off"
id="query"
name="query"
type="text"
aria-label="Search FEC.gov">
<button type="submit" class="button--standard combo__button button--search">
<span class="u-visually-hidden">Search</span>
</button>
</div>
</form>
</li> -->
<li><h2 class="site-nav__title u-under-lg-only">Menu</h2></li>
<li class="site-nav__item u-under-lg-only">
<a class="site-nav__link" href="/" rel="home">
<span class="site-nav__link__title">Home</span>
</a>
</li>
<li class="site-nav__item" data-submenu="data">
<a class="site-nav__link {% if self.content_section == 'data' or parent == 'data' %}is-parent{% endif %}" href="/data/" >
<a class="site-nav__link {% if self.content_section == 'data' or parent == 'data' %}is-parent{% endif %}" href="/data/" tabindex="0">
<span class="site-nav__link__title">
Campaign finance data</span>
</a>
{% include 'partials/navigation/nav-data.html' %}
</li>
<li class="site-nav__item site-nav__item--secondary" data-submenu="help">
<a href="/help-candidates-and-committees/" class="site-nav__link {% if self.content_section == 'help' %}is-parent{% endif %}">
<a href="/help-candidates-and-committees/" class="site-nav__link {% if self.content_section == 'help' %}is-parent{% endif %}" tabindex="0">
<span class="site-nav__link__title">Help for candidates and committees</span>
</a>
{% include 'partials/navigation/nav-help.html' %}
</li>
<li class="site-nav__item" data-submenu="legal">
<a href="/legal-resources/" class="site-nav__link {% if self.content_section == 'legal' or parent == 'legal' %}is-parent{% endif %}">
<a href="/legal-resources/" class="site-nav__link {% if self.content_section == 'legal' or parent == 'legal' %}is-parent{% endif %}" tabindex="0">
<span class="site-nav__link__title">Legal resources</span>
</a>
{% include 'partials/navigation/nav-legal.html' %}
</li>
<li class="site-nav__item site-nav__item--secondary" data-submenu="about">
<a href="/about/" class="site-nav__link {% if self.content_section == 'about' %}is-parent{% endif %}">
<a href="/about/" class="site-nav__link {% if self.content_section == 'about' %}is-parent{% endif %}" tabindex="0">
<span class="site-nav__link__title">About</span>
</a>
{% include 'partials/navigation/nav-about.html' %}
Expand Down
13 changes: 10 additions & 3 deletions fec/home/templatetags/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,22 @@ def web_app_url(path):

@register.filter()
def highlight_matches(text):
"""Replaces the highlight markers with span tags for digitalgov search results"""
highlighted_text = text.replace('\ue000', '<span class="t-highlight">').replace('\ue001', '</span>')
"""
Replaces the highlight markers with span tags for digitalgov search results.
Because format_html uses str.format, remove { and } because they are special characters.
"""
cleaned_text = text.replace("{", "").replace("}", "")
highlighted_text = cleaned_text.replace(
"\ue000", '<span class="t-highlight">'
).replace("\ue001", "</span>")

return format_html(highlighted_text)


@register.filter(name='splitlines')
def splitlines(value):
"""
Returns the value turned into a list.
Returns the value turned into a list.
"""
return value.splitlines()

Expand Down
23 changes: 23 additions & 0 deletions fec/home/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.test import TestCase

from home.templatetags.filters import highlight_matches


class TestFilters(TestCase):

def test_highlight_matches(self):
text = '\ue000Highlighted\ue001 results'
highlighted_text = highlight_matches(text)
self.assertEqual(
highlighted_text,
'<span class="t-highlight">Highlighted</span> results'
)

def test_highlight_matches_with_brackets(self):
"""highlight_matches should remove { and } from results"""
text = '\ue000Highlighted\ue001 {results}'
highlighted_text = highlight_matches(text)
self.assertEqual(
highlighted_text,
'<span class="t-highlight">Highlighted</span> results'
)

0 comments on commit b85db8a

Please sign in to comment.