Wrap setting the document title into an own function to work around bugs in Chrome.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Jan 2011 06:29:01 +0000 (07:29 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Jan 2011 06:29:01 +0000 (07:29 +0100)
src/main/resources/static/javascript/sone.js

index 656e22c..fb16b97 100644 (file)
@@ -1035,7 +1035,7 @@ function markReplyAsKnown(replyElements) {
 function resetActivity() {
        title = document.title;
        if (title.indexOf('(') == 0) {
-               document.title = title.substr(title.indexOf(' ') + 1);
+               setTitle(title.substr(title.indexOf(' ') + 1));
        }
 }
 
@@ -1043,7 +1043,7 @@ function setActivity() {
        if (!focus) {
                title = document.title;
                if (title.indexOf('(') != 0) {
-                       document.title = "(!) " + title;
+                       setTitle("(!) " + title);
                }
                if (!iconBlinking) {
                        setTimeout(toggleIcon, 1500);
@@ -1052,6 +1052,18 @@ function setActivity() {
        }
 }
 
+/**
+ * Sets the window title after a small delay to prevent race-condition issues.
+ *
+ * @param title
+ *            The title to set
+ */
+function setTitle(title) {
+       setTimeout(function() {
+               document.title = title;
+       }, 50);
+}
+
 /** Whether the icon is currently showing activity. */
 var iconActive = false;