reorder still in wip, better logic but stuck on keys

This commit is contained in:
2025-07-14 23:26:18 -04:00
parent 89d5a08609
commit f9bd33cc0d
+87 -20
View File
@@ -300,17 +300,18 @@
create new layer create new layer
</button> </button>
</div> </div>
<p>or</p>
<div> <div>
<h2 class="menuHeader">add image to page</h2> <h2 class="menuHeader">add image to page</h2>
<input <input
id="newImageContainerNameInput" id="newImageContainerNameInput"
placeholder="optional: image name" placeholder="optional: image name"
style="width: 50%;"
type="text" type="text"
/> />
<input <input
id="newImageContainerUrlInput" id="newImageContainerUrlInput"
placeholder="required: direct url to image" placeholder="required: direct url to image"
style="width: 50%;"
type="text" type="text"
/> />
<button id="newImageContainerCreateButton" onclick="createNewImageContainer(this)"> <button id="newImageContainerCreateButton" onclick="createNewImageContainer(this)">
@@ -530,6 +531,7 @@
let loadingFromSave = (x != undefined) && (y != undefined); let loadingFromSave = (x != undefined) && (y != undefined);
let isImage = (imageUrl != undefined); let isImage = (imageUrl != undefined);
// if constructing image container // if constructing image container
if (isImage) { if (isImage) {
numberOfImageContainers++; numberOfImageContainers++;
@@ -548,7 +550,9 @@
if (name == "") this.name = "image " + numberOfImageContainers; if (name == "") this.name = "image " + numberOfImageContainers;
else this.name = name; else this.name = name;
this.id = findLowestAvailableId(); this.id = findLowestAvailableId();
zIndexMap.set(this.id, numberOfImageContainers + numberOfTextContainers);
this.imageUrl = imageUrl; this.imageUrl = imageUrl;
// deep copy default settings // deep copy default settings
this.containerSettings = JSON.parse(JSON.stringify(defaultImageContainerSettings)); this.containerSettings = JSON.parse(JSON.stringify(defaultImageContainerSettings));
@@ -575,10 +579,12 @@
if (name == "") this.name = "bookmark layer " + numberOfTextContainers; if (name == "") this.name = "bookmark layer " + numberOfTextContainers;
else this.name = name; else this.name = name;
this.id = findLowestAvailableId(); this.id = findLowestAvailableId();
this.sections = {}; zIndexMap.set(this.id, numberOfTextContainers + numberOfImageContainers);
// deep copy default settings // deep copy default settings
this.containerSettings = JSON.parse(JSON.stringify(defaultTextContainerSettings)); this.containerSettings = JSON.parse(JSON.stringify(defaultTextContainerSettings));
this.sections = {};
} }
this.initializeTextContainer(); this.initializeTextContainer();
@@ -595,7 +601,6 @@
// and save // and save
containerDataMap.set(this.id, this); containerDataMap.set(this.id, this);
zIndexMap.set(this.id, numberOfImageContainers + numberOfTextContainers);
} }
@@ -782,12 +787,13 @@
} }
createTextContainerMenuListing() { createTextContainerMenuListing() {
let layerIndex = zIndexMap.get(this.id);
document.getElementById("containers").insertAdjacentHTML( document.getElementById("containers").insertAdjacentHTML(
"beforeend", "beforeend",
` `
<div class="containerListing" id=${this.id + "-container-listing"}> <div class="containerListing" id=${this.id + "-container-listing"}>
<p class="expandableMenuToggle active" onclick="toggleExpandableMenu(this)">- ${this.name}</p> <p class="expandableMenuToggle active" onclick="toggleExpandableMenu(this)">[${layerIndex}]: ${this.name}</p>
<div class="expandableMenu" id=${this.id + "-settings-menu"} style="display: block;"> <div class="expandableMenu" id=${this.id + "-settings-menu"} style="display: block;">
<p class="expandableMenuToggle" onclick="toggleExpandableMenu(this)">+ ${this.name}: bookmarks</p> <p class="expandableMenuToggle" onclick="toggleExpandableMenu(this)">+ ${this.name}: bookmarks</p>
@@ -932,6 +938,10 @@
</div> </div>
</div> </div>
<button id=${this.id + "--move-up-button"} onclick="reorderContainer(this, 'top')">summon to top</button>
<button id=${this.id + "--move-up-button"} onclick="reorderContainer(this, 'up')">move up</button>
<button id=${this.id + "--move-down-button"} onclick="reorderContainer(this, 'down')">move down</button>
<button id=${this.id + "--move-up-button"} onclick="reorderContainer(this, 'bottom')">banish to bottom</button>
<button id=${this.id + "--delete-button"} onclick="deleteContainer(this)">delete</button> <button id=${this.id + "--delete-button"} onclick="deleteContainer(this)">delete</button>
</div> </div>
` `
@@ -944,7 +954,7 @@
` `
<div class="containerListing" id=${this.id + "-container-listing"}> <div class="containerListing" id=${this.id + "-container-listing"}>
<p class="expandableMenuToggle active" onclick="toggleExpandableMenu(this)">- ${this.name}</p> <p class="expandableMenuToggle active" onclick="toggleExpandableMenu(this)">[${zIndexMap.get(this.id)}]: ${this.name}</p>
<div class="expandableMenu" id=${this.id + "-settings-menu"} style="display: block;"> <div class="expandableMenu" id=${this.id + "-settings-menu"} style="display: block;">
<p class="expandableMenuToggle" onclick="toggleExpandableMenu(this)">+ ${this.name}: color + shape options</p> <p class="expandableMenuToggle" onclick="toggleExpandableMenu(this)">+ ${this.name}: color + shape options</p>
@@ -973,7 +983,17 @@
<input id=${this.id + "-settings-shadow-alpha"} /> <input id=${this.id + "-settings-shadow-alpha"} />
</div> </div>
<button id=${this.id + "--delete-button"} onclick="deleteContainer(this)">delete</button> <div style="display: flex; flex-direction: row; justify-content: space-between;">
<div>
<button id=${this.id + "--move-top-button"} onclick="reorderContainer(this, 'top')">summon to top</button>
<button id=${this.id + "--move-up-button"} onclick="reorderContainer(this, 'up')">move up</button>
<button id=${this.id + "--move-down-button"} onclick="reorderContainer(this, 'down')">move down</button>
<button id=${this.id + "--move-bottom-button"} onclick="reorderContainer(this, 'bottom')">banish to bottom</button>
</div>
<div>
<button id=${this.id + "--delete-button"} onclick="deleteContainer(this)">delete</button>
</div>
</div>
</div> </div>
</div> </div>
` `
@@ -1444,12 +1464,15 @@
.addEventListener("input", changeWallpaper, false); .addEventListener("input", changeWallpaper, false);
document document
/** load container data /** load container data */
let occupiedIndexMapValues = let zIndexMapData = JSON.parse(localStorage.getItem("zIndexMapData")) || [];
JSON.parse(localStorage.getItem("occupiedIndexMapValues")) || []; let zIndexMapKeys = Object.keys(zIndexMapData) || [];
for (let i = 0; i < occupiedIndexMapValues.length; i++) { for (let i = 0; i < zIndexMapKeys.length; i++) {
occupiedIndices.set(occupiedIndexMapValues[i], true); zIndexMap.set(
}*/ zIndexMapKeys[i],
zIndexMapData[zIndexMapKeys[i]]
);
}
let containerMapValues = let containerMapValues =
JSON.parse(localStorage.getItem("containerMapValues")) || []; JSON.parse(localStorage.getItem("containerMapValues")) || [];
@@ -1599,13 +1622,12 @@
}); });
localStorage.setItem("containerMapValues", JSON.stringify(valueArray)); localStorage.setItem("containerMapValues", JSON.stringify(valueArray));
/* save the states of occupied ID indice /* save z-indexes */
valueArray = []; let temp = {};
occupiedIndices.keys().forEach((value) => { zIndexMap.keys().forEach((key) => {
valueArray.push(value); temp[key] = zIndexMap.get(key);
}); });
localStorage.setItem("occupiedIndexMapValues", JSON.stringify(valueArray)); localStorage.setItem("zIndexMapData", JSON.stringify(temp));
*/
// save wallpaper info // save wallpaper info
localStorage.setItem("wallpaper", JSON.stringify(wallpaper)); localStorage.setItem("wallpaper", JSON.stringify(wallpaper));
@@ -1801,6 +1823,51 @@
); );
} }
function reorderContainer(buttonPressed, direction) {
let containerId = buttonPressed.id.split("--")[0];
let container = document.getElementById(containerId);
let currentIndex = zindexmap.get(containerId);
let tempContainer;
let start;
// TODO if only using mapKeys for length, just sum the numberOf..Containers
let mapKeys = [];
zIndexMap.keys().forEach(key => {
mapKeys.push(key);
});
// move indicated container
if (direction == "up") {
start = currentIndex + 1;
// TODO can't access with index dummy. gotta be id. figure out how to get the id of the necessary indices...
tempContainer = zIndexMap.get(// currentIndex + 1);
}
else if (direction == "down") {
start = currentIndex - 1;
tempContainer = zIndexMap.get(// currentIndex - 1);
}
else if (direction == "top") {
start = mapKeys.length;
tempContainer = zIndexMap.get(// mapKeys.length);
}
else if (direction == "bottom") {
start = 1;
tempContainer = zIndexMap.get(// 1);
}
for (let i = start; i < mapKeys.length; i++) {
zIndexMap.set(containerDataMap(i).id, i);
document.getElementById(containerDataMap(i)).style.zIndex = i;
}
zindexMap.set(tempContainer, currentIndex);
// consider a redraw function for menu listings
}
function deleteContainer(buttonPressed) { function deleteContainer(buttonPressed) {
let containerId = buttonPressed.id.split("--")[0]; let containerId = buttonPressed.id.split("--")[0];
let container = containerDataMap.get(containerId); let container = containerDataMap.get(containerId);