Skip to content
Permalink
Browse files

Notification Center instead of inline checkboxes

  • Loading branch information...
Depado committed May 21, 2014
1 parent d9b3e68 commit 77fc14b8f047aafcbeb18db52788b88d3f140370
Showing with 34 additions and 14 deletions.
  1. +31 −3 static/custom.js
  2. +3 −11 views/index.html
@@ -30,17 +30,17 @@ socket.on('updatechat', function (username, data) {
+ d.getHours() + ':' + (d.getMinutes()<10?'0':'') + d.getMinutes() + '] ' + username + ' > ' + data
+ '</p></div></li>'
);
titleNotify(isActive);
if(!isActive) {
if(document.title != "[New] Unicorn Chat") document.title = "[New] Unicorn Chat";
if ("Notification" in window) {
if(Notification.permission === "granted") {
if($('#notify-on-message').is(':checked')) {
var notification = new Notification("New Message", {'body':username + ' : ' + data, 'icon': "/custom/favicon.gif"});
var notification = new Notification(username + ' : ' + data, {'icon': "/custom/favicon.gif"});
}
if ($('#notify-on-hl').is(':checked')) {
var patt = new RegExp("(^|\\W)"+selfusername+"(\\W|$)");
if(patt.test(data)) {
var notification = new Notification("Highlight", {'body':username + ' highlighted you.', 'icon': "/custom/favicon.gif"});
var notification = new Notification(username + ' highlighted you.', {'icon': "/custom/favicon.gif"});
}
}
}
@@ -53,6 +53,15 @@ socket.on('server-message', function(data) {
$('#conversation').append('<p>'+ data + '</p>');
titleNotify(isActive);
scrollDown();
if(!isActive) {
if ("Notification" in window) {
if(Notification.permission === "granted") {
if ($('#notify-on-server').is(':checked')) {
var notification = new Notification(data, {'icon': "/custom/favicon.gif"});
}
}
}
}
});

socket.on('username', function(data) {
@@ -86,6 +95,7 @@ socket.on('disconnect', function() {
$('#notify-settings').hide();
$('#nickname-send').html('Connect');
$('#conversation').append('<p>You\'re disconnected.</p>');
$('#notify-settings').popover('hide');
titleNotify(isActive);
scrollDown();
});
@@ -166,4 +176,22 @@ $(function() {
}, wait);
};
});
$('#notify-settings').popover({
'html':true,
'placement': 'top',
'content':
'<p>Notify me on...</p>' +
'<label style="font-weight: normal;">' +
'<input type="checkbox" name="checkbox" id="notify-on-hl">' +
'&nbsp;Highlight' +
'</label><br />'+
'<label style="font-weight: normal;">' +
'<input type="checkbox" name="checkbox" id="notify-on-message" />' +
'&nbsp;New Message' +
'</label><br />' +
'<label style="font-weight: normal;">' +
'<input type="checkbox" name="checkbox" id="notify-on-server" />' +
'&nbsp;Server Message' +
'</label>'
});
});
@@ -6,6 +6,8 @@
<link href='http://fonts.googleapis.com/css?family=Press+Start+2P' rel='stylesheet' type='text/css'>
<script src='/jquery/dist/jquery.min.js'></script>
<link href='//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css' rel='stylesheet'>
<script src='/bootstrap/js/tooltip.js'></script>
<script src='/bootstrap/js/popover.js'></script>
<link rel='stylesheet' type='text/css' href='/custom/custom.css'>
<script src='/socket.io/socket.io.js'></script>
<script src='/custom/custom.js'></script>
@@ -42,17 +44,7 @@
Activate Browser Notification
</button>
<span id="error-message"></span>
<span class="pull-right" id="notify-settings">
<label style="font-weight: normal;">
<input type="checkbox" name="checkbox" id="notify-on-hl">
Notify me on Highlight
</label>
<label style="font-weight: normal;">
<input type="checkbox" name="checkbox" id="notify-on-message" />
Notify on New Message&nbsp;
</label>
</span>
</div>
<button class="pull-right" id="notify-settings">Notification Center</button>
</div>
</div>
</div>

0 comments on commit 77fc14b

Please sign in to comment.
You can’t perform that action at this time.