From b41ad8c91e905abd2d4452763004ddf9621ed02b Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 10 Aug 2012 20:17:42 +0200 Subject: Deal with deleting faulty images. --- web/js/011-display.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/web/js/011-display.js b/web/js/011-display.js index ab56562..479cb8e 100644 --- a/web/js/011-display.js +++ b/web/js/011-display.js @@ -98,9 +98,16 @@ $(document).ready(function() { for (i = 0; i < currentAlbum.photos.length; ++i) { link = $(""); image = $("\"""); - link.append(image); image.get(0).photo = currentAlbum.photos[i]; + link.append(image); photos.push(link); + (function(theLink, theImage, theAlbum) { + theImage.error(function() { + photos.splice(photos.indexOf(theLink), 1); + theLink.remove(); + theAlbum.photos.splice(theAlbum.photos.indexOf(theImage.get(0).photo), 1); + }); + })(link, image, currentAlbum); } thumbsElement = $("#thumbs"); thumbsElement.empty(); @@ -112,11 +119,16 @@ $(document).ready(function() { image = $("
" + currentAlbum.albums[i].path + "
"); link.append(image); subalbums.push(link); - (function(theAlbum, theImage) { + (function(theContainer, theAlbum, theImage, theLink) { photoFloat.albumPhoto(theAlbum, function(album, photo) { theImage.css("background-image", "url(" + photoFloat.photoPath(album, photo, 150, true) + ")"); + }, function error() { + theContainer.albums.splice(currentAlbum.albums.indexOf(theAlbum), 1); + theLink.remove(); + subalbums.splice(subalbums.indexOf(theLink), 1); + }); - })(currentAlbum.albums[i], image); + })(currentAlbum, currentAlbum.albums[i], image, link); } subalbumsElement = $("#subalbums"); subalbumsElement.empty(); -- cgit v1.2.3-59-g8ed1b