Optional notification badge

This commit is contained in:
Mattias Erming 2014-09-15 11:16:45 -07:00
parent 9e1c33d658
commit 7d72f40d91
2 changed files with 19 additions and 7 deletions

View File

@ -193,7 +193,13 @@
</label> </label>
</div> </div>
<div class="col-sm-12"> <div class="col-sm-12">
<h2>Sound</h2> <h2>Notifications</h2>
</div>
<div class="col-sm-12">
<label class="opt">
<input id="badge" type="checkbox" name="badge">
Enable badge
</label>
</div> </div>
<div class="col-sm-12"> <div class="col-sm-12">
<label class="opt"> <label class="opt">

View File

@ -40,10 +40,6 @@ $(function() {
}; };
} }
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
$("#play").on("click", function() { pop.play(); }); $("#play").on("click", function() { pop.play(); });
$("#footer .icon").tooltip(); $("#footer .icon").tooltip();
@ -100,6 +96,7 @@ $(function() {
if (data.networks.length === 0) { if (data.networks.length === 0) {
$("#footer").find(".connect").trigger("click"); $("#footer").find(".connect").trigger("click");
} else { } else {
sidebar.find(".empty").hide();
sidebar.find(".networks").html( sidebar.find(".networks").html(
render("network", { render("network", {
networks: data.networks networks: data.networks
@ -115,7 +112,6 @@ $(function() {
); );
} }
sidebar.find(".empty").hide();
$("body").removeClass("signed-out"); $("body").removeClass("signed-out");
$("#sign-in").detach(); $("#sign-in").detach();
@ -237,6 +233,7 @@ $(function() {
var settings = $("#settings"); var settings = $("#settings");
var options = $.extend({ var options = $.extend({
badge: false,
join: true, join: true,
mode: true, mode: true,
motd: false, motd: false,
@ -270,6 +267,15 @@ $(function() {
}).find("input") }).find("input")
.trigger("change"); .trigger("change");
$("#badge").on("change", function() {
var self = $(this);
if (self.prop("checked")) {
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
}
});
var viewport = $("#viewport"); var viewport = $("#viewport");
viewport.on("click", ".lt, .rt", function(e) { viewport.on("click", ".lt, .rt", function(e) {
@ -401,8 +407,8 @@ $(function() {
var type = msg.type; var type = msg.type;
var highlight = type.contains("highlight"); var highlight = type.contains("highlight");
if (highlight || isQuery) { if (highlight || isQuery) {
pop.play();
if (!document.hasFocus() || !$(target).hasClass("active")) { if (!document.hasFocus() || !$(target).hasClass("active")) {
pop.play();
favico.badge("!"); favico.badge("!");
if (Notification.permission === "granted") { if (Notification.permission === "granted") {
var n = new Notification(msg.from + " says:", { var n = new Notification(msg.from + " says:", {