From 4dd2bc95491695d34177fd24cf9eb6033fbbb61f Mon Sep 17 00:00:00 2001 From: Matchu Date: Tue, 31 Jul 2012 11:14:32 -0400 Subject: [PATCH] fix some outfits list bugs I think I got the 0-width bug where the outfit never expands beyond 0px width, and there were also some issues with the fact that image subscriptions pointed to the current outfit object, even after that object had changed identity, so now we re-fetch from the cache by ID. --- public/javascripts/outfits/edit.js | 6 +++--- public/javascripts/wardrobe.js | 31 ++++++++++++++++-------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/public/javascripts/outfits/edit.js b/public/javascripts/outfits/edit.js index 4f3d03bc..60a899f4 100644 --- a/public/javascripts/outfits/edit.js +++ b/public/javascripts/outfits/edit.js @@ -550,7 +550,7 @@ View.Outfits = function (wardrobe) { wardrobe.outfits.bind('addOutfit', function (outfit, i) { var next_child = outfits_list_el.children().not('.hiding').eq(i), - outfit_el = $.tmpl('outfitTemplate', outfit); + outfit_el = $.tmpl('outfitTemplate', outfit.clone()); if(next_child.length) { outfit_el.insertBefore(next_child); } else { @@ -558,8 +558,8 @@ View.Outfits = function (wardrobe) { } updateActiveOutfit(); - var naturalWidth = outfit_el.width(); - log("Natural width is", naturalWidth); + var naturalWidth = outfit_el.css('width'); + log("Natural width is", naturalWidth, outfit_el.width()); outfit_el.width(0).animate({width: naturalWidth}, 'normal'); listSubscribeToImage(outfit); }); diff --git a/public/javascripts/wardrobe.js b/public/javascripts/wardrobe.js index fd868482..74991ae0 100644 --- a/public/javascripts/wardrobe.js +++ b/public/javascripts/wardrobe.js @@ -1119,21 +1119,24 @@ function Wardrobe() { var DELAY = 5000; var controller = this; - function checkSubscription(outfit) { - outfit.reload(function () { - if(outfitSubscriptionTotals[outfit.id] > 0) { - if(outfit.image_enqueued) { - log("Outfit image still enqueued; will try again soon", outfit); - setTimeout(function () { checkSubscription(outfit) }, DELAY); + function checkSubscription(outfit_id) { + Outfit.find(outfit_id, function (outfit) { + log("Checking image for", outfit); + outfit.reload(function () { + if(outfitSubscriptionTotals[outfit_id] > 0) { + if(outfit.image_enqueued) { + log("Outfit image still enqueued; will try again soon", outfit); + setTimeout(function () { checkSubscription(outfit_id) }, DELAY); + } else { + // Unsubscribe everyone from this outfit and fire ready events + delete outfitSubscriptionTotals[outfit_id]; + controller.events.trigger('imageReady', outfit); + } } else { - // Unsubscribe everyone from this outfit and fire ready events - delete outfitSubscriptionTotals[outfit.id]; - controller.events.trigger('imageReady', outfit); + log("Outfit was unsubscribed", outfit); + delete outfitSubscriptionTotals[outfit_id]; } - } else { - log("Outfit was unsubscribed", outfit); - delete outfitSubscriptionTotals[outfit.id]; - } + }); }); } @@ -1146,7 +1149,7 @@ function Wardrobe() { } else { // This is a new subscription! Let's start checking it. outfitSubscriptionTotals[outfit.id] = 1; - checkSubscription(outfit); + checkSubscription(outfit.id); } // Regardless, trigger the enqueued event for the new consumer's sake.