Skip to content

Commit

Permalink
refactor: Improve button styling and simplify code structure
Browse files Browse the repository at this point in the history
- Updated button styles for better visual consistency.
- Added comments to provide better insight to the code.
- Removed unnecessary click event listener used for testing/debugging.
  • Loading branch information
iton0 committed Feb 22, 2024
1 parent fd1c8ef commit deb92cd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
22 changes: 5 additions & 17 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,18 @@
aria-controls="collapseExample"
>
</i>
<div
class="btn-group me-2"
role="group"
aria-label="Tree creating buttons"
>
<button type="button" class="btn btn-outline-primary" id="addFolder">
<div class="btn-group me-2" aria-label="Tree creating buttons">
<button type="button" class="btn btn-secondary" id="addFolder">
Folder
</button>
<button type="button" class="btn btn-outline-primary" id="addFile">
<button type="button" class="btn btn-secondary" id="addFile">
File
</button>
</div>
<div
class="btn-group me-2"
role="group"
aria-label="Tree updating buttons"
>
<div class="btn-group me-2" aria-label="Tree updating buttons">
<button type="button" class="btn btn-danger" id="clear">Clear</button>
</div>
<div
class="btn-group me-2"
role="group"
aria-label="Tree creating buttons"
>
<div class="btn-group me-2" aria-label="Tree creating buttons">
<button type="button" class="btn btn-success" id="forge">
Forge
</button>
Expand Down
13 changes: 5 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ document.addEventListener("DOMContentLoaded", () => {
const dragContainer = document.getElementById("drag-container");
const trashContainer = document.querySelector(".trash");

// Function to create an HTML element with class and attributes
function createElementWithClassAndAttribute(
elementType,
className,
Expand All @@ -15,7 +16,9 @@ document.addEventListener("DOMContentLoaded", () => {
return newElement;
}

// Function to create a container element
function createContainer(type) {
// Create child elements for the container
const newContainer = createElementWithClassAndAttribute("span", type, {
"data-nesting-level": 0,
draggable: true,
Expand Down Expand Up @@ -90,6 +93,7 @@ document.addEventListener("DOMContentLoaded", () => {
);
});

// If sibling with same name exists returns to default name
if (hasDuplicateSibling) {
alert(`A ${type} with the same name already exists`);
nameInput.name = `new_${type}`;
Expand All @@ -103,6 +107,7 @@ document.addEventListener("DOMContentLoaded", () => {
containerContent.appendChild(dragHandle);
containerContent.appendChild(nameInput);
newContainer.appendChild(containerContent);
// Files cannot have elements nested in them
if (type === "folder") {
newContainer.appendChild(nestItems);
}
Expand Down Expand Up @@ -181,14 +186,6 @@ document.addEventListener("DOMContentLoaded", () => {
}
}

// For testing/debugging
newContainer.addEventListener("click", (e) => {
e.stopPropagation();
e.preventDefault();
console.log("current target:", e.currentTarget);
console.log("nesting level :", e.currentTarget.dataset.nestingLevel);
});

// New container event listeners
newContainer.addEventListener("dragstart", (e) => {
e.stopPropagation();
Expand Down

0 comments on commit deb92cd

Please sign in to comment.