(function () { var hangersInitCallbacks = []; function onHangersInit(callback) { hangersInitCallbacks[hangersInitCallbacks.length] = callback; } function hangersInit() { for (var i = 0; i < hangersInitCallbacks.length; i++) { hangersInitCallbacks[i](); } } /* Hanger groups */ var hangerGroups = []; $("div.closet-hangers-group").each(function () { var el = $(this); var lists = []; el.find("div.closet-list").each(function () { var el = $(this); var id = el.attr("data-id"); if (id) { lists[lists.length] = { id: parseInt(id, 10), label: el.find("h4").text(), }; } }); hangerGroups[hangerGroups.length] = { label: el.find("h3").text(), lists: lists, owned: el.attr("data-owned") == "true", }; }); $("div.closet-hangers-group span.toggle").live("click", function () { $(this).closest(".closet-hangers-group").toggleClass("hidden"); }); var hangersElQuery = "#closet-hangers"; var hangersEl = $(hangersElQuery); /* Compare with Your Items */ $("#toggle-compare").click(function () { hangersEl.toggleClass("comparing"); }); /* Hanger forms */ var body = $(document.body).addClass("js"); if (!body.hasClass("current-user")) return false; // When we get hangers HTML, add the controls. We do this in JS rather than // in the HTML for caching, since otherwise the requests can take forever. // If there were another way to add hangers, then we'd have to worry about // that, but, right now, the only way to create a new hanger from this page // is through the autocompleter, which reinitializes anyway. Geez, this thing // is begging for a rewrite, but today we're here for performance. $("#closet-hanger-update-tmpl").template("updateFormTmpl"); $("#closet-hanger-destroy-tmpl").template("destroyFormTmpl"); onHangersInit(function () { // Super-lame hack to get the user ID from where it already is :/ var currentUserId = itemsSearchForm.data("current-user-id"); $("#closet-hangers div.closet-hangers-group").each(function () { var groupEl = $(this); var owned = groupEl.data("owned"); groupEl.find("div.closet-list").each(function () { var listEl = $(this); var listId = listEl.data("id"); listEl.find("div.object").each(function () { var hangerEl = $(this); var hangerId = hangerEl.data("id"); var quantityEl = hangerEl.find("div.quantity"); var quantity = hangerEl.data("quantity"); // Ooh, this part is weird. We only want the name to be linked, so // lift everything else out. var checkboxId = "hanger-selected-" + hangerId; var label = $("