Merge pull request #28 from lpoujol/desktopNotificationSetting

Remove "badge" setting and rely on browser choice for desktop notifcations
This commit is contained in:
Jérémie Astori 2016-03-06 14:45:52 -05:00
commit c4d628db49
3 changed files with 31 additions and 6 deletions

View file

@ -1128,6 +1128,11 @@ button,
color: #2ecc40;
}
#settings .error {
color: #e74c3c;
margin-top: .2em;
}
#form {
background: #eee;
border-top: 1px solid #ddd;

View file

@ -243,8 +243,9 @@
</div>
<div class="col-sm-12">
<label class="opt">
<input id="badge" type="checkbox" name="badge">
Enable badge
<input id="desktopNotifications" type="checkbox" name="desktopNotifications">
Enable desktop notifications<br>
<div class="error" id="warnDisabledDesktopNotifications"><strong>Warning</strong>: Desktop notifications are blocked by your web browser</div>
</label>
</div>
<div class="col-sm-12">

View file

@ -407,7 +407,7 @@ $(function() {
var userStyles = $("#user-specified-css");
var settings = $("#settings");
var options = $.extend({
badge: false,
desktopNotifications: false,
colors: false,
join: true,
links: true,
@ -467,11 +467,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);
}
}
});
@ -757,7 +757,7 @@ $(function() {
}
toggleFaviconNotification(true);
if (options.badge && Notification.permission === "granted") {
if (options.desktopNotifications && Notification.permission === "granted") {
var title;
var body;
@ -860,6 +860,8 @@ $(function() {
});
});
windows.on("show", "#settings", updateDesktopNotificationStatus);
forms.on("submit", "form", function(e) {
e.preventDefault();
var event = "auth";
@ -992,6 +994,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",