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 24, 2024
1 parent a3afdb4 commit 4bd43c6
Showing 1 changed file with 18 additions and 40 deletions.
58 changes: 18 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,32 @@ 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");
anchor = document.querySelector(`input[name=subid][value="${id}"]`).closest(".game_area_purchase_game_wrapper");
} 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 4bd43c6

Please sign in to comment.