Animate icon on activity.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Jan 2011 08:37:40 +0000 (09:37 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 27 Jan 2011 08:37:40 +0000 (09:37 +0100)
src/main/resources/static/javascript/sone.js

index e422237..a465b24 100644 (file)
@@ -1037,7 +1037,28 @@ function setActivity() {
                if (title.indexOf('(') != 0) {
                        document.title = "(!) " + title;
                }
-               changeIcon("images/icon-activity.png");
+               setTimeout(toggleIcon, 1500);
+       }
+}
+
+/** Whether the icon is currently showing activity. */
+var iconActive = false;
+
+/**
+ * Toggles the icon. If the window has gained focus and the icon is still
+ * showing the activity state, it is returned to normal.
+ */
+function toggleIcon() {
+       if (focus) {
+               if (iconActive) {
+                       changeIcon("images/icon.png");
+                       iconActive = false;
+               }
+       } else {
+               iconActive = !iconActive;
+               console.log("showing icon: " + iconActive);
+               changeIcon(iconActive ? "images/icon-activity.png" : "images/icon.png");
+               setTimeout(toggleIcon, 1500);
        }
 }