2022-01-01 14:36:25 +01:00
|
|
|
"use strict";
|
|
|
|
(() => {
|
|
|
|
const inputList = [];
|
|
|
|
const pollOptionsAnchor = document.querySelector(".poll-options");
|
2022-01-11 21:00:44 +01:00
|
|
|
const extendMessageDiv = document.querySelector("#extend-message");
|
|
|
|
const inputCounter = document.querySelector("#options-counter");
|
|
|
|
const addOptionButton = document.querySelector("#add-options-button");
|
|
|
|
|
2022-01-01 14:36:25 +01:00
|
|
|
function createPollOptionInput() {
|
|
|
|
if (inputList.length >= parseInt(MAX_POLL_OPTIONS)) return;
|
|
|
|
const optionEl = document.createElement("div");
|
|
|
|
optionEl.classList.add("poll-option");
|
|
|
|
const input = document.createElement("input");
|
|
|
|
input.type = "text";
|
|
|
|
input.maxLength = MAX_CHARACTER_LENGTH;
|
|
|
|
input.name = "poll-option";
|
|
|
|
input.placeholder = "Enter your option here";
|
|
|
|
optionEl.appendChild(input);
|
|
|
|
|
2022-01-10 21:45:12 +01:00
|
|
|
input.addEventListener("keyup", () => {
|
2022-01-11 21:00:44 +01:00
|
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) {
|
|
|
|
pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
|
|
}
|
2022-01-01 14:36:25 +01:00
|
|
|
});
|
|
|
|
inputList.push(input);
|
2022-01-11 21:00:44 +01:00
|
|
|
inputCounter.textContent = inputList.length;
|
2022-01-01 14:36:25 +01:00
|
|
|
|
|
|
|
return optionEl;
|
|
|
|
}
|
|
|
|
|
|
|
|
pollOptionsAnchor.querySelectorAll(".poll-option input").forEach(el => {
|
2022-01-10 21:45:12 +01:00
|
|
|
el.addEventListener("keyup", () => {
|
2022-01-11 21:00:44 +01:00
|
|
|
if (inputList.every(el => el.value) && pollOptionsAnchor) {
|
|
|
|
pollOptionsAnchor.appendChild(createPollOptionInput());
|
|
|
|
}
|
2022-01-01 14:36:25 +01:00
|
|
|
});
|
|
|
|
inputList.push(el);
|
|
|
|
});
|
2022-01-11 21:00:44 +01:00
|
|
|
|
|
|
|
inputCounter.textContent = inputList.length;
|
|
|
|
|
|
|
|
if (extendMessageDiv) extendMessageDiv.style.display = "block";
|
|
|
|
if (addOptionButton) addOptionButton.remove();
|
|
|
|
|
2022-01-01 14:36:25 +01:00
|
|
|
return createPollOptionInput;
|
|
|
|
})();
|