diff --git a/static/html/joinchat.html b/static/html/joinchat.html index bd6c85f..d91ed2b 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..7d42b06 100644 --- a/static/js/chat/chat.js +++ b/static/js/chat/chat.js @@ -46,6 +46,9 @@ new Vue({ }, methods: { addmsg: function(msg){ + if (document.hidden) { + blinkTitle("TechnoChat", "New message!", 1200, true); + } this.chatContent += '
' + '' // Avatar + msg.username diff --git a/static/js/lib/blinktitle.js b/static/js/lib/blinktitle.js new file mode 100755 index 0000000..23e063c --- /dev/null +++ b/static/js/lib/blinktitle.js @@ -0,0 +1,47 @@ +var hold = ""; + +function blinkTitle(msg1, msg2, delay, isFocus, timeout) { + if (isFocus == null) { + isFocus = false; + } + if (timeout == null) { + timeout = false; + } + if(timeout){ + setTimeout(blinkTitleStop, timeout); + } + document.title = msg1; + if (isFocus == false) { + hold = window.setInterval(function() { + if (document.title == msg1) { + document.title = msg2; + } else { + document.title = msg1; + } + }, delay); + } + if (isFocus == true) { + var onPage = false; + window.onfocus = function() { + onPage = true; + }; + // window.onblur = function() { + // onPage = false; + // }; + hold = window.setInterval(function() { + if (onPage == false) { + if (document.title == msg1) { + document.title = msg2; + } else { + document.title = msg1; + } + } else { + document.title = msg1 + } + }, delay); + } +} + +function blinkTitleStop() { + clearInterval(hold); +}