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){
|
2016-01-03 19:34:16 -05:00
|
|
|
|
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; };
|
|
|
|
|
2016-01-03 19:34:16 -05:00
|
|
|
|
2014-09-23 14:16:02 -04:00
|
|
|
// 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);
|
|
|
|
}
|
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
|
|
|
});
|