Basic Notifications support for the web client.
This commit is contained in:
parent
5790c82837
commit
684fea5d62
1 changed files with 35 additions and 5 deletions
|
|
@ -249,17 +249,41 @@ function onBeforeUnload() {
|
||||||
|
|
||||||
var unread = 0;
|
var unread = 0;
|
||||||
var originalTitle = document.title;
|
var originalTitle = document.title;
|
||||||
|
var focused = true;
|
||||||
|
|
||||||
function onVisibilityChange() {
|
/*function onVisibilityChange() {
|
||||||
if(!document.hidden) {
|
if(!document.hidden) {
|
||||||
document.title = originalTitle;
|
document.title = originalTitle;
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
function onBlur(e) {
|
||||||
|
focused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onNewLine(originator, text) {
|
function onFocus(e) {
|
||||||
if(document.hidden) {
|
focused = true;
|
||||||
|
document.title = originalTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onNewLine(text, originator) {
|
||||||
|
if(!focused) {
|
||||||
unread++;
|
unread++;
|
||||||
document.title = "(" + unread + ") " + originalTitle;
|
document.title = "(" + unread + ") " + originalTitle;
|
||||||
|
Notification.requestPermission().then(function(result) {
|
||||||
|
if(result === "granted") {
|
||||||
|
var title = originalTitle === "" ? "Evennia" : originalTitle;
|
||||||
|
var options = {
|
||||||
|
body: text.replace(/(<([^>]+)>)/ig,"")
|
||||||
|
}
|
||||||
|
var n = new Notification(title, options);
|
||||||
|
n.onclick = function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
window.focus();
|
||||||
|
this.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,11 +292,17 @@ function onNewLine(originator, text) {
|
||||||
//
|
//
|
||||||
|
|
||||||
// Event when client finishes loading
|
// Event when client finishes loading
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
Notification.requestPermission();
|
||||||
|
|
||||||
// Event when client window changes
|
// Event when client window changes
|
||||||
$(window).bind("resize", doWindowResize);
|
$(window).bind("resize", doWindowResize);
|
||||||
|
|
||||||
$(document).on("visibilitychange", onVisibilityChange);
|
$(window).blur(onBlur);
|
||||||
|
$(window).focus(onFocus);
|
||||||
|
|
||||||
|
//$(document).on("visibilitychange", onVisibilityChange);
|
||||||
|
|
||||||
$("#inputfield").bind("resize", doWindowResize)
|
$("#inputfield").bind("resize", doWindowResize)
|
||||||
.keypress(onKeyPress)
|
.keypress(onKeyPress)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue