From bf9e50083b31e2d3a608d62c4fe336697c37ab0c Mon Sep 17 00:00:00 2001 From: Ludovic POUJOL Date: Thu, 3 Mar 2016 17:43:30 +0100 Subject: [PATCH] Rename badge setting to desktopNotifications Also checks the browser status and display a warning message if it blocks desktop notifications --- client/css/style.css | 5 +++++ client/index.html | 5 +++-- client/js/lounge.js | 27 +++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/client/css/style.css b/client/css/style.css index 22f2fd16..5ac1fd16 100644 --- a/client/css/style.css +++ b/client/css/style.css @@ -1109,6 +1109,11 @@ button, color: #2ecc40; } +#settings .error { + color: #e74c3c; + margin-top: .2em; +} + #form { background: #eee; border-top: 1px solid #ddd; diff --git a/client/index.html b/client/index.html index f8b08412..3cc42ca5 100644 --- a/client/index.html +++ b/client/index.html @@ -243,8 +243,9 @@
diff --git a/client/js/lounge.js b/client/js/lounge.js index 4b943571..16f3b397 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -427,7 +427,7 @@ $(function() { var userStyles = $("#user-specified-css"); var settings = $("#settings"); var options = $.extend({ - badge: false, + desktopNotifications: false, colors: false, join: true, links: true, @@ -487,11 +487,11 @@ $(function() { }).find("input") .trigger("change"); - $("#badge").on("change", function() { + $("#desktopNotifications").on("change", function() { var self = $(this); if (self.prop("checked")) { if (Notification.permission !== "granted") { - Notification.requestPermission(); + Notification.requestPermission(updateDesktopNotificationStatus); } } }); @@ -689,7 +689,7 @@ $(function() { } toggleFaviconNotification(true); - if (options.badge && Notification.permission === "granted") { + if (options.desktopNotifications && Notification.permission === "granted") { var title; var body; @@ -792,6 +792,8 @@ $(function() { }); }); + windows.on("show", "#settings", updateDesktopNotificationStatus); + forms.on("submit", "form", function(e) { e.preventDefault(); var event = "auth"; @@ -918,6 +920,23 @@ $(function() { location.reload(); } + function updateDesktopNotificationStatus(){ + var checkbox = $("#desktopNotifications"); + var warning = $("#warnDisabledDesktopNotifications"); + + if (Notification.permission === "denied"){ + checkbox.attr("disabled", true); + checkbox.attr("checked", false); + warning.show(); + } else { + if (Notification.permission === "default" && checkbox.prop("checked")){ + checkbox.attr("checked", false); + } + checkbox.attr("disabled", false); + warning.hide(); + } + } + function sortable() { sidebar.sortable({ axis: "y",