From 167db22e15c72c32cd67ce1a2b242dc4527e0b64 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 24 Jun 2021 19:31:19 +0000 Subject: slightly refactor for desktop notifications and fix minor issues --- view/js/main.js | 26 ++++++++++++++++++++++++++ view/js/mod_hq.js | 7 +++++-- view/tpl/hq_controls.tpl | 4 ++-- view/tpl/notifications_widget.tpl | 17 ++--------------- 4 files changed, 35 insertions(+), 19 deletions(-) (limited to 'view') diff --git a/view/js/main.js b/view/js/main.js index 78bd790cd..a286d53bf 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -1730,3 +1730,29 @@ function makeid(length) { return result; } +function push_notification_request(e) { + if (!('Notification' in window)) { + alert('This browser does not support push notifications'); + } + else if (Notification.permission !== 'granted') { + Notification.requestPermission(function(permission) { + if(permission === 'granted') { + $(e.target).closest('button').hide(); + } + }); + } +} + + +function push_notification(body, title) { + let options = { + body: body, + icon: '/images/hz-64.png', + silent: false + } + + let n = new Notification(title, options); + n.onclick = function (event) { + setTimeout(n.close.bind(n), 300); + } +} diff --git a/view/js/mod_hq.js b/view/js/mod_hq.js index 362045412..7583a4ddd 100644 --- a/view/js/mod_hq.js +++ b/view/js/mod_hq.js @@ -1,15 +1,18 @@ $(document).ready(function() { - $(document).on('click', '#jot-toggle', function(e) { + $(document).on('click', '.jot-toggle', function(e) { $(window).scrollTop(0); $('#jot-popup').toggle(); $('#profile-jot-text').focus(); }); - $(document).on('click', '#notes-toggle', function(e) { + $(document).on('click', '.notes-toggle', function(e) { $(window).scrollTop(0); $('#personal-notes').toggleClass('d-none'); $('#note-text').focus(); }); + $(document).on('hz:handleNetworkNotificationsItems', function(e, obj) { + push_notification(obj.message, obj.name); + }); }); diff --git a/view/tpl/hq_controls.tpl b/view/tpl/hq_controls.tpl index ce97a26a6..3adbfa7c0 100644 --- a/view/tpl/hq_controls.tpl +++ b/view/tpl/hq_controls.tpl @@ -1,7 +1,7 @@
{{foreach $entries as $e}} - {{/foreach}}
diff --git a/view/tpl/notifications_widget.tpl b/view/tpl/notifications_widget.tpl index 263318aad..5cbfcc214 100644 --- a/view/tpl/notifications_widget.tpl +++ b/view/tpl/notifications_widget.tpl @@ -354,8 +354,8 @@ if($('#nav-' + notifyType + '-menu .notification[data-b64mid=\'' + this.b64mid + '\']').length) return true; - if(!replace && !followup && this.thread_top && notifyType == 'network') { - sse_dektop_notification($('

' + this.message + '

').text(), this.name); + if(!replace && !followup && (this.thread_top && notifyType === 'network')) { + $(document).trigger('hz:handleNetworkNotificationsItems', this); } html = notifications_tpl.format(this.notify_link,this.photo,this.name,this.addr,this.message,this.when,this.hclass,this.b64mid,this.notify_id,this.thread_top,this.unseen,this.private_forum, encodeURIComponent(this.mids), this.body); @@ -471,19 +471,6 @@ sse_handleNotifications(obj, false, false); }); } - - function sse_dektop_notification(body, title) { - let options = { - body: body, - icon: '/images/hz-64.png', - silent: false - } - let n = new Notification(title, options); - n.onclick = function (event) { - setTimeout(n.close.bind(n), 300); - } - } -
-- cgit v1.2.3