Skip to content

Commit

Permalink
chat: add blinking title on new message
Browse files Browse the repository at this point in the history
  • Loading branch information
skinass committed Jul 23, 2018
1 parent 603ad62 commit b3c2e29
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions static/html/joinchat.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
<script src="/js/lib/blinktitle.js"></script>
<script src="/js/chat/chat.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions static/js/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ new Vue({
},
methods: {
addmsg: function(msg){
if (document.hidden) {
blinkTitle("TechnoChat", "New message!", 1200, true);
}
this.chatContent += '<div class="chip" >'
+ '<img src="' + this.roboHash(msg.username) + '">' // Avatar
+ msg.username
Expand Down
47 changes: 47 additions & 0 deletions static/js/lib/blinktitle.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b3c2e29

Please sign in to comment.