diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..36c817ea --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +/app/assets/javascripts/lib diff --git a/app/assets/javascripts/ajax_auth.js b/app/assets/javascripts/ajax_auth.js index 27f81bbb..81fd79d5 100644 --- a/app/assets/javascripts/ajax_auth.js +++ b/app/assets/javascripts/ajax_auth.js @@ -1,20 +1,20 @@ (function () { - var CSRFProtection; - var token = $('meta[name="csrf-token"]').attr("content"); - if (token) { - CSRFProtection = function (xhr, settings) { - var sendToken = - typeof settings.useCSRFProtection === "undefined" || // default to true - settings.useCSRFProtection; - if (sendToken) { - xhr.setRequestHeader("X-CSRF-Token", token); - } - }; - } else { - CSRFProtection = $.noop; - } + var CSRFProtection; + var token = $('meta[name="csrf-token"]').attr("content"); + if (token) { + CSRFProtection = function (xhr, settings) { + var sendToken = + typeof settings.useCSRFProtection === "undefined" || // default to true + settings.useCSRFProtection; + if (sendToken) { + xhr.setRequestHeader("X-CSRF-Token", token); + } + }; + } else { + CSRFProtection = $.noop; + } - $.ajaxSetup({ - beforeSend: CSRFProtection, - }); + $.ajaxSetup({ + beforeSend: CSRFProtection, + }); })(); diff --git a/app/assets/javascripts/closet_hangers/index.js b/app/assets/javascripts/closet_hangers/index.js index c78019b0..429a5c43 100644 --- a/app/assets/javascripts/closet_hangers/index.js +++ b/app/assets/javascripts/closet_hangers/index.js @@ -1,842 +1,842 @@ (function () { - var hangersInitCallbacks = []; + var hangersInitCallbacks = []; - function onHangersInit(callback) { - hangersInitCallbacks[hangersInitCallbacks.length] = callback; - } + function onHangersInit(callback) { + hangersInitCallbacks[hangersInitCallbacks.length] = callback; + } - function hangersInit() { - for (var i = 0; i < hangersInitCallbacks.length; i++) { - try { - hangersInitCallbacks[i](); - } catch (error) { - console.error(error); - } - } - } + function hangersInit() { + for (var i = 0; i < hangersInitCallbacks.length; i++) { + try { + hangersInitCallbacks[i](); + } catch (error) { + console.error(error); + } + } + } - /* + /* Hanger groups */ - var hangerGroups = []; + var hangerGroups = []; - $(".closet-hangers-group").each(function () { - var el = $(this); - var lists = []; + $(".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(), - }; - } - }); + 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", - }; - }); + hangerGroups[hangerGroups.length] = { + label: el.find("h3").text(), + lists: lists, + owned: el.attr("data-owned") == "true", + }; + }); - $(".closet-hangers-group span.toggle").live("click", function () { - $(this).closest(".closet-hangers-group").toggleClass("hidden"); - }); + $(".closet-hangers-group span.toggle").live("click", function () { + $(this).closest(".closet-hangers-group").toggleClass("hidden"); + }); - var hangersElQuery = "#closet-hangers"; - var hangersEl = $(hangersElQuery); + var hangersElQuery = "#closet-hangers"; + var hangersEl = $(hangersElQuery); - /* + /* Compare with Your Items */ - $("#toggle-compare").click(function () { - hangersEl.toggleClass("comparing"); - }); + $("#toggle-compare").click(function () { + hangersEl.toggleClass("comparing"); + }); - // Read the item IDs of trade matches from the meta tags. - const ownedIds = - document - .querySelector("meta[name=trade-matches-owns]") - ?.getAttribute("value") - ?.split(",") ?? []; - const wantedIds = - document - .querySelector("meta[name=trade-matches-wants]") - ?.getAttribute("value") - ?.split(",") ?? []; + // Read the item IDs of trade matches from the meta tags. + const ownedIds = + document + .querySelector("meta[name=trade-matches-owns]") + ?.getAttribute("value") + ?.split(",") ?? []; + const wantedIds = + document + .querySelector("meta[name=trade-matches-wants]") + ?.getAttribute("value") + ?.split(",") ?? []; - // Apply the `user-owns` and `user-wants` classes to the relevant entries. - // This both provides immediate visual feedback, and sets up "Compare with - // Your Items" to toggle to just them! - // - // NOTE: The motivation here is caching: this allows us to share a cache of - // the closet list contents across all users, without `user-owns` or - // `user-wants` classes for one specific user getting cached and reused. - const hangerEls = document.querySelectorAll("#closet-hangers .object"); - for (const hangerEl of hangerEls) { - const itemId = hangerEl.getAttribute("data-item-id"); - if (ownedIds.includes(itemId)) { - hangerEl.classList.add("user-owns"); - } - if (wantedIds.includes(itemId)) { - hangerEl.classList.add("user-wants"); - } - } + // Apply the `user-owns` and `user-wants` classes to the relevant entries. + // This both provides immediate visual feedback, and sets up "Compare with + // Your Items" to toggle to just them! + // + // NOTE: The motivation here is caching: this allows us to share a cache of + // the closet list contents across all users, without `user-owns` or + // `user-wants` classes for one specific user getting cached and reused. + const hangerEls = document.querySelectorAll("#closet-hangers .object"); + for (const hangerEl of hangerEls) { + const itemId = hangerEl.getAttribute("data-item-id"); + if (ownedIds.includes(itemId)) { + hangerEl.classList.add("user-owns"); + } + if (wantedIds.includes(itemId)) { + hangerEl.classList.add("user-wants"); + } + } - /* + /* Hanger forms */ - var body = $(document.body).addClass("js"); - if (!body.hasClass("current-user")) return false; + 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 .closet-hangers-group").each(function () { - var groupEl = $(this); - var owned = groupEl.data("owned"); + // 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 .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"); + 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"); + 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 = $("