Browse Source

add asterisk to browser tab if it is hidden when moved

romanmatiasko 10 years ago
parent
commit
ac5b981b03
1 changed files with 13 additions and 0 deletions
  1. 13 0
      public/javascripts/play.js

+ 13 - 0
public/javascripts/play.js

@@ -306,6 +306,19 @@ $(function() {
 
   $socket.on('move', function (data) {
     movePiece(from=data.move.from, to=data.move.to, promotion=data.move.promotion, rcvd=true);
+
+    if (typeof document.hidden === undefined) return;
+    if (document.hidden) {
+      var title = $('title').text();
+      $('title').text('* ' + title);
+
+      $(window).on('focus', removeAsterisk);
+
+      function removeAsterisk(e) {
+        $('title').text(title);
+        $(window).off('focus', removeAsterisk);
+      }
+    }
   });
 
   $socket.on('opponent-disconnected', function (data) {