() document.title, ( , ).
. , - visibilityChange (actionFunction).
-, document.title - comeBackAlerts(). :
/* , actionFunction */
function visibilityChange(actionFunction){
window.focus();
var hidden = "hidden";
if (hidden in document){
document.addEventListener("visibilitychange", actionFunction);
}
else if ((hidden = "mozHidden") in document){
document.addEventListener("mozvisibilitychange", actionFunction);
}
else if ((hidden = "webkitHidden") in document){
document.addEventListener("webkitvisibilitychange", actionFunction);
}
else if ((hidden = "msHidden") in document){
document.addEventListener("msvisibilitychange", actionFunction);
}
else if ("onfocusin" in document){
document.onfocusin = document.onfocusout = actionFunction;
}
else{
window.onpageshow = window.onpagehide
= window.onfocus = window.onblur = actionFunction;
}
}
/* , */
var comeBackAlerts = (function () {
var oldTitle = document.getElementsByTagName('h1')[0].innerText;
var msg = "Arbir.ru";
var intervalId;
var blink = function(){
intervalId = setInterval( function() {
if(document.title == msg){
document.title = oldTitle;
}
else{
document.title = msg;
}
}, 1000);
};
var clear = function() {
clearInterval(intervalId);
document.title = oldTitle;
window.onmousemove = null;
window.onmouseout = null;
intervalId = null;
};
return function () {
if (!intervalId) {
blink();
window.onmousemove = clear;
}
};
}());
/* */
visibilityChange(comeBackAlerts);
, , .