Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/application/conpherence/behavior-pontificate.js
/** | /** | ||||
* @provides javelin-behavior-conpherence-pontificate | * @provides javelin-behavior-conpherence-pontificate | ||||
* @requires javelin-behavior | * @requires javelin-behavior | ||||
* javelin-dom | * javelin-dom | ||||
* javelin-util | * javelin-util | ||||
* javelin-workflow | * javelin-workflow | ||||
* javelin-stratcom | * javelin-stratcom | ||||
*/ | */ | ||||
JX.behavior('conpherence-pontificate', function(config) { | JX.behavior('conpherence-pontificate', function(config) { | ||||
var page_is_visible = true; | |||||
var hidden = "hidden"; | |||||
var onchange = function(evt) { | |||||
var v = true; | |||||
var h = false; | |||||
var evtMap = { | |||||
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h | |||||
}; | |||||
evt = evt || window.event; | |||||
if (evt.type in evtMap) { | |||||
page_is_visible = evtMap[evt.type]; | |||||
} else { | |||||
page_is_visible = !page_is_visible; | |||||
} | |||||
} | |||||
if (hidden in document) { | |||||
document.addEventListener("visibilitychange", onchange); | |||||
} else if ((hidden = "mozHidden") in document) { | |||||
document.addEventListener("mozvisibilitychange", onchange); | |||||
} else if ((hidden = "webkitHidden") in document) { | |||||
document.addEventListener("webkitvisibilitychange", onchange); | |||||
} else if ((hidden = "msHidden") in document) { | |||||
document.addEventListener("msvisibilitychange", onchange); | |||||
} else if ('onfocusin' in document) { | |||||
document.onfocusin = document.onfocusout = onchange; | |||||
} else { | |||||
window.onpageshow = onchange; | |||||
window.onpagehide = onchange; | |||||
window.onfocus = onchange; | |||||
window.onblur = onchange; | |||||
} | |||||
JX.Stratcom.listen('aphlict-receive-message', null, function(e) { | JX.Stratcom.listen('aphlict-receive-message', null, function(e) { | ||||
var message = e.getData(); | var message = e.getData(); | ||||
if (message.type != 'message') { | if (message.type != 'message') { | ||||
// Not a message event. | // Not a message event. | ||||
return; | return; | ||||
} | } | ||||
Show All 22 Lines | JX.Stratcom.listen('aphlict-receive-message', null, function(e) { | ||||
new JX.Workflow('/conpherence/update/' + thread_id + '/') | new JX.Workflow('/conpherence/update/' + thread_id + '/') | ||||
.setData(params) | .setData(params) | ||||
.setHandler(function(r) { | .setHandler(function(r) { | ||||
var messages = JX.DOM.find(document, 'div', 'conpherence-messages'); | var messages = JX.DOM.find(document, 'div', 'conpherence-messages'); | ||||
JX.DOM.appendContent(messages, JX.$H(r.transactions)); | JX.DOM.appendContent(messages, JX.$H(r.transactions)); | ||||
messages.scrollTop = messages.scrollHeight; | messages.scrollTop = messages.scrollHeight; | ||||
if (!page_is_visible) { | |||||
var hierarchy = JX.$N('div', {}, JX.$H(r.transactions)); | |||||
for (var i = 0; i < hierarchy.children.length; i++) { | |||||
var child = hierarchy.children[i]; | |||||
var notificationTitle = JX.DOM.find( | |||||
child, | |||||
"div", | |||||
"conpherence-message-author").innerText; | |||||
var notificationBody = JX.DOM.find( | |||||
child, | |||||
"div", | |||||
"conpherence-message-content").innerText; | |||||
var notificationIcon = child.style.backgroundImage; | |||||
notificationIcon = notificationIcon.substr( | |||||
4, | |||||
notificationIcon.length - 5); | |||||
if ("Notification" in window) { | |||||
if (Notification.permission === "granted") { | |||||
var notification = new Notification( | |||||
notificationTitle, | |||||
{ | |||||
body: notificationBody, | |||||
icon: notificationIcon | |||||
}); | |||||
notification.onclick = function() { window.focus(); }; | |||||
} else if (Notification.permission !== "denied") { | |||||
Notification.requestPermission(function(permission) { | |||||
if (!("permission" in Notification)) { | |||||
Notification.permission = permission; | |||||
} | |||||
if (permission === "granted") { | |||||
var notification = new Notification( | |||||
notificationTitle, | |||||
{ | |||||
body: notificationBody, | |||||
icon: notificationIcon | |||||
}); | |||||
notification.onclick = function() { window.focus(); }; | |||||
} | |||||
}); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
// TODO: Continued grossness from above. | // TODO: Continued grossness from above. | ||||
infonode.value = r.latest_transaction_id; | infonode.value = r.latest_transaction_id; | ||||
}) | }) | ||||
.start(); | .start(); | ||||
}); | }); | ||||
var onsubmit = function(e) { | var onsubmit = function(e) { | ||||
e.kill(); | e.kill(); | ||||
if ("Notification" in window) { | |||||
if (Notification.permission !== "denied") { | |||||
Notification.requestPermission(function(permission) { | |||||
if (!("permission" in Notification)) { | |||||
Notification.permission = permission; | |||||
} | |||||
}); | |||||
} | |||||
} | |||||
hach-que: Chrome only allows the page to request permission for desktop notifications when initiated by a… | |||||
var form = e.getNode('tag:form'); | var form = e.getNode('tag:form'); | ||||
var root = e.getNode('conpherence-layout'); | var root = e.getNode('conpherence-layout'); | ||||
var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane'); | var messages_root = JX.DOM.find(root, 'div', 'conpherence-message-pane'); | ||||
var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane'); | var header_root = JX.DOM.find(root, 'div', 'conpherence-header-pane'); | ||||
var form_root = JX.DOM.find(root, 'div', 'conpherence-form'); | var form_root = JX.DOM.find(root, 'div', 'conpherence-form'); | ||||
var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages'); | var messages = JX.DOM.find(messages_root, 'div', 'conpherence-messages'); | ||||
var fileWidget = null; | var fileWidget = null; | ||||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
Chrome only allows the page to request permission for desktop notifications when initiated by a user action (such as a click). Hence this has to live here (or on some other button).