Wrap setting the document title into an own function to work around bugs in Chrome.
[Sone.git] / src / main / resources / static / javascript / sone.js
index a465b24..fb16b97 100644 (file)
@@ -742,6 +742,15 @@ function ajaxifyNotification(notification) {
        notification.find("form.mark-as-read button").click(function() {
                $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()});
        });
+       notification.find("a[class^='link-']").each(function() {
+               linkElement = $(this);
+               if (linkElement.is("[href^='viewPost']")) {
+                       id = linkElement.attr("class").substr(5);
+                       if (hasPost(id)) {
+                               linkElement.attr("href", "#post-" + id);
+                       }
+               }
+       });
        notification.find("form.dismiss button").click(function() {
                $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
                        /* dismiss in case of error, too. */
@@ -1026,24 +1035,41 @@ 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));
        }
-       changeIcon("images/icon.png");
 }
 
 function setActivity() {
        if (!focus) {
                title = document.title;
                if (title.indexOf('(') != 0) {
-                       document.title = "(!) " + title;
+                       setTitle("(!) " + title);
+               }
+               if (!iconBlinking) {
+                       setTimeout(toggleIcon, 1500);
+                       iconBlinking = true;
                }
-               setTimeout(toggleIcon, 1500);
        }
 }
 
+/**
+ * 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;
 
+/** Whether the icon is currently supposed to blink. */
+var iconBlinking = false;
+
 /**
  * Toggles the icon. If the window has gained focus and the icon is still
  * showing the activity state, it is returned to normal.
@@ -1054,6 +1080,7 @@ function toggleIcon() {
                        changeIcon("images/icon.png");
                        iconActive = false;
                }
+               iconBlinking = false;
        } else {
                iconActive = !iconActive;
                console.log("showing icon: " + iconActive);