From 8c25684fe1febf8d55bd076e282f1b69d21c9e7f Mon Sep 17 00:00:00 2001 From: Steven Evans Date: Thu, 5 Jul 2018 13:09:00 -0400 Subject: [PATCH] [refactor] Moved 'createPopup' to its own TS file. --- src/Bladeburner.js | 3 ++- src/CompanyManagement.js | 3 ++- src/Gang.js | 3 ++- src/Prestige.js | 3 ++- src/SaveObject.js | 4 ++-- utils/HelperFunctions.js | 20 -------------------- utils/uiHelpers/createPopup.ts | 32 ++++++++++++++++++++++++++++++++ 7 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 utils/uiHelpers/createPopup.ts diff --git a/src/Bladeburner.js b/src/Bladeburner.js index 29044e92b..5f2c07533 100644 --- a/src/Bladeburner.js +++ b/src/Bladeburner.js @@ -13,12 +13,13 @@ import {createProgressBarText} from "../utils/helpers/creat import {dialogBoxCreate} from "../utils/DialogBox"; import {addOffset, clearObject, removeChildrenFromElement, - createPopup, appendLineBreaks, + appendLineBreaks, removeElementById, removeElement} from "../utils/HelperFunctions"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; import numeral from "numeral/min/numeral.min"; import {createElement} from "../utils/uiHelpers/createElement"; +import {createPopup} from "../utils/uiHelpers/createPopup"; import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {formatNumber} from "../utils/StringHelperFunctions"; import {getRandomInt} from "../utils/helpers/getRandomInt"; diff --git a/src/CompanyManagement.js b/src/CompanyManagement.js index 46691768a..7be89ebba 100644 --- a/src/CompanyManagement.js +++ b/src/CompanyManagement.js @@ -9,12 +9,13 @@ import Decimal from "decimal.js"; import {dialogBoxCreate} from "../utils/DialogBox"; import {removeElementById, createAccordionElement, - removeChildrenFromElement, createPopup, + removeChildrenFromElement, clearSelector} from "../utils/HelperFunctions"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; import numeral from "numeral/min/numeral.min"; import {createElement} from "../utils/uiHelpers/createElement"; +import {createPopup} from "../utils/uiHelpers/createPopup"; import {formatNumber, generateRandomString} from "../utils/StringHelperFunctions"; import {getRandomInt} from "../utils/helpers/getRandomInt"; import {isString} from "../utils/helpers/isString"; diff --git a/src/Gang.js b/src/Gang.js index be791e8ec..a61441b50 100644 --- a/src/Gang.js +++ b/src/Gang.js @@ -7,9 +7,10 @@ import {dialogBoxCreate} from "../utils/DialogBox"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; import {removeChildrenFromElement, - createAccordionElement, createPopup, + createAccordionElement, removeElementById, removeElement} from "../utils/HelperFunctions"; import {createElement} from "../utils/uiHelpers/createElement"; +import {createPopup} from "../utils/uiHelpers/createPopup"; import numeral from "numeral/min/numeral.min"; import {formatNumber} from "../utils/StringHelperFunctions"; import {getRandomInt} from "../utils/helpers/getRandomInt"; diff --git a/src/Prestige.js b/src/Prestige.js index 198247bff..c4952a4e1 100644 --- a/src/Prestige.js +++ b/src/Prestige.js @@ -30,8 +30,9 @@ import {initStockMarket, initSymbolToStockMap, import {Terminal, postNetburnerText} from "./Terminal"; import Decimal from "decimal.js"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {createPopup, removeElementById} from "../utils/HelperFunctions"; +import {removeElementById} from "../utils/HelperFunctions"; import {createElement} from "../utils/uiHelpers/createElement"; +import {createPopup} from "../utils/uiHelpers/createPopup"; import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {yesNoBoxCreate, yesNoBoxGetYesButton, yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; diff --git a/src/SaveObject.js b/src/SaveObject.js index 54716d128..e77f30d2e 100644 --- a/src/SaveObject.js +++ b/src/SaveObject.js @@ -19,11 +19,11 @@ import {loadSpecialServerIps, SpecialServerIps} from "./SpecialServerIps"; import {loadStockMarket, StockMarket} from "./StockMarket"; import {dialogBoxCreate} from "../utils/DialogBox"; import {gameOptionsBoxClose} from "../utils/GameOptions"; -import {clearEventListeners, - createPopup, removeElementById} from "../utils/HelperFunctions"; +import {clearEventListeners, removeElementById} from "../utils/HelperFunctions"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; import {createElement} from "../utils/uiHelpers/createElement"; +import {createPopup} from "../utils/uiHelpers/createPopup"; import {formatNumber} from "../utils/StringHelperFunctions"; import Decimal from "decimal.js"; diff --git a/utils/HelperFunctions.js b/utils/HelperFunctions.js index fb2950776..b80b18271 100644 --- a/utils/HelperFunctions.js +++ b/utils/HelperFunctions.js @@ -89,25 +89,6 @@ function getElementById(elementId) { return el; } -function createPopup(id, elems) { - var container = createElement("div", { - class:"popup-box-container", - id:id, - display:"block" - }), - content = createElement("div", { - class:"popup-box-content", - id:id + "-content", - }); - - for (var i = 0; i < elems.length; ++i) { - content.appendChild(elems[i]); - } - container.appendChild(content); - document.getElementById("entire-game-container").appendChild(container); - return container; -} - //Creates both the header and panel element of an accordion and sets the click handler function createAccordionElement(params) { var li = document.createElement("li"), @@ -186,6 +167,5 @@ export {sizeOfObject, createAccordionElement, appendLineBreaks, removeChildrenFromElement, - createPopup, clearSelector, getElementById}; diff --git a/utils/uiHelpers/createPopup.ts b/utils/uiHelpers/createPopup.ts new file mode 100644 index 000000000..2e954f811 --- /dev/null +++ b/utils/uiHelpers/createPopup.ts @@ -0,0 +1,32 @@ +import { createElement } from "./createElement"; + +/** + * Creates the necessary DOM elements to present an in-game popup to the player. + * @param id The (hopefully) unique identifier for the popup container. + * @param elems The collection of HTML Elements to show within the popup. + */ +export function createPopup(id: string, elems: HTMLElement[]) { + const container: HTMLDivElement = createElement("div", { + class: "popup-box-container", + display: "block", + id, + }) as HTMLDivElement; + const content: HTMLElement = createElement("div", { + class: "popup-box-content", + id: `${id}-content`, + }); + + for (const elem of elems) { + content.appendChild(elem); + } + container.appendChild(content); + const gameContainer: HTMLElement | null = document.getElementById("entire-game-container"); + + if (gameContainer === null) { + throw new Error("Unable to find the game container. Something is *seriously* wrong..."); + } + + gameContainer.appendChild(container); + + return container; +}