moved refreshTitle into app.js, messaging someone now invokes an alternating title, hehe

This commit is contained in:
Julian Lam
2013-12-05 23:24:47 -05:00
parent 385aa6df92
commit b81737bc0f
6 changed files with 46 additions and 26 deletions

View File

@@ -396,7 +396,44 @@ var socket,
$('body,html').animate({
scrollTop: $('html').height() - 100
});
}
};
var titleObj = {
active: false,
interval: undefined,
titles: []
};
app.alternatingTitle = function (title) {
if (typeof title !== 'string') return;
if (title.length > 0) {
titleObj.titles[1] = title;
if (titleObj.interval) {
clearInterval(titleObj.interval);
}
titleObj.interval = setInterval(function() {
window.document.title = titleObj.titles[titleObj.titles.indexOf(window.document.title) ^ 1];
}, 2000);
} else {
if (titleObj.interval) {
clearInterval(titleObj.interval);
}
if (titleObj.titles[0]) window.document.title = titleObj.titles[0];
}
};
app.refreshTitle = function(url) {
if (!url) {
var a = document.createElement('a');
a.href = document.location;
url = a.pathname.slice(1);
}
socket.emit('api:meta.buildTitle', url, function(title, numNotifications) {
titleObj.titles[0] = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
app.alternatingTitle('');
});
};
jQuery('document').ready(function () {
$('#search-form').on('submit', function () {
@@ -410,5 +447,5 @@ var socket,
showWelcomeMessage = location.href.indexOf('loggedin') !== -1;
app.loadConfig();
app.alternatingTitle('');
}());