mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 12:45:45 +01:00
Fixed re-balanced Corporation issues. Converted several popups in the Corporation mechanic to support Enter/Esc hotkeys
This commit is contained in:
parent
5dcb1a02b2
commit
a9bd883395
1142
dist/engine.bundle.js
vendored
1142
dist/engine.bundle.js
vendored
File diff suppressed because it is too large
Load Diff
1107
dist/vendor.bundle.js
vendored
1107
dist/vendor.bundle.js
vendored
File diff suppressed because one or more lines are too long
@ -521,6 +521,10 @@ export let CONSTANTS: IMap<any> = {
|
|||||||
Agriculture industry
|
Agriculture industry
|
||||||
|
|
||||||
* Stock Market, Travel, and Corporation main menu links are now properly styled
|
* Stock Market, Travel, and Corporation main menu links are now properly styled
|
||||||
|
* Many pop-up/dialog boxes now support the 'Enter' and 'Esc' hotkeys. If you
|
||||||
|
find a pop-up/dialog box that doesnt support this, let me know specifically which one
|
||||||
|
('Enter' for the default option, 'Esc' for cancelling and closing the pop-up box)
|
||||||
|
* Added "brace_style = preserve_inline" configuration to Script Editor Beautifier
|
||||||
`
|
`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import { Reviver,
|
|||||||
import { appendLineBreaks } from "../../utils/uiHelpers/appendLineBreaks";
|
import { appendLineBreaks } from "../../utils/uiHelpers/appendLineBreaks";
|
||||||
import { createElement } from "../../utils/uiHelpers/createElement";
|
import { createElement } from "../../utils/uiHelpers/createElement";
|
||||||
import { createPopup } from "../../utils/uiHelpers/createPopup";
|
import { createPopup } from "../../utils/uiHelpers/createPopup";
|
||||||
|
import { createPopupCloseButton } from "../../utils/uiHelpers/createPopupCloseButton";
|
||||||
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";
|
||||||
@ -1286,13 +1287,8 @@ Industry.prototype.createResearchBox = function() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
// Close button
|
// Close button
|
||||||
boxContent.appendChild(createElement("button", {
|
boxContent.appendChild(createPopupCloseButton(researchTreeBox, {
|
||||||
class: "std-button",
|
class: "std-button",
|
||||||
clickListener: () => {
|
|
||||||
if (researchTreeBox != null) {
|
|
||||||
removeElement(researchTreeBox);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
display: "block",
|
display: "block",
|
||||||
innerText: "Close",
|
innerText: "Close",
|
||||||
}));
|
}));
|
||||||
@ -2098,14 +2094,17 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
});
|
});
|
||||||
var confirmBtn;
|
var confirmBtn;
|
||||||
var input = createElement("input", {
|
var input = createElement("input", {
|
||||||
type:"number", value:mat.buy ? mat.buy : null, placeholder: "Purchase amount",
|
margin: "5px",
|
||||||
|
placeholder: "Purchase amount",
|
||||||
|
type: "number",
|
||||||
|
value: mat.buy ? mat.buy : null,
|
||||||
onkeyup:(e)=>{
|
onkeyup:(e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.keyCode === 13) {confirmBtn.click();}
|
if (e.keyCode === 13) {confirmBtn.click();}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
confirmBtn = createElement("a", {
|
confirmBtn = createElement("button", {
|
||||||
innerText:"Confirm", class:"a-link-button",
|
innerText:"Confirm", class:"std-button",
|
||||||
clickListener:()=>{
|
clickListener:()=>{
|
||||||
if (isNaN(input.value)) {
|
if (isNaN(input.value)) {
|
||||||
dialogBoxCreate("Invalid amount");
|
dialogBoxCreate("Invalid amount");
|
||||||
@ -2118,8 +2117,8 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var clearButton = createElement("a", {
|
var clearButton = createElement("button", {
|
||||||
innerText:"Clear Purchase", class:"a-link-button",
|
innerText:"Clear Purchase", class:"std-button",
|
||||||
clickListener:()=>{
|
clickListener:()=>{
|
||||||
mat.buy = 0;
|
mat.buy = 0;
|
||||||
removeElementById(purchasePopupId);
|
removeElementById(purchasePopupId);
|
||||||
@ -2127,12 +2126,11 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var cancelBtn = createElement("a", {
|
const cancelBtn = createPopupCloseButton(purchasePopupId, {
|
||||||
innerText:"Cancel", class:"a-link-button",
|
class: "std-button",
|
||||||
clickListener:()=>{
|
innerText: "Cancel",
|
||||||
removeElementById(purchasePopupId);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
createPopup(purchasePopupId, [txt, input, confirmBtn, clearButton, cancelBtn]);
|
createPopup(purchasePopupId, [txt, input, confirmBtn, clearButton, cancelBtn]);
|
||||||
input.focus();
|
input.focus();
|
||||||
}
|
}
|
||||||
@ -2307,7 +2305,7 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
var br = createElement("br", {});
|
var br = createElement("br", {});
|
||||||
var confirmBtn;
|
var confirmBtn;
|
||||||
var inputQty = createElement("input", {
|
var inputQty = createElement("input", {
|
||||||
type:"text", marginTop:"4px",
|
type: "text", marginTop: "4px",
|
||||||
value: mat.sllman[1] ? mat.sllman[1] : null, placeholder: "Sell amount",
|
value: mat.sllman[1] ? mat.sllman[1] : null, placeholder: "Sell amount",
|
||||||
onkeyup:(e)=>{
|
onkeyup:(e)=>{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -2315,16 +2313,17 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
var inputPx = createElement("input", {
|
var inputPx = createElement("input", {
|
||||||
type:"text", marginTop:"4px",
|
type: "text", marginTop: "4px",
|
||||||
value: mat.sCost ? mat.sCost : null, placeholder: "Sell price",
|
value: mat.sCost ? mat.sCost : null, placeholder: "Sell price",
|
||||||
onkeyup:(e)=>{
|
onkeyup: (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.keyCode === 13) {confirmBtn.click();}
|
if (e.keyCode === 13) {confirmBtn.click();}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
confirmBtn = createElement("a", {
|
confirmBtn = createElement("button", {
|
||||||
innerText:"Confirm", class:"a-link-button", margin:"6px",
|
class: "std-button",
|
||||||
clickListener:()=>{
|
innerText: "Confirm",
|
||||||
|
clickListener: () => {
|
||||||
//Parse price
|
//Parse price
|
||||||
var cost = inputPx.value.replace(/\s+/g, '');
|
var cost = inputPx.value.replace(/\s+/g, '');
|
||||||
cost = cost.replace(/[^-()\d/*+.MP]/g, ''); //Sanitize cost
|
cost = cost.replace(/[^-()\d/*+.MP]/g, ''); //Sanitize cost
|
||||||
@ -2387,12 +2386,11 @@ Warehouse.prototype.createMaterialUI = function(mat, matName, parentRefs) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var cancelBtn = createElement("a", {
|
const cancelBtn = createPopupCloseButton(sellPopupid, {
|
||||||
innerText:"Cancel", class:"a-link-button", margin: "6px",
|
class: "std-button",
|
||||||
clickListener:()=>{
|
innerText: "Cancel",
|
||||||
removeElementById(sellPopupid);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
createPopup(sellPopupid, [txt, br, inputQty, inputPx, confirmBtn, cancelBtn]);
|
createPopup(sellPopupid, [txt, br, inputQty, inputPx, confirmBtn, cancelBtn]);
|
||||||
inputQty.focus();
|
inputQty.focus();
|
||||||
}
|
}
|
||||||
@ -2779,9 +2777,14 @@ Corporation.prototype.storeCycles = function(numCycles=1) {
|
|||||||
Corporation.prototype.process = function() {
|
Corporation.prototype.process = function() {
|
||||||
var corp = this;
|
var corp = this;
|
||||||
if (this.storedCycles >= CyclesPerIndustryStateCycle) {
|
if (this.storedCycles >= CyclesPerIndustryStateCycle) {
|
||||||
var state = this.getState(), marketCycles=1;
|
const state = this.getState();
|
||||||
|
const marketCycles = 1;
|
||||||
this.storedCycles -= (marketCycles * CyclesPerIndustryStateCycle);
|
this.storedCycles -= (marketCycles * CyclesPerIndustryStateCycle);
|
||||||
|
|
||||||
|
this.divisions.forEach(function(ind) {
|
||||||
|
ind.process(marketCycles, state, corp);
|
||||||
|
});
|
||||||
|
|
||||||
//At the start of a new cycle, calculate profits from previous cycle
|
//At the start of a new cycle, calculate profits from previous cycle
|
||||||
if (state === "START") {
|
if (state === "START") {
|
||||||
this.revenue = new Decimal(0);
|
this.revenue = new Decimal(0);
|
||||||
@ -2820,11 +2823,6 @@ Corporation.prototype.process = function() {
|
|||||||
this.updateSharePrice();
|
this.updateSharePrice();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.divisions.forEach(function(ind) {
|
|
||||||
ind.process(marketCycles, state, corp);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
this.state.nextState();
|
this.state.nextState();
|
||||||
|
|
||||||
if (routing.isOn(Page.Corporation)) {this.updateUIContent();}
|
if (routing.isOn(Page.Corporation)) {this.updateUIContent();}
|
||||||
@ -3208,14 +3206,8 @@ Corporation.prototype.updateUIHeaderTabs = function() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var noBtn = createElement("span", {
|
|
||||||
class:"popup-box-button",
|
const noBtn = createPopupCloseButton(container, {innerText: "Cancel"});
|
||||||
innerText:"Cancel",
|
|
||||||
clickListener: function() {
|
|
||||||
removeElementById("cmpy-mgmt-expand-industry-popup");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Make an object to keep track of what industries you're already in
|
//Make an object to keep track of what industries you're already in
|
||||||
var ownedIndustries = {}
|
var ownedIndustries = {}
|
||||||
@ -3261,6 +3253,7 @@ Corporation.prototype.updateUIHeaderTabs = function() {
|
|||||||
container.appendChild(content);
|
container.appendChild(content);
|
||||||
document.getElementById("entire-game-container").appendChild(container);
|
document.getElementById("entire-game-container").appendChild(container);
|
||||||
container.style.display = "flex";
|
container.style.display = "flex";
|
||||||
|
nameInput.focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
@ -3804,9 +3797,6 @@ Corporation.prototype.updateCorporationOverviewContent = function() {
|
|||||||
console.log("WARNING: Could not find overview text elemtn in updateCorporationOverviewContent()");
|
console.log("WARNING: Could not find overview text elemtn in updateCorporationOverviewContent()");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var totalFunds = this.funds,
|
|
||||||
totalRevenue = new Decimal(0),
|
|
||||||
totalExpenses = new Decimal(0);
|
|
||||||
|
|
||||||
// Formatted text for profit
|
// Formatted text for profit
|
||||||
var profit = this.revenue.minus(this.expenses).toNumber(),
|
var profit = this.revenue.minus(this.expenses).toNumber(),
|
||||||
@ -3827,7 +3817,7 @@ Corporation.prototype.updateCorporationOverviewContent = function() {
|
|||||||
`Your earnings (Post-Tax): ${numeralWrapper.format(playerEarnings * (this.dividendTaxPercentage / 100), "$0.000a")} / s<br>`;
|
`Your earnings (Post-Tax): ${numeralWrapper.format(playerEarnings * (this.dividendTaxPercentage / 100), "$0.000a")} / s<br>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
var txt = "Total Funds: " + numeralWrapper.format(totalFunds.toNumber(), '$0.000a') + "<br>" +
|
var txt = "Total Funds: " + numeralWrapper.format(this.funds.toNumber(), '$0.000a') + "<br>" +
|
||||||
"Total Revenue: " + numeralWrapper.format(this.revenue.toNumber(), "$0.000a") + " / s<br>" +
|
"Total Revenue: " + numeralWrapper.format(this.revenue.toNumber(), "$0.000a") + " / s<br>" +
|
||||||
"Total Expenses: " + numeralWrapper.format(this.expenses.toNumber(), "$0.000a") + "/ s<br>" +
|
"Total Expenses: " + numeralWrapper.format(this.expenses.toNumber(), "$0.000a") + "/ s<br>" +
|
||||||
"Total Profits: " + profitStr + " / s<br>" +
|
"Total Profits: " + profitStr + " / s<br>" +
|
||||||
@ -3918,13 +3908,11 @@ Corporation.prototype.displayDivisionContent = function(division, city) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var cancelBtn = createElement("a", {
|
const cancelBtn = createPopupCloseButton(popupId, {
|
||||||
innerText:"Cancel", class:"a-link-button", display:"inline-block", margin:"3px",
|
class: "std-button",
|
||||||
clickListener:()=>{
|
innerText: "Cancel",
|
||||||
removeElementById(popupId);
|
});
|
||||||
return false;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
createPopup(popupId, [text, citySelector, confirmBtn, cancelBtn]);
|
createPopup(popupId, [text, citySelector, confirmBtn, cancelBtn]);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ export const CorporationUpgrades: IMap<any[]> = {
|
|||||||
"to consumers through their dreams. Each level of this upgrade provides a passive " +
|
"to consumers through their dreams. Each level of this upgrade provides a passive " +
|
||||||
"increase in awareness of all of your companies (divisions) by 0.004 / market cycle," +
|
"increase in awareness of all of your companies (divisions) by 0.004 / market cycle," +
|
||||||
"and in popularity by 0.001 / market cycle. A market cycle is approximately " +
|
"and in popularity by 0.001 / market cycle. A market cycle is approximately " +
|
||||||
"20 seconds."],
|
"15 seconds."],
|
||||||
|
|
||||||
//Makes advertising more effective
|
//Makes advertising more effective
|
||||||
"3": [3, 4e9, 1.12, 0.005,
|
"3": [3, 4e9, 1.12, 0.005,
|
||||||
|
@ -272,7 +272,10 @@ $(document).keydown(function(e) {
|
|||||||
function beautifyScript() {
|
function beautifyScript() {
|
||||||
var editor = ace.edit('javascript-editor');
|
var editor = ace.edit('javascript-editor');
|
||||||
var code = editor.getValue();
|
var code = editor.getValue();
|
||||||
code = beautify(code, { indent_size: 4 })
|
code = beautify(code, {
|
||||||
|
indent_size: 4,
|
||||||
|
brace_style: "preserve-inline",
|
||||||
|
});
|
||||||
editor.setValue(code);
|
editor.setValue(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2015,6 +2015,7 @@ let Terminal = {
|
|||||||
yesBtn.innerHTML = "Travel to BitNode Nexus";
|
yesBtn.innerHTML = "Travel to BitNode Nexus";
|
||||||
noBtn.innerHTML = "Cancel";
|
noBtn.innerHTML = "Cancel";
|
||||||
yesBtn.addEventListener("click", function() {
|
yesBtn.addEventListener("click", function() {
|
||||||
|
console.log("yesBtn event listener");
|
||||||
hackWorldDaemon(Player.bitNodeN, true);
|
hackWorldDaemon(Player.bitNodeN, true);
|
||||||
return yesNoBoxClose();
|
return yesNoBoxClose();
|
||||||
});
|
});
|
||||||
|
@ -11,10 +11,21 @@ import {clearEventListeners} from "./uiHelpers/clearEventListeners";
|
|||||||
export let yesNoBoxOpen: boolean = false;
|
export let yesNoBoxOpen: boolean = false;
|
||||||
|
|
||||||
const yesNoBoxContainer: HTMLElement | null = document.getElementById("yes-no-box-container");
|
const yesNoBoxContainer: HTMLElement | null = document.getElementById("yes-no-box-container");
|
||||||
const yesNoBoxYesButton: HTMLElement | null = document.getElementById("yes-no-box-yes");
|
|
||||||
const yesNoBoxNoButton: HTMLElement | null = document.getElementById("yes-no-box-no");
|
|
||||||
const yesNoBoxTextElement: HTMLElement | null = document.getElementById("yes-no-box-text");
|
const yesNoBoxTextElement: HTMLElement | null = document.getElementById("yes-no-box-text");
|
||||||
|
|
||||||
|
export function yesNoBoxHotkeyHandler(e: KeyboardEvent) {
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
yesNoBoxClose();
|
||||||
|
} else if (e.keyCode === 13) {
|
||||||
|
const yesBtn: HTMLElement | null = document.getElementById("yes-no-box-yes");
|
||||||
|
if (yesBtn) {
|
||||||
|
yesBtn.click();
|
||||||
|
} else {
|
||||||
|
console.error(`Could not find YesNoBox Yes button DOM element`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function yesNoBoxClose(): boolean {
|
export function yesNoBoxClose(): boolean {
|
||||||
if (yesNoBoxContainer) {
|
if (yesNoBoxContainer) {
|
||||||
yesNoBoxContainer.style.display = "none";
|
yesNoBoxContainer.style.display = "none";
|
||||||
@ -29,18 +40,6 @@ export function yesNoBoxClose(): boolean {
|
|||||||
return false; //So that 'return yesNoBoxClose()' is return false in event listeners
|
return false; //So that 'return yesNoBoxClose()' is return false in event listeners
|
||||||
}
|
}
|
||||||
|
|
||||||
export function yesNoBoxHotkeyHandler(e: KeyboardEvent) {
|
|
||||||
if (e.keyCode === 27) {
|
|
||||||
yesNoBoxClose();
|
|
||||||
} else if (e.keyCode === 13) {
|
|
||||||
if (yesNoBoxNoButton) {
|
|
||||||
yesNoBoxNoButton.click();
|
|
||||||
} else {
|
|
||||||
console.error(`Could not find YesNoBox No button DOM element`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export function yesNoBoxGetYesButton() {
|
export function yesNoBoxGetYesButton() {
|
||||||
return clearEventListeners("yes-no-box-yes");
|
return clearEventListeners("yes-no-box-yes");
|
||||||
}
|
}
|
||||||
@ -55,6 +54,8 @@ export function yesNoBoxCreate(txt: string) {
|
|||||||
|
|
||||||
if (yesNoBoxTextElement) {
|
if (yesNoBoxTextElement) {
|
||||||
yesNoBoxTextElement.innerHTML = txt;
|
yesNoBoxTextElement.innerHTML = txt;
|
||||||
|
} else {
|
||||||
|
console.error(`Text element not found for YesNoBox`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (yesNoBoxContainer) {
|
if (yesNoBoxContainer) {
|
||||||
@ -73,11 +74,22 @@ export function yesNoBoxCreate(txt: string) {
|
|||||||
* Yes-No pop up box with text input field
|
* Yes-No pop up box with text input field
|
||||||
*/
|
*/
|
||||||
const yesNoTextInputBoxContainer: HTMLElement | null = document.getElementById("yes-no-text-input-box-container");
|
const yesNoTextInputBoxContainer: HTMLElement | null = document.getElementById("yes-no-text-input-box-container");
|
||||||
const yesNoTextInputBoxYesButton: HTMLElement | null = document.getElementById("yes-no-text-input-box-yes");
|
|
||||||
const yesNoTextInputBoxNoButton: HTMLElement | null = document.getElementById("yes-no-text-input-box-no");
|
|
||||||
const yesNoTextInputBoxInput: HTMLInputElement | null = document.getElementById("yes-no-text-input-box-input") as HTMLInputElement;
|
const yesNoTextInputBoxInput: HTMLInputElement | null = document.getElementById("yes-no-text-input-box-input") as HTMLInputElement;
|
||||||
const yesNoTextInputBoxTextElement: HTMLElement | null = document.getElementById("yes-no-text-input-box-text");
|
const yesNoTextInputBoxTextElement: HTMLElement | null = document.getElementById("yes-no-text-input-box-text");
|
||||||
|
|
||||||
|
export function yesNoTxtInpBoxHotkeyHandler(e: KeyboardEvent) {
|
||||||
|
if (e.keyCode === 27) {
|
||||||
|
yesNoTxtInpBoxClose();
|
||||||
|
} else if (e.keyCode === 13) {
|
||||||
|
const yesBtn: HTMLElement | null = document.getElementById("yes-no-text-input-box-yes");
|
||||||
|
if (yesBtn) {
|
||||||
|
yesBtn.click();
|
||||||
|
} else {
|
||||||
|
console.error(`Could not find YesNoTxtInputBox Yes button DOM element`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function yesNoTxtInpBoxClose(): boolean {
|
export function yesNoTxtInpBoxClose(): boolean {
|
||||||
if (yesNoTextInputBoxContainer != null) {
|
if (yesNoTextInputBoxContainer != null) {
|
||||||
yesNoTextInputBoxContainer.style.display = "none";
|
yesNoTextInputBoxContainer.style.display = "none";
|
||||||
@ -87,6 +99,10 @@ export function yesNoTxtInpBoxClose(): boolean {
|
|||||||
}
|
}
|
||||||
yesNoBoxOpen = false;
|
yesNoBoxOpen = false;
|
||||||
yesNoTextInputBoxInput!.value = "";
|
yesNoTextInputBoxInput!.value = "";
|
||||||
|
|
||||||
|
// Remove hotkey handler
|
||||||
|
document.removeEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,5 +137,8 @@ export function yesNoTxtInpBoxCreate(txt: string) {
|
|||||||
console.error("Container not found for YesNoTextInputBox");
|
console.error("Container not found for YesNoTextInputBox");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add event listener for Esc and Enter hotkeys
|
||||||
|
document.addEventListener("keydown", yesNoTxtInpBoxHotkeyHandler);
|
||||||
|
|
||||||
yesNoTextInputBoxInput!.focus();
|
yesNoTextInputBoxInput!.focus();
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
/* Creates a Close/Cancel button that is used for removing popups */
|
/* Creates a Close/Cancel button that is used for removing popups */
|
||||||
|
|
||||||
import { createElement } from "./createElement";
|
import { createElement } from "./createElement";
|
||||||
import { getElementById } from "./getElementById";
|
|
||||||
import { removeElement } from "./removeElement";
|
import { removeElement } from "./removeElement";
|
||||||
|
|
||||||
interface ICreatePopupCloseButtonOptions {
|
interface ICreatePopupCloseButtonOptions {
|
||||||
|
class?: string;
|
||||||
|
display?: string;
|
||||||
innerText?: string;
|
innerText?: string;
|
||||||
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createPopupCloseButton(popup: Element | string, options: ICreatePopupCloseButtonOptions) {
|
export function createPopupCloseButton(popup: Element | string, options: ICreatePopupCloseButtonOptions) {
|
||||||
let button: HTMLButtonElement;
|
let button: HTMLButtonElement;
|
||||||
|
|
||||||
|
|
||||||
// TODO event listener works with escape. Add and remove event listener
|
// TODO event listener works with escape. Add and remove event listener
|
||||||
// from document
|
// from document
|
||||||
function closePopupWithEscFn(e: any): void {
|
function closePopupWithEscFn(e: any): void {
|
||||||
@ -21,21 +22,25 @@ export function createPopupCloseButton(popup: Element | string, options: ICreate
|
|||||||
}
|
}
|
||||||
|
|
||||||
button = createElement("button", {
|
button = createElement("button", {
|
||||||
class: "std-button",
|
class: options.class ? options.class : "popup-box-button",
|
||||||
|
display: options.display ? options.display : "inline-block",
|
||||||
innerText: options.innerText == null ? "Cancel" : options.innerText,
|
innerText: options.innerText == null ? "Cancel" : options.innerText,
|
||||||
clickListener: () => {
|
clickListener: () => {
|
||||||
if (popup instanceof Element) {
|
if (popup instanceof Element) {
|
||||||
removeElement(popup);
|
removeElement(popup);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
const popupEl = getElementById(popup);
|
const popupEl = document.getElementById(popup);
|
||||||
removeElement(popupEl);
|
if (popupEl instanceof Element) {
|
||||||
|
removeElement(popupEl);
|
||||||
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error(`createPopupCloseButton() threw: ${e}`);
|
console.error(`createPopupCloseButton() threw: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.removeEventListener("keydown", closePopupWithEscFn);
|
document.removeEventListener("keydown", closePopupWithEscFn);
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
}) as HTMLButtonElement;
|
}) as HTMLButtonElement;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user