Fix notifications

This commit is contained in:
Mattias Erming 2014-09-14 06:18:53 -07:00
parent 4d1aa174a1
commit 0c6c54bc83
3 changed files with 20 additions and 17 deletions

View File

@ -12,7 +12,7 @@
<link rel="stylesheet" href="css/style.css">
<link id="theme" rel="stylesheet" href="<%=theme%>">
<link rel="shortcut icon" href="/img/favicon.png">
<link rel="shortcut icon" href="/img/logo-32.png">
</head>
<body class="<%= public ? "public" : "" %>">
@ -225,6 +225,7 @@
<script src="js/libs/handlebars/equal.js"></script>
<script src="js/libs/handlebars/tz.js"></script>
<script src="js/libs/handlebars/uri.js"></script>
<script src="js/libs/handlebars/users.js"></script>
<script src="js/libs/jquery.js"></script>
<script src="js/libs/jquery/bootstrap.js"></script>
<script src="js/libs/jquery/cookie.js"></script>
@ -233,14 +234,16 @@
<script src="js/libs/jquery/stickyscroll.js"></script>
<script src="js/libs/jquery/tabcomplete.js"></script>
<script src="js/libs/moment.js"></script>
<script src="js/libs/notification.js"></script>
<script src="js/libs/socket.io.js"></script>
<script src="js/libs/string.contains.js"></script>
<script src="js/libs/uri.js"></script>
<% } else { %>
<script src="js/libs.min.js"></script>
<% } %>
<script src="js/shout.templates.js"></script>
<script src="js/shout.js"></script>
<% } %>
</body>
</html>

View File

@ -41,7 +41,7 @@ $(function() {
}
// Request notification permissions if we don't already have it
if (Notification.permission !== 'granted') {
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
@ -411,25 +411,24 @@ $(function() {
});
chat.on("msg", ".messages", function(e, target, msg) {
var btn = sidebar.find(".chan[data-target=" + target + "]:not(.active)");
var query = btn.hasClass("query");
var button = sidebar.find(".chan[data-target=" + target + "]");
var isQuery = button.hasClass("query");
var type = msg.type;
var highlight = type.contains("highlight");
if (highlight || query) {
if (highlight || isQuery) {
pop.play();
if (!document.hasFocus() || !$(target).hasClass("active")) {
favico.badge("!");
if (Notification.permission === 'granted') {
var n = new Notification( msg.from + ' - ' + btn.data('title'), {
body: msg.text,
icon: '/img/favicon.png'
if (Notification.permission === "granted") {
var n = new Notification(msg.from + " says:", {
body: msg.text.trim(),
icon: ""
} );
n.onclick = function() {
window.focus();
btn.click();
button.click();
this.close();
};
// Close notification after 5s
window.setTimeout(function() {
n.close();
}, 5 * 1000);
@ -437,7 +436,8 @@ $(function() {
}
}
if (btn.length === 0) {
button = button.filter(":not(.active)");
if (button.length === 0) {
return;
}
@ -451,12 +451,12 @@ $(function() {
return;
}
var badge = btn.find(".badge");
var badge = button.find(".badge");
if (badge.length !== 0) {
var i = (badge.data("count") || 0) + 1;
badge.data("count", i);
badge.html(i > 999 ? (i / 1000).toFixed(1) + "k" : i);
if (highlight || query) {
if (highlight || isQuery) {
badge.addClass("highlight");
}
}

View File

@ -1,8 +1,8 @@
module.exports = {
public: true,
host: "0.0.0.0",
port: 9000,
port: 9090,
theme: "themes/example.css",
home: "",
debug: false
debug: true
};