cryptalk/public/js/lib/window.js

45 lines
859 B
JavaScript
Raw Permalink Normal View History

2014-09-23 14:16:02 -04:00
/*
2014-09-26 08:46:35 -04:00
Accepts:
'window:title'
2014-09-23 14:16:02 -04:00
Emits:
'window:focused'
'window:blurred'
Exports:
title = window.getTitle();
window.setTitle(title);
*/
2014-09-26 08:46:35 -04:00
define(['castrato'],function (mediator){
2014-09-23 14:16:02 -04:00
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; };
2014-09-23 14:16:02 -04:00
// Keep track of document focus/blur
if (window.addEventListener){
// Normal browsers
2017-02-22 17:09:50 -05:00
window.addEventListener('focus', focusCallback, true);
window.addEventListener('blur', blurCallback, true);
2014-09-23 14:16:02 -04:00
} else {
// IE
2017-02-22 17:09:50 -05:00
window.observe('focusin', focusCallback);
window.observe('focusout', blurCallback);
2014-09-23 14:16:02 -04:00
}
2014-09-26 08:46:35 -04:00
mediator.on('window:title',exports.setTitle);
2014-09-23 14:16:02 -04:00
return exports;
2014-09-26 08:46:35 -04:00
2014-09-23 14:16:02 -04:00
});