mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 21:25:47 +01:00
[refactor] Moved 'clearEventListeners' to its own TS file
This commit is contained in:
parent
7edf5b5f1a
commit
8016321bfb
@ -11,8 +11,7 @@ import {Settings} from "./Settings";
|
||||
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {factionInvitationBoxCreate} from "../utils/FactionInvitationBox";
|
||||
import {clearEventListeners,
|
||||
removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {createElement} from "../utils/uiHelpers/createElement";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
|
@ -5,7 +5,7 @@ import {iTutorialSteps, iTutorialNextStep,
|
||||
iTutorialIsRunning, currITutorialStep} from "./InteractiveTutorial";
|
||||
import {Player} from "./Player";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
import {createElement} from "../utils/uiHelpers/createElement";
|
||||
|
@ -3,7 +3,7 @@ import {CONSTANTS} from "./Constants";
|
||||
import {Engine} from "./engine";
|
||||
import {Player} from "./Player";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
||||
import {infiltrationBoxCreate} from "../utils/InfiltrationBox";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions";
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Engine} from "./engine";
|
||||
import {Player} from "./Player";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
|
||||
/* InteractiveTutorial.js */
|
||||
let iTutorialSteps = {
|
||||
|
@ -15,7 +15,7 @@ import {Settings} from "./Settings";
|
||||
import {SpecialServerNames, SpecialServerIps} from "./SpecialServerIps";
|
||||
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {createRandomIp} from "../utils/IPAddress";
|
||||
import numeral from "numeral/min/numeral.min";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions";
|
||||
|
@ -3,7 +3,7 @@ import {Engine} from "./engine";
|
||||
import {displayFactionContent} from "./Faction";
|
||||
import {Player} from "./Player";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {addOffset} from "../utils/helpers/addOffset";
|
||||
import {formatNumber} from "../utils/StringHelperFunctions";
|
||||
import {getRandomInt} from "../utils/helpers/getRandomInt";
|
||||
|
@ -21,7 +21,7 @@ import {SourceFiles, applySourceFile} from "./SourceFile";
|
||||
|
||||
import Decimal from "decimal.js";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {createRandomIp} from "../utils/IPAddress";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
|
@ -6,9 +6,9 @@ import {SourceFiles, SourceFile,
|
||||
PlayerOwnedSourceFile} from "./SourceFile";
|
||||
import {Terminal} from "./Terminal";
|
||||
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners,
|
||||
removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {yesNoBoxCreate, yesNoBoxGetYesButton,
|
||||
yesNoBoxGetNoButton, yesNoBoxClose} from "../utils/YesNoBox";
|
||||
|
||||
|
@ -19,7 +19,7 @@ import {loadSpecialServerIps, SpecialServerIps} from "./SpecialServerIps";
|
||||
import {loadStockMarket, StockMarket} from "./StockMarket";
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {gameOptionsBoxClose} from "../utils/GameOptions";
|
||||
import {clearEventListeners} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
import {createElement} from "../utils/uiHelpers/createElement";
|
||||
|
@ -6,8 +6,7 @@ import {WorkerScript} from "./NetscriptWorker";
|
||||
import {Player} from "./Player";
|
||||
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {clearEventListeners,
|
||||
clearEventListenersEl} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {Reviver, Generic_toJSON,
|
||||
Generic_fromJSON} from "../utils/JSONReviver";
|
||||
import numeral from "numeral/min/numeral.min";
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {dialogBoxCreate} from "../utils/DialogBox";
|
||||
import {gameOptionsBoxOpen, gameOptionsBoxClose}from "../utils/GameOptions";
|
||||
import {clearEventListeners,
|
||||
removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {removeChildrenFromElement} from "../utils/HelperFunctions";
|
||||
import {clearEventListeners} from "../utils/uiHelpers/clearEventListeners";
|
||||
import {createElement} from "../utils/uiHelpers/createElement";
|
||||
import {exceptionAlert} from "../utils/helpers/exceptionAlert";
|
||||
import numeral from "numeral/min/numeral.min";
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {Faction, joinFaction} from "../src/Faction";
|
||||
import {Engine} from "../src/engine";
|
||||
import {Player} from "../src/Player";
|
||||
import {clearEventListeners} from "./HelperFunctions";
|
||||
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
||||
|
||||
/* Faction Invitation Pop-up box */
|
||||
function factionInvitationBoxClose() {
|
||||
|
@ -1,16 +1,6 @@
|
||||
//General helper functions
|
||||
import {isString} from "./helpers/isString";
|
||||
|
||||
//Given an element by its Id(usually an 'a' element), removes all event listeners
|
||||
//from that element by cloning and replacing. Then returns the new cloned element
|
||||
function clearEventListeners(elemId) {
|
||||
var elem = document.getElementById(elemId);
|
||||
if (elem == null) {console.log("ERR: Could not find element for: " + elemId); return null;}
|
||||
var newElem = elem.cloneNode(true);
|
||||
elem.parentNode.replaceChild(newElem, elem);
|
||||
return newElem;
|
||||
}
|
||||
|
||||
//Same as clearEventListeners except it takes a DOM element object rather than an ID
|
||||
function clearEventListenersEl(el) {
|
||||
if (el == null) {console.log("ERR: element passed into clearEventListenersEl is null"); return null;}
|
||||
@ -72,8 +62,7 @@ function clearSelector(selector) {
|
||||
}
|
||||
}
|
||||
|
||||
export {clearEventListeners,
|
||||
clearEventListenersEl,
|
||||
export {clearEventListenersEl,
|
||||
removeElement,
|
||||
createAccordionElement,
|
||||
removeChildrenFromElement,
|
||||
|
@ -3,7 +3,7 @@ import {CONSTANTS} from "../src/Constants";
|
||||
import {Factions, Faction} from "../src/Faction";
|
||||
import {Player} from "../src/Player";
|
||||
import {dialogBoxCreate} from "./DialogBox";
|
||||
import {clearEventListeners} from "./HelperFunctions";
|
||||
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
||||
import {formatNumber} from "./StringHelperFunctions";
|
||||
|
||||
//Keep track of last faction
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {killWorkerScript} from "../src/NetscriptWorker";
|
||||
import {clearEventListeners} from "./HelperFunctions";
|
||||
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
||||
import {arrayToString} from "./helpers/arrayToString";
|
||||
|
||||
$(document).keydown(function(event) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {clearEventListeners} from "./HelperFunctions";
|
||||
import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
||||
/* Generic Yes-No Pop-up box
|
||||
* Can be used to create pop-up boxes that require a yes/no response from player
|
||||
*/
|
||||
|
23
utils/uiHelpers/clearEventListeners.ts
Normal file
23
utils/uiHelpers/clearEventListeners.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { getElementById } from "./getElementById";
|
||||
|
||||
/**
|
||||
* Given an element by its ID, removes all event listeners from that element by cloning and
|
||||
* replacing. Then returns the new cloned element.
|
||||
* @param elemId The HTML ID to retrieve the element by.
|
||||
*/
|
||||
export function clearEventListeners(elemId: string) {
|
||||
try {
|
||||
const elem: HTMLElement = getElementById(elemId);
|
||||
const newElem: HTMLElement = elem.cloneNode(true) as HTMLElement;
|
||||
if (elem.parentNode !== null) {
|
||||
elem.parentNode.replaceChild(newElem, elem);
|
||||
}
|
||||
|
||||
return newElem;
|
||||
} catch (e) {
|
||||
// tslint:disable-next-line:no-console
|
||||
console.error(e);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user