diff --git a/static/html/joinchat.html b/static/html/joinchat.html index bd6c85f..15e9fb8 100644 --- a/static/html/joinchat.html +++ b/static/html/joinchat.html @@ -54,6 +54,7 @@ + diff --git a/static/js/chat/chat.js b/static/js/chat/chat.js index c72447b..b067fa1 100644 --- a/static/js/chat/chat.js +++ b/static/js/chat/chat.js @@ -5,6 +5,12 @@ const EventConnInitOk = 0; const EventConnInitNoSuchChat = 1; const EventConnInitMaxUsrsReached = 2; +const NewMsgTitle = "New message!"; + +window.onfocus = function() { + pageTitleNotification.off(); +} + new Vue({ el: '#app', @@ -16,6 +22,8 @@ new Vue({ okconnected: true, // True if email and username have been filled in fail: false, name: '', + onPage: false, + newMessagesNum: 0, }, created: function() { var self = this; @@ -46,6 +54,9 @@ new Vue({ }, methods: { addmsg: function(msg){ + if (document.hidden) { + pageTitleNotification.on(NewMsgTitle); + } this.chatContent += '
' + '' // Avatar + msg.username @@ -80,4 +91,4 @@ function getParameterByName(name, url) { if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); -} \ No newline at end of file +} diff --git a/static/js/lib/PageTitleNotification.js b/static/js/lib/PageTitleNotification.js new file mode 100755 index 0000000..702f1c5 --- /dev/null +++ b/static/js/lib/PageTitleNotification.js @@ -0,0 +1 @@ +!function(t,n){t.pageTitleNotification=function(){var e={currentTitle:null,interval:null};return{on:function(i,l){e.interval||(e.currentTitle=n.title,e.interval=t.setInterval(function(){n.title=e.currentTitle===n.title?i:e.currentTitle},l||1e3))},off:function(){t.clearInterval(e.interval),e.interval=null,n.title=e.currentTitle}}}()}(window,document); \ No newline at end of file