From 41f42f22e63544e84fcb6b413a5c22b1c3954c8d Mon Sep 17 00:00:00 2001 From: agatemosu Date: Wed, 24 Jul 2024 15:47:07 +0200 Subject: [PATCH] Use `innerHTML` in `addRow` --- script.js | 98 +++++++++++++++---------------------------------------- 1 file changed, 26 insertions(+), 72 deletions(-) diff --git a/script.js b/script.js index ea62c1e..bd8a570 100644 --- a/script.js +++ b/script.js @@ -93,81 +93,35 @@ function createColorPicker(colorPicker, tierLabel, defaultColor) { function addRow(tierName = "New tier", defaultColor = clearColor) { const newRow = document.createElement("div"); newRow.className = "row"; - - // Labels and colors (i.e. left) - const tierLabelDiv = document.createElement("div"); - tierLabelDiv.className = "tier-label"; - tierLabelDiv.style.backgroundColor = defaultColor; - tierLabelDiv.contentEditable = "true"; - - const paragraph = document.createElement("p"); - paragraph.textContent = tierName; - paragraph.spellcheck = false; - - const tooltip = document.createElement("div"); - tooltip.className = "tooltip"; - tooltip.contentEditable = "false"; - - const colorPicker = document.createElement("div"); - colorPicker.className = "color-picker"; - - // Tiers (i.e. center) - const tierDiv = document.createElement("div"); - tierDiv.className = "tier sort"; - - // Options (i.e. right) - const optionsDiv = document.createElement("div"); - optionsDiv.className = "tier-options"; - optionsDiv.dataset.html2canvasIgnore = ""; - - const optionsContainer = document.createElement("div"); - optionsContainer.className = "options-container"; - - const deleteButton = document.createElement("div"); - deleteButton.className = "option delete"; - - const deleteImage = document.createElement("img"); - deleteImage.src = "assets/trash.svg"; - deleteImage.alt = "Delete"; - - const upButton = document.createElement("div"); - upButton.className = "option up"; - - const upImage = document.createElement("img"); - upImage.src = "assets/chevron-up.svg"; - upImage.alt = "Up"; - - const downButton = document.createElement("div"); - downButton.className = "option down"; - - const downImage = document.createElement("img"); - downImage.src = "assets/chevron-down.svg"; - downImage.alt = "Down"; - - // Add divs to the row / main container - tooltip.appendChild(colorPicker); - - tierLabelDiv.appendChild(paragraph); - tierLabelDiv.appendChild(tooltip); - - deleteButton.appendChild(deleteImage); - upButton.appendChild(upImage); - downButton.appendChild(downImage); - - optionsContainer.appendChild(deleteButton); - optionsContainer.appendChild(upButton); - optionsContainer.appendChild(downButton); - - optionsDiv.appendChild(optionsContainer); - - newRow.appendChild(tierLabelDiv); - newRow.appendChild(tierDiv); - newRow.appendChild(optionsDiv); + newRow.innerHTML = ` +
+

${tierName}

+
+
+
+
+
+
+
+
+ Delete +
+
+ Up +
+
+ Down +
+
+
+ `; mainContainer.appendChild(newRow); - addRowListeners(newRow, defaultColor); - initializeDragula(); }