cryptalk/public/js/cryptalk_modules/win.js

40 lines
785 B
JavaScript
Raw Normal View History

2014-09-23 14:16:02 -04:00
/*
Emits:
'window:focused'
'window:blurred'
Exports:
title = window.getTitle();
window.setTitle(title);
*/
define(['mediator'],function (mediator){
var exports = {},
focusCallback = function() {
2014-09-24 11:20:20 -04:00
mediator.emit('window:focused');
2014-09-23 14:16:02 -04:00
},
blurCallback = function() {
2014-09-24 11:20:20 -04:00
mediator.emit('window:blurred');
2014-09-23 14:16:02 -04:00
};
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);
}
return exports;
});