Convert to tabs and switch to using Vue
This commit is contained in:
parent
e461a0a677
commit
0001dca6e7
5 changed files with 55 additions and 127 deletions
|
|
@ -11,9 +11,7 @@
|
|||
<link rel="stylesheet" href="style.css">
|
||||
|
||||
<!-- JAVASCRIPT -->
|
||||
<script src="./js/delete_choice.js"></script>
|
||||
<script src="./js/add_choice.js"></script>
|
||||
<script src="./js/choosing.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<template id="choice-template">
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
const add_choice = () => {
|
||||
let index = document.getElementsByClassName("choice").length;
|
||||
|
||||
|
||||
let choice_div = document.getElementById("choice-template");
|
||||
let clone = choice_div.content.cloneNode(true);
|
||||
clone.children[0].children[0].id = `text-in-${index}`;
|
||||
clone.children[0].children[1].id = `weight-in-${index}`;
|
||||
|
||||
// Add to document without resetting the other ones
|
||||
document.getElementById("choices").appendChild(clone);
|
||||
};
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
const construct_choices = () => {
|
||||
let choices = document.getElementById("choices").children;
|
||||
let start_of_next_range = 1;
|
||||
let options = [];
|
||||
|
||||
// Construct the array for choosing
|
||||
for (choice of choices) {
|
||||
let name = choice.children[0].value;
|
||||
let weight = parseInt(choice.children[1].value);
|
||||
|
||||
if (Number.isNaN(weight)) {
|
||||
break;
|
||||
};
|
||||
|
||||
options.push({
|
||||
"name": name,
|
||||
"min": start_of_next_range,
|
||||
"max": start_of_next_range + weight - 1
|
||||
});
|
||||
start_of_next_range += weight;
|
||||
};
|
||||
|
||||
return {
|
||||
"choices": options,
|
||||
"max_value": start_of_next_range - 1
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
const choose_option = () => {
|
||||
let {choices, max_value} = construct_choices();
|
||||
|
||||
// No options, error
|
||||
if (choices.length === 0 && max_value === 0) {
|
||||
document.getElementById("result").innerText = "\nERROR: No Choices to pick from";
|
||||
return;
|
||||
}
|
||||
|
||||
// Only one option exists, no need to waste time with randomness
|
||||
else if (choices.length === 1) {
|
||||
document.getElementById("result").innerText = choices[0].name
|
||||
};
|
||||
|
||||
|
||||
let chosen_value = Math.round(Math.random() * max_value);
|
||||
|
||||
|
||||
// Find the choice which the randomly chosen number fits within
|
||||
for (choice of choices) {
|
||||
if (choice.min <= chosen_value <= choice.max) {
|
||||
document.getElementById("result").innerText = choice.name;
|
||||
return;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
const delete_choice = (node) => {
|
||||
node.parentElement.parentElement.removeChild(node.parentElement)
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue