Rework pretty much all image displaying code
[Sone.git] / src / main / resources / static / javascript / sone.js
index 3204507..3235f51 100644 (file)
@@ -145,7 +145,7 @@ function filterSoneId(soneId) {
  *            The date and time of the last update (formatted for display)
  */
 function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated, lastUpdatedText) {
-       var updateSone = sone.find(".sone." + filterSoneId(soneId));
+    var updateSone = sone.find(".sone." + filterSoneId(soneId));
        updateSone.toggleClass("unknown", status == "unknown").
                toggleClass("idle", status == "idle").
                toggleClass("inserting", status == "inserting").
@@ -1878,6 +1878,22 @@ var currentSoneMenuId;
 /** Timeout handler for the next-to-show Sone context menu. */
 var currentSoneMenuTimeoutHandler;
 
+function replaceImagesWithErrorWithBrokenImages() {
+       var replaceImage = function(imageElement, sourcePath) {
+               $(imageElement).attr("src", sourcePath)
+                       .attr("width", "160")
+                       .attr("height", "120")
+                       .attr("style", "position: absolute; top: 0px; left: 0px; opacity: .25");
+       };
+
+       $(".image-in-album .image img").error(function () {
+               replaceImage(this, "images/broken-image.png");
+       });
+       $(".album .image img").error(function () {
+               replaceImage(this, "images/broken-album.png");
+       });
+}
+
 $(document).ready(function() {
 
        /* rip out the status update textarea. */
@@ -1946,11 +1962,11 @@ $(document).ready(function() {
 
        /* Ajaxifies all posts. */
        /* calling getTranslation here will cache the necessary values. */
-       getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {
-               getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(text) {
-                       getTranslation("WebInterface.DefaultText.Reply", function(text) {
-                               getTranslation("WebInterface.Button.Comment", function(text) {
-                                       sone.find(".post").each(function() {
+       getTranslation("WebInterface.Confirmation.DeletePostButton", function() {
+               getTranslation("WebInterface.Confirmation.DeleteReplyButton", function() {
+                       getTranslation("WebInterface.DefaultText.Reply", function() {
+                getTranslation("WebInterface.Button.Comment", function () {
+                    sone.find(".post").each(function() {
                                                ajaxifyPost(this);
                                        });
                                });
@@ -2005,6 +2021,8 @@ $(document).ready(function() {
        /* activate status polling. */
        setTimeout(getStatus, 5000);
 
+       replaceImagesWithErrorWithBrokenImages();
+
        /* reset activity counter when the page has focus. */
        $(window).focus(function() {
                focus = true;