Skip to content

Node.js based forum software built for the modern web

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

Julian Lamb81737bc0fb2
diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js
index e30b000470..bba039ea66 100644
--- a/public/src/ajaxify.js
+++ b/public/src/ajaxify.js
@@ -119,7 +119,7 @@ var ajaxify = {};
});
}
- utils.refreshTitle(url);
+ app.refreshTitle(url);
}, url, template);
diff --git a/public/src/app.js b/public/src/app.js
index 09c1f377bb..c7fe7835e7 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -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('');
}());
\ No newline at end of file
diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js
index 9e67ba51d5..eb8d0f3e20 100644
--- a/public/src/forum/footer.js
+++ b/public/src/forum/footer.js
@@ -112,7 +112,7 @@
socket.emit('api:notifications.mark_all_read', null, function() {
notifIcon.toggleClass('active', false);
- utils.refreshTitle();
+ app.refreshTitle();
// Update favicon + local count
Tinycon.setBubble(0);
@@ -167,7 +167,7 @@
type: 'warning',
timeout: 2000
});
- utils.refreshTitle();
+ app.refreshTitle();
// Update the favicon + local storage
var savedCount = parseInt(localStorage.getItem('notifications:count'),10) || 0;
@@ -209,7 +209,6 @@
});
socket.on('chatMessage', function(data) {
-
require(['chat'], function(chat) {
var modal = null;
if (chat.modalExists(data.fromuid)) {
@@ -220,10 +219,12 @@
chat.load(modal.attr('UUID'));
} else {
chat.toggleNew(modal.attr('UUID'), true);
+ app.alternatingTitle(data.username + ' has messaged you');
}
} else {
modal = chat.createModal(data.username, data.fromuid);
chat.toggleNew(modal.attr('UUID'), true);
+ app.alternatingTitle(data.username + ' has messaged you');
}
});
});
diff --git a/public/src/modules/taskbar.js b/public/src/modules/taskbar.js
index df7e8c460d..96ba98ac38 100644
--- a/public/src/modules/taskbar.js
+++ b/public/src/modules/taskbar.js
@@ -26,6 +26,7 @@ define(function() {
taskbar.minimizeAll();
module.load(uuid);
taskbar.toggleNew(uuid, false);
+ app.alternatingTitle('');
// Highlight the button
$(taskbar.tasklist).removeClass('active');
diff --git a/public/src/utils.js b/public/src/utils.js
index a7afef8ef7..926c05a0c5 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -169,23 +169,6 @@
return tags;
},
- refreshTitle: function(url) {
- if (!url) {
- var a = document.createElement('a');
- a.href = document.location;
- url = a.pathname.slice(1);
- }
- var notificationIcon;
-
- socket.emit('api:meta.buildTitle', url, function(title, numNotifications) {
- document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
- notificationIcon = notificationIcon || document.querySelector('.notifications a i');
- if (numNotifications > 0 && notificationIcon) {
- notificationIcon.className = 'fa fa-circle active';
- }
- });
- },
-
isRelativeUrl: function(url) {
var firstChar = url.slice(0, 1);
return (firstChar === '.' || firstChar === '/');
diff --git a/src/websockets.js b/src/websockets.js
index 80a4694dd1..6e18ee6edd 100644
--- a/src/websockets.js
+++ b/src/websockets.js
@@ -1158,6 +1158,4 @@ websockets.init = function(io) {
return userSockets;
}
}
-})(module.exports);
-
-
+})(module.exports);
\ No newline at end of file