[refactor] Moved 'createPopup' to its own TS file.

This commit is contained in:
Steven Evans 2018-07-05 13:09:00 -04:00
parent 107f1de18d
commit 8c25684fe1
7 changed files with 42 additions and 26 deletions

@ -13,12 +13,13 @@ import {createProgressBarText} from "../utils/helpers/creat
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {addOffset, clearObject, import {addOffset, clearObject,
removeChildrenFromElement, removeChildrenFromElement,
createPopup, appendLineBreaks, appendLineBreaks,
removeElementById, removeElement} from "../utils/HelperFunctions"; removeElementById, removeElement} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min"; import numeral from "numeral/min/numeral.min";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt"; import {getRandomInt} from "../utils/helpers/getRandomInt";

@ -9,12 +9,13 @@ import Decimal from "decimal.js";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {removeElementById, import {removeElementById,
createAccordionElement, createAccordionElement,
removeChildrenFromElement, createPopup, removeChildrenFromElement,
clearSelector} from "../utils/HelperFunctions"; clearSelector} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min"; import numeral from "numeral/min/numeral.min";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {formatNumber, generateRandomString} from "../utils/StringHelperFunctions"; import {formatNumber, generateRandomString} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt"; import {getRandomInt} from "../utils/helpers/getRandomInt";
import {isString} from "../utils/helpers/isString"; import {isString} from "../utils/helpers/isString";

@ -7,9 +7,10 @@ import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {removeChildrenFromElement, import {removeChildrenFromElement,
createAccordionElement, createPopup, createAccordionElement,
removeElementById, removeElement} from "../utils/HelperFunctions"; removeElementById, removeElement} from "../utils/HelperFunctions";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import numeral from "numeral/min/numeral.min"; import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt"; import {getRandomInt} from "../utils/helpers/getRandomInt";

@ -30,8 +30,9 @@ import {initStockMarket, initSymbolToStockMap,
import {Terminal, postNetburnerText} from "./Terminal"; import {Terminal, postNetburnerText} from "./Terminal";
import Decimal from "decimal.js"; import Decimal from "decimal.js";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {createPopup, removeElementById} from "../utils/HelperFunctions"; import {removeElementById} from "../utils/HelperFunctions";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {yesNoBoxCreate, yesNoBoxGetYesButton, import {yesNoBoxCreate, yesNoBoxGetYesButton,
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox"; yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";

@ -19,11 +19,11 @@ import {loadSpecialServerIps, SpecialServerIps} from "./SpecialServerIps";
import {loadStockMarket, StockMarket} from "./StockMarket"; import {loadStockMarket, StockMarket} from "./StockMarket";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {gameOptionsBoxClose} from "../utils/GameOptions"; import {gameOptionsBoxClose} from "../utils/GameOptions";
import {clearEventListeners, import {clearEventListeners, removeElementById} from "../utils/HelperFunctions";
createPopup, removeElementById} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {createElement} from "../utils/uiHelpers/createElement"; import {createElement} from "../utils/uiHelpers/createElement";
import {createPopup} from "../utils/uiHelpers/createPopup";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import Decimal from "decimal.js"; import Decimal from "decimal.js";

@ -89,25 +89,6 @@ function getElementById(elementId) {
return el; 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 //Creates both the header and panel element of an accordion and sets the click handler
function createAccordionElement(params) { function createAccordionElement(params) {
var li = document.createElement("li"), var li = document.createElement("li"),
@ -186,6 +167,5 @@ export {sizeOfObject,
createAccordionElement, createAccordionElement,
appendLineBreaks, appendLineBreaks,
removeChildrenFromElement, removeChildrenFromElement,
createPopup,
clearSelector, clearSelector,
getElementById}; getElementById};

@ -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;
}