diff options
author | Ben Sturmfels <ben@sturm.com.au> | 2021-08-19 18:50:57 +1000 |
---|---|---|
committer | Ben Sturmfels <ben@sturm.com.au> | 2021-08-19 18:52:10 +1000 |
commit | ea5669f93ef5a06d22f27cf473f8a2fdcada1ce8 (patch) | |
tree | ddf380f344068efff5502d55f359c3151ca80ce3 /mediagoblin | |
parent | 6c408fb4ea24d43d0cb45dbc253f9de35af120bd (diff) | |
download | mediagoblin-ea5669f93ef5a06d22f27cf473f8a2fdcada1ce8.tar.lz mediagoblin-ea5669f93ef5a06d22f27cf473f8a2fdcada1ce8.tar.xz mediagoblin-ea5669f93ef5a06d22f27cf473f8a2fdcada1ce8.zip |
Convert notifications.js to vanilla JavaScript (no jQuery).
Diffstat (limited to 'mediagoblin')
-rw-r--r-- | mediagoblin/notifications/__init__.py | 1 | ||||
-rw-r--r-- | mediagoblin/static/js/notifications.js | 50 | ||||
-rw-r--r-- | mediagoblin/templates/mediagoblin/base.html | 10 |
3 files changed, 27 insertions, 34 deletions
diff --git a/mediagoblin/notifications/__init__.py b/mediagoblin/notifications/__init__.py index 96c0276a..6c31dd00 100644 --- a/mediagoblin/notifications/__init__.py +++ b/mediagoblin/notifications/__init__.py @@ -76,6 +76,7 @@ def mark_comment_notification_seen(comment_id, user): if comment == None: return + # TODO: This seems to always return no comments. comment_gmr = GenericModelReference.query.filter_by( obj_pk=comment.id, model_type=comment.__tablename__ diff --git a/mediagoblin/static/js/notifications.js b/mediagoblin/static/js/notifications.js index 78694f59..ae84e85b 100644 --- a/mediagoblin/static/js/notifications.js +++ b/mediagoblin/static/js/notifications.js @@ -1,4 +1,3 @@ -'use strict'; /** * GNU MediaGoblin -- federated, autonomous media hosting * Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. @@ -17,33 +16,26 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -var notifications = {}; - -(function (n) { - n._base = '/'; - n._endpoint = 'notifications/json'; - - n.init = function () { - $('.notification-gem').on('click', function () { - $('.header_dropdown_down:visible').click(); - }); - } - -})(notifications) - -$(document).ready(function () { - notifications.init(); +'use strict'; - var mark_all_comments_seen = document.getElementById('mark_all_comments_seen'); +(function () { + // Small pill/gem indicator showing number of unseen comments. Comments are + // shown inside the header panel which may be hidden. + var notificationGem = document.querySelector('.notification-gem'); + notificationGem.addEventListener('click', function() { + panel.show() + }); - if (mark_all_comments_seen) { - mark_all_comments_seen.href = '#'; - mark_all_comments_seen.onclick = function() { - $.ajax({ - type: 'GET', - url: mark_all_comments_seen_url, - success: function(res, status, xhr) { window.location.reload(); }, - }); - } - } -}); + // Mark all comments seen feature. + // + // TODO: Currently broken due to bug in mark_comment_notification_seen(). + var mark_all_comments_seen = document.getElementById('mark_all_comments_seen'); + if (mark_all_comments_seen) { + mark_all_comments_seen.href = '#'; + mark_all_comments_seen.onclick = function() { + fetch(mark_all_comments_seen_url).then(function(response) { + window.location.reload(); + }); + }; + } +})(); diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index 4b3b9846..4bbaa21c 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -42,11 +42,6 @@ href="{{ request.staticdirect('/images/goblin.ico') }}" /> <script type="text/javascript" src="{{ request.staticdirect('/js/extlib/jquery.js') }}"></script> - <script type="text/javascript" - src="{{ request.staticdirect('/js/notifications.js') }}"></script> - <script> - var mark_all_comments_seen_url = "{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}" - </script> {# For clarification, the difference between the extra_head.html template # and the head template hook is that the former should be used by @@ -185,6 +180,11 @@ {%- endblock mediagoblin_body %} <script type="text/javascript" src="{{ request.staticdirect('/js/header_dropdown.js') }}"></script> + <script type="text/javascript" + src="{{ request.staticdirect('/js/notifications.js') }}"></script> + <script> + var mark_all_comments_seen_url = "{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}" + </script> {% include 'mediagoblin/bits/body_end.html' %} </body> </html> |