Skip to content

Commit

Permalink
Simplify inserting ITAD prices
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Apr 25, 2024
1 parent a3afdb4 commit 5743f7a
Showing 1 changed file with 20 additions and 40 deletions.
60 changes: 20 additions & 40 deletions src/js/Content/Features/Store/Common/FITADPrices.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,34 @@ export default class FITADPrices extends Feature {
}

_insertPrices(type, id, data) {
let node;
let placement = "beforebegin";
let anchor;

if (type === "sub") {
node = document.querySelector(`input[name=subid][value="${id}"]`).closest(".game_area_purchase_game");
const inputEl = document.querySelector(`input[name=subid][value="${id}"]`);
anchor = inputEl.closest(".game_area_purchase_game_wrapper") // Subs on app pages
|| inputEl.closest(".game_area_purchase_game"); // Subs on sub pages
} else if (type === "bundle") {
node = document.querySelector(`.game_area_purchase_game_wrapper[data-ds-bundleid="${id}"]`);
if (node) {
placement = "afterbegin";

// Move any "Complete your Collection!" banner out of the way
const banner = node.querySelector(".ds_completetheset");
const newParent = node.querySelector(".game_area_purchase_game");
if (banner && newParent) {
newParent.appendChild(banner);
}
} else {
node = document.querySelector(`.game_area_purchase_game[data-ds-bundleid="${id}"]`);
}
anchor = document.querySelector(`.game_area_purchase_game_wrapper[data-ds-bundleid="${id}"]`) // Bundles on app pages
|| document.querySelector(`.game_area_purchase_game[data-ds-bundleid="${id}"]`); // Bundles on bundle pages
}

let target = node.parentElement;
let anchor = node;

if (placement === "afterbegin") {
target = node;
anchor = node.firstElementChild ?? null;
if (anchor) {
new PriceOverview({
target: anchor.parentElement,
anchor,
props: {data}
});
}

new PriceOverview({
target,
anchor,
props: {data}
});
}

_insertBundles(data) {
const target = document.querySelector("#game_area_purchase");

if (target) {
const anchor = target.nextElementSibling;

if (anchor) {
new BundleOverview({
target: anchor.parentElement,
anchor,
props: {data}
});
}
const anchor = document.querySelector("#game_area_purchase")?.nextElementSibling;
if (anchor) {
new BundleOverview({
target: anchor.parentElement,
anchor,
props: {data}
});
}
}

Expand Down

0 comments on commit 5743f7a

Please sign in to comment.