|
|
@ -2,6 +2,10 @@
|
|
|
|
const container = document.getElementById("container");
|
|
|
|
const container = document.getElementById("container");
|
|
|
|
const editor = document.getElementById("editor");
|
|
|
|
const editor = document.getElementById("editor");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const input = document.getElementById("input");
|
|
|
|
|
|
|
|
const insert = document.getElementById("insert");
|
|
|
|
|
|
|
|
const cancel = document.getElementById("cancel");
|
|
|
|
|
|
|
|
|
|
|
|
// List of labels
|
|
|
|
// List of labels
|
|
|
|
let labels = [];
|
|
|
|
let labels = [];
|
|
|
|
let closing = false;
|
|
|
|
let closing = false;
|
|
|
@ -90,16 +94,24 @@ function drawLabel() {
|
|
|
|
let height = maxY - minY;
|
|
|
|
let height = maxY - minY;
|
|
|
|
|
|
|
|
|
|
|
|
if (width > minimumSizeX && height > minimumSizeY) {
|
|
|
|
if (width > minimumSizeX && height > minimumSizeY) {
|
|
|
|
|
|
|
|
new Promise(function (resolve, reject) {
|
|
|
|
|
|
|
|
insert.addEventListener("click", (e) => {
|
|
|
|
|
|
|
|
if (input.value) {
|
|
|
|
|
|
|
|
resolve(input.value);
|
|
|
|
|
|
|
|
} else reject("no input");
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}).then((textInput) => {
|
|
|
|
// Create a label and push it into the array of labels
|
|
|
|
// Create a label and push it into the array of labels
|
|
|
|
// The index is +1 because it is
|
|
|
|
let label = createLabel(minX, minY, width, height, labels.length, textInput);
|
|
|
|
let label = createLabel(minX, minY, width, height, labels.length);
|
|
|
|
|
|
|
|
labels.push(label);
|
|
|
|
labels.push(label);
|
|
|
|
container.appendChild(label);
|
|
|
|
container.appendChild(label);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create the label element
|
|
|
|
// Create the label element
|
|
|
|
function createLabel(x, y, width, height, index) {
|
|
|
|
function createLabel(x, y, width, height, index, input) {
|
|
|
|
let label = document.createElement("div");
|
|
|
|
let label = document.createElement("div");
|
|
|
|
label.classList.add("label");
|
|
|
|
label.classList.add("label");
|
|
|
|
label.style.left = `${x}px`;
|
|
|
|
label.style.left = `${x}px`;
|
|
|
@ -125,8 +137,13 @@ function createLabel(x, y, width, height, index) {
|
|
|
|
close.addEventListener("click", (e) => {
|
|
|
|
close.addEventListener("click", (e) => {
|
|
|
|
label.remove();
|
|
|
|
label.remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
label.appendChild(close);
|
|
|
|
label.appendChild(close);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add the text
|
|
|
|
|
|
|
|
let text = document.createElement("p");
|
|
|
|
|
|
|
|
text.classList.add("label--text");
|
|
|
|
|
|
|
|
text.innerHTML = input;
|
|
|
|
|
|
|
|
label.appendChild(text);
|
|
|
|
|
|
|
|
|
|
|
|
return label;
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|