diff --git a/startpage.html b/startpage.html
index ee33c23..129f06b 100644
--- a/startpage.html
+++ b/startpage.html
@@ -427,10 +427,7 @@
let settingsMenuData = {};
// cookie holder for coordinates + size of containers
- let containerDataMap = new Map(); // key: element.id | values: {x:, y:, width:, height:, containerSettings}
-
- // cookie holder for container settings
- // let containerSettings = {};
+ let containerDataMap = new Map();
// default values for easy resetting
let defaultTextContainerSettings = {
@@ -473,8 +470,6 @@
shadowRgba: "rgba(255,255,255,.90)",
};
- // cookie holder for images
- // let imageMap = new Map(); // key: img.id | value: {id:, url:}
let wallpaper = "";
// local states
@@ -492,7 +487,9 @@
let audioLink = "";
let autoplayAudio = true;
- let numberOfContainers = 0;
+ let numberOfTextContainers = 0;
+ let numberOfImageContainers = 0;
+ let occupiedIndices = new Map();
let cursors = {};
@@ -506,6 +503,7 @@
imageUrl;
containerSettings;
sections;
+ clockIntervalId;
constructor(
id,
@@ -516,7 +514,7 @@
width,
imageUrl,
containerSettings,
- sections
+ sections,
) {
// check if id is already used
if (Object.keys(containerDataMap)
@@ -534,6 +532,8 @@
// if initializing saved bookmark container
if (x != undefined && y != undefined && imageUrl == undefined) {
+ numberOfTextContainers++;
+
this.name = name;
this.id = id;
this.x = x;
@@ -553,7 +553,8 @@
// if initializing saved image container
else if (x != undefined && y != undefined && imageUrl != undefined) {
- // todo: initialize saved image container
+ numberOfImageContainers++;
+
this.name = name;
this.id = id;
this.x = x;
@@ -569,9 +570,11 @@
// if intializing brand new bookmark container
else if (imageUrl == undefined) {
+ numberOfTextContainers++;
+
if (name == "") {
- this.name = "bookmark layer " + numberOfContainers;
- this.id = "bookmark-layer-" + numberOfContainers;
+ this.name = "bookmark layer " + numberOfTextContainers;
+ this.id = findLowestAvailableId("text");
}
else {
this.name = name;
@@ -591,15 +594,15 @@
// if initializing brand new image
else {
+ numberOfImageContainers++;
if (name == "") {
- this.name = "image " + numberOfContainers;
- this.id = "image-layer-" + numberOfContainers;
+ this.name = "image " + numberOfImageContainers;
+ this.id = findLowestAvailableId("image");
}
else {
this.name = name;
this.id = name.replace(" ", "-").toLowerCase();
}
- console.log(this.id);
this.imageUrl = imageUrl;
@@ -607,7 +610,6 @@
this.createImageContainerMenuListing();
}
-
this.applySettings();
this.addContainerEventListeners()
@@ -615,7 +617,6 @@
// and save
containerDataMap.set(this.id, this);
- numberOfContainers++;
}
/**
@@ -633,7 +634,7 @@
@@ -686,7 +687,7 @@
document.getElementById(this.id + "-clock").innerText =
timeFormat.format(new Date());
// set time on interval to continue to update
- setInterval(() => {
+ this.clockIntervalId = setInterval(() => {
document.getElementById(this.id + "-clock").innerText =
timeFormat.format(new Date());
}, 1000);
@@ -955,7 +956,7 @@
-
+
`
);
@@ -967,13 +968,13 @@
`
(you have no layers right now)
` @@ -1626,10 +1619,16 @@ let valueArray = []; containerDataMap.values().forEach((value) => { valueArray.push(value); - console.log(value); }); localStorage.setItem("containerMapValues", JSON.stringify(valueArray)); + // save the states of occupied ID indice + valueArray = []; + occupiedIndices.keys().forEach((value) => { + valueArray.push(value); + }); + localStorage.setItem("occupiedIndexMapValues", JSON.stringify(valueArray)); + // save wallpaper info localStorage.setItem("wallpaper", JSON.stringify(wallpaper)); localStorage.setItem( @@ -1826,8 +1825,38 @@ function deleteContainer(buttonPressed) { let containerId = buttonPressed.id.split("--")[0]; + let container = containerDataMap.get(containerId); + + if (container.imageUrl == undefined) { + numberOfTextContainers--; + clearInterval(container.clockIntervalId); + } + else { + numberOfImageContainers--; + } + containerDataMap.delete(containerId); - // remove element from DOM + occupiedIndices.delete(containerId); + + document.getElementById(containerId).remove(); + document.getElementById(containerId + "-container-listing").remove(); + } + + /** + * uses map to determine the lowest available ID index for given type, to + * prevent accidentally using the same ID number for unnamed containers twice + */ + function findLowestAvailableId(containerType) { + let id = ""; + for(let index = 0; index < 200; index ++) { + id = containerType + "-" + index; + if (!occupiedIndices.has(id)) { + occupiedIndices.set(id, true); + console.log(id); + return id; + } + } + return -1; } /** upon click release on movable elements, store position data for when saving to localStorage when disabling edit mode */ @@ -2151,10 +2180,8 @@ let link = container.sections[sectionIndex].links[linkIndex]; container.sections[sectionIndex].links.splice(linkIndex, 1); if (direction == "up" && linkIndex != 0) { - console.log("up: " + linkIndex); links.splice(linkIndex - 1, 0, link); } else if (direction == "down" && linkIndex != links.length) { - console.log("down: " + linkIndex); links.splice(linkIndex + 1, 0, link); } @@ -2182,7 +2209,6 @@ let numImages = 1; for (const key of keys) { if (key.slice(-1) > numImages) { - console.log(key); numImages = parseInt(key.slice(-1)); } } @@ -2268,8 +2294,6 @@ let containerId = colorChange.currentTarget.id.split("-settings")[0]; let container = containerDataMap.get(containerId); - console.log(container); - container.containerSettings.backgroundRgba = hexToRgba( document.getElementById(containerId + "-settings-bg-color").value, document.getElementById(containerId + "-settings-bg-alpha").value