cryptalk/client/source/window.js

42 lines
887 B
JavaScript
Raw Normal View History

2021-11-03 15:35:57 -04:00
/*
Accepts:
'window:title'
Emits:
'window:focused'
'window:blurred'
Exports:
title = window.getTitle();
window.setTitle(title);
*/
export default function(mediator) {
var exports = {},
focusCallback = function() {
mediator.emit('window:focused');
},
blurCallback = function() {
mediator.emit('window:blurred');
};
exports.setTitle = function(t) { document.title = t; },
exports.getTitle = function() { return document.title; };
// Keep track of document focus/blur
if (window.addEventListener){
// Normal browsers
window.addEventListener('focus', focusCallback, true);
window.addEventListener('blur', blurCallback, true);
} else {
// IE
window.observe('focusin', focusCallback);
window.observe('focusout', blurCallback);
}
mediator.on('window:title',exports.setTitle);
return exports;
}