diff --git a/hypha/static_src/src/javascript/apply/notifications.js b/hypha/static_src/src/javascript/apply/notifications.js new file mode 100644 index 0000000000000000000000000000000000000000..43e3de5143a943e3b449b3b212bf57384bf7d9c2 --- /dev/null +++ b/hypha/static_src/src/javascript/apply/notifications.js @@ -0,0 +1,17 @@ +function notificationToggle() { + document.getElementById("notificationDropdown").classList.toggle("show"); +} + +// Close the dropdown menu if the user clicks outside of it +window.onclick = function(event) { + if (!event.target.matches('.dropbtn, .dropbtn *')) { + var dropdowns = document.getElementsByClassName("dropdown-content"); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + openDropdown.classList.remove('show'); + } + } + } +} diff --git a/hypha/static_src/src/sass/apply/components/_activity-notifications.scss b/hypha/static_src/src/sass/apply/components/_activity-notifications.scss index 86d2dfdd3db2a8e7e58475141975adf329341092..9cdc26e2de6bb3adde2576c44e1f2164d39c6106 100644 --- a/hypha/static_src/src/sass/apply/components/_activity-notifications.scss +++ b/hypha/static_src/src/sass/apply/components/_activity-notifications.scss @@ -1,17 +1,11 @@ .dropbtn { - padding: 5px 12px; + padding: 7px 12px; cursor: pointer; } .dropdown { position: relative; display: inline-block; - - &:hover { - .dropdown-content { - display: block; - } - } } .dropdown-content { @@ -42,3 +36,7 @@ .source-label { background-color: #7dc588; } + +.show { + display:block; +} diff --git a/hypha/templates/base-apply.html b/hypha/templates/base-apply.html index a9d4b8e1fc094a8a0decae97e1e3d56cdc3f6bc4..c67b94e85295999ce301a5d21485165954e67000 100644 --- a/hypha/templates/base-apply.html +++ b/hypha/templates/base-apply.html @@ -30,6 +30,7 @@ <script src="{% static 'js/jquery.min.js' %}"></script> <script src="{% static 'js/js.cookie.min.js' %}"></script> <script src="{% static 'js/main-top.js' %}"></script> + <script src="{% static 'js/apply/notifications.js' %}"></script> {% if COOKIES_ACCEPTED and MATOMO_URL and MATOMO_SITEID %} {# we are only expecting strings, so make sure we escape the values #} <script> @@ -106,14 +107,15 @@ <div class="header__button-container"> {% if latest_notifications %} <div class="dropdown"> - <a href="#" class=" button--contains-icons dropbtn" aria-haspopup="activity" aria-expanded="false" role="button"> + <a href="#" onclick="return notificationToggle()" class=" button--contains-icons dropbtn" aria-haspopup="activity" aria-expanded="false" role="button"> <svg class="icon"><use xlink:href="#bell-icon"></use></svg> </a> - <div class="dropdown-content" role="activity"> + <div id="notificationDropdown" class="dropdown-content" role="activity"> + <p><b>Notifications</b></p> {% for notification in latest_notifications %} <p class="dropdown-item"> <span class="source-label">{{ notification.source_content_type.name|source_type }}</span> - <a href="{{ notification.source.get_absolute_url }}">{{ notification.source.title|capfirst }}</a> + <a href="{{ notification.source.get_absolute_url }}">{{ notification.source.title|capfirst|truncatechars:15 }}</a> : {{ notification.user }} {% ifequal notification.type 'comment' %}made a comment{% else %} {{ notification.message|safe }}{% endifequal %} </p> {% endfor %}