[refactor] Moved 'removeChildrenFromElements' to its own TS file

This commit is contained in:
Steven Evans 2018-07-08 00:00:57 -04:00
parent 95939a8818
commit 9e26ee7858
11 changed files with 36 additions and 29 deletions

@ -5,14 +5,14 @@ import {workerScripts,
import {Player} from "./Player";
import {getServer} from "./Server";
import {dialogBoxCreate} from "../utils/DialogBox";
import {createAccordionElement,
removeChildrenFromElement} from "../utils/HelperFunctions";
import {createAccordionElement} from "../utils/HelperFunctions";
import {arrayToString} from "../utils/helpers/arrayToString";
import {createElement} from "../utils/uiHelpers/createElement";
import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {logBoxCreate} from "../utils/LogBox";
import numeral from "numeral/min/numeral.min";
import {formatNumber} from "../utils/StringHelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {removeElement} from "../utils/uiHelpers/removeElement";
/* {

@ -12,13 +12,13 @@ import {Script, RunningScript} from "./Script";
import {Server} from "./Server";
import {SourceFiles} from "./SourceFile";
import {dialogBoxCreate} from "../utils/DialogBox";
import {createAccordionElement,
removeChildrenFromElement} from "../utils/HelperFunctions";
import {createAccordionElement} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import {clearObject} from "../utils/helpers/clearObject";
import {createElement} from "../utils/uiHelpers/createElement";
import {isString} from "../utils/helpers/isString";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
//Augmentations
function Augmentation(params) {

@ -11,7 +11,7 @@ import {KEY} from "./Terminal";
import {createProgressBarText} from "../utils/helpers/createProgressBarText";
import {dialogBoxCreate} from "../utils/DialogBox";
import {removeChildrenFromElement} from "../utils/HelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";

@ -1,6 +1,6 @@
import {Engine} from "./engine";
import {removeChildrenFromElement} from "../utils/HelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {createElement} from "../utils/uiHelpers/createElement";
import {exceptionAlert} from "../utils/helpers/exceptionAlert";
import {isString} from "../utils/helpers/isString";

@ -7,8 +7,7 @@ import {Player} from "./Player";
import Decimal from "decimal.js";
import {dialogBoxCreate} from "../utils/DialogBox";
import {removeChildrenFromElement,
clearSelector} from "../utils/HelperFunctions";
import {clearSelector} from "../utils/HelperFunctions";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import numeral from "numeral/min/numeral.min";
@ -17,6 +16,7 @@ import {createPopup} from "../utils/uiHelpers
import {formatNumber, generateRandomString} from "../utils/StringHelperFunctions";
import {getRandomInt} from "../utils/helpers/getRandomInt";
import {isString} from "../utils/helpers/isString";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {removeElementById} from "../utils/uiHelpers/removeElementById";
import {yesNoBoxCreate, yesNoTxtInpBoxCreate,
yesNoBoxGetYesButton, yesNoBoxGetNoButton,

@ -11,7 +11,7 @@ import {Settings} from "./Settings";
import {dialogBoxCreate} from "../utils/DialogBox";
import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox";
import {removeChildrenFromElement} from "../utils/HelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {createElement} from "../utils/uiHelpers/createElement";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";

@ -6,13 +6,13 @@ import {Player} from "./Player";
import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver";
import {removeChildrenFromElement,
createAccordionElement} from "../utils/HelperFunctions";
import {createAccordionElement} 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";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {removeElement} from "../utils/uiHelpers/removeElement";
import {removeElementById} from "../utils/uiHelpers/removeElementById";
import {yesNoBoxCreate, yesNoTxtInpBoxCreate,

@ -8,7 +8,7 @@ import {Terminal} from "./Terminal";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {dialogBoxCreate} from "../utils/DialogBox";
import {removeChildrenFromElement} from "../utils/HelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {yesNoBoxCreate, yesNoBoxGetYesButton,
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";

@ -1,6 +1,6 @@
import {dialogBoxCreate} from "../utils/DialogBox";
import {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions";
import {removeChildrenFromElement} from "../utils/HelperFunctions";
import {removeChildrenFromElement} from "../utils/uiHelpers/removeChildrenFromElement";
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
import {createElement} from "../utils/uiHelpers/createElement";
import {exceptionAlert} from "../utils/helpers/exceptionAlert";

@ -1,18 +1,3 @@
//General helper functions
import {isString} from "./helpers/isString";
function removeChildrenFromElement(el) {
if (isString(el)) {
el = document.getElementById(el);
}
if (el == null) {return;}
if (el instanceof Element) {
while(el.firstChild) {
el.removeChild(el.firstChild);
}
}
}
//Creates both the header and panel element of an accordion and sets the click handler
function createAccordionElement(params) {
var li = document.createElement("li"),
@ -49,5 +34,4 @@ function clearSelector(selector) {
}
export {createAccordionElement,
removeChildrenFromElement,
clearSelector};

@ -0,0 +1,23 @@
import { isString } from "../helpers/isString";
import { getElementById } from "./getElementById";
export function removeChildrenFromElement(el: string | null | Element) {
if (el === null) {
return;
}
try {
const elem: HTMLElement | Element = (isString(el) ? getElementById(el as string) : el as Element);
if (elem instanceof Element) {
while (elem.firstChild) {
elem.removeChild(elem.firstChild);
}
}
} catch (e) {
// tslint:disable-next-line:no-console
console.debug(e);
return;
}
}