Browse Source

(feat: tabs) Add tab divs, refactor card setup

Signature of resultsCard() changes to include a targetContainer, which
takes a JQuery HTMLElement (ie one returned by a selector)
tags/v0.3.5
bertieb 3 years ago
parent
commit
cd540e9401
1 changed files with 21 additions and 8 deletions
  1. +21
    -8
      src/ts/frontend.ts

+ 21
- 8
src/ts/frontend.ts View File

@@ -353,13 +353,15 @@ function describeRolls(resultsProperties: ResultProperties): string {
/** /**
* Set up results card that contains one set of RollStats results * Set up results card that contains one set of RollStats results
*/ */
function resultsCard(resultsProperties: ResultProperties): JQuery<HTMLElement>{
function resultsCard(resultsProperties: ResultProperties,
targetContainer: JQuery<HTMLElement>)
: JQuery<HTMLElement> {
// <div id="results"> is the general results div to append results to // <div id="results"> is the general results div to append results to
// TODO: include class shortname in id (?) // TODO: include class shortname in id (?)
let cardId = `results-${resultsProperties.itemId()}`; let cardId = `results-${resultsProperties.itemId()}`;


$("#results").append(`<div class="card my-4" id="${cardId}">`);
let resultsCard = $("#results").find(`#${cardId}`);
targetContainer.append(`<div class="card my-4" id="${cardId}">`);
let resultsCard = targetContainer.find(`#${cardId}`);
resultsCard.append(`<div class="card-body">`); resultsCard.append(`<div class="card-body">`);
let resultsCardBody: JQuery<HTMLElement> = $(`#${cardId}`).find("div.card-body"); let resultsCardBody: JQuery<HTMLElement> = $(`#${cardId}`).find("div.card-body");
return resultsCardBody; return resultsCardBody;
@@ -411,7 +413,10 @@ function resultsBody(resultProperties: ResultProperties): string {
* Put the results together - card, head, body → fill charts and tables * Put the results together - card, head, body → fill charts and tables
*/ */
function addResults(resultProperties: ResultProperties): void { function addResults(resultProperties: ResultProperties): void {
let resultsCardBody = resultsCard(resultProperties);
console.log(`#tabContent-${resultProperties.diceVariant}`);
let targetContainer: JQuery<HTMLElement> = $(`#tabContent-${resultProperties.diceVariant}`);

let resultsCardBody = resultsCard(resultProperties, targetContainer);


resultsCardBody.append(resultsHeader(resultProperties)); resultsCardBody.append(resultsHeader(resultProperties));


@@ -524,14 +529,22 @@ async function getResults():Promise<string>{
let variantControlAdded = false; let variantControlAdded = false;
// Start of cutoff, add navigation anchor for variant // Start of cutoff, add navigation anchor for variant
$("#results").append(variantNavAnchor(cutoff)); $("#results").append(variantNavAnchor(cutoff));

// Add navigation for this variant (<li>) // Add navigation for this variant (<li>)
// NB: first one gets 'active', otherwise it doesn't // NB: first one gets 'active', otherwise it doesn't
let buttonClass = (cutoff === cutoffStart) ? "nav-link active" : "nav-link"; let buttonClass = (cutoff === cutoffStart) ? "nav-link active" : "nav-link";
$(`#${navId}`).append(`<li class="nav-item" role="presentation"> $(`#${navId}`).append(`<li class="nav-item" role="presentation">
<button class="${buttonClass}" id="tab-nav-c${cutoff}"
data-bs-toggle="tab" data-bs-target="#tab-content-c${cutoff}"
type="button" role="tab">Cutoff ${cutoff}</button>
</li>`);
<button class="${buttonClass}" id="tab-nav-c${cutoff}"
data-bs-toggle="tab" data-bs-target="#tabContent-c${cutoff}"
type="button" role="tab">Cutoff ${cutoff}</button>
</li>`);

// Add tab container for this variant (<div>) -- id: #tabContent-c${cutoff}
// NB: first one also gets "show active" classes similar to above
let tabClass = (cutoff === cutoffStart) ? "tab-pane fade show active" : "tab-pane fade";
$(`#${tabContentId}`).append(`<div class="${tabClass}"
id="tabContent-c${cutoff}" role="tabpanel">`);

// Roll the dice for this variant // Roll the dice for this variant
for (let i = 1; i < maxDice; i++) { for (let i = 1; i < maxDice; i++) {
let rsSetup = { numDice: i, diceOptions: { successCutOff: cutoff } }; let rsSetup = { numDice: i, diceOptions: { successCutOff: cutoff } };


Loading…
Cancel
Save