Compare commits

..

No commits in common. '1f9d55829e05cfccd4d615ca0d6429d0e9ee1863' and '6e9c5c343a7c53a113a97fb079c9905106ba14cb' have entirely different histories.

@ -11,12 +11,6 @@
<body>
<div id="container">
<div id="editor"></div>
<form class="text-input">
<input id="input" type="text" />
<button id="insert" type="submit">Insert</button>
<button id="cancel">x</button>
</form>
</div>
</body>
</html>

@ -2,10 +2,6 @@
const container = document.getElementById("container");
const editor = document.getElementById("editor");
const input = document.getElementById("input");
const insert = document.getElementById("insert");
const cancel = document.getElementById("cancel");
// List of labels
let labels = [];
let closing = false;
@ -25,7 +21,6 @@ let showEditor = false;
// Store the coordinates and trigger the function
container.addEventListener("mousedown", (e) => {
// Avoid inserting a new label if the user is clicking on a close button)
if (e.target.tagName !== "BUTTON") {
startX = e.x;
startY = e.y;
@ -94,25 +89,16 @@ function drawLabel() {
let height = maxY - minY;
if (width > minimumSizeX && height > minimumSizeY) {
new Promise(function (resolve, reject) {
// TODO: show the modal for text input then if insert and value --> resolve, if cancel --> 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
let label = createLabel(minX, minY, width, height, labels.length, textInput);
labels.push(label);
container.appendChild(label);
});
// 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);
labels.push(label);
container.appendChild(label);
}
}
// Create the label element
function createLabel(x, y, width, height, index, input) {
function createLabel(x, y, width, height, index) {
let label = document.createElement("div");
label.classList.add("label");
label.style.left = `${x}px`;
@ -138,13 +124,8 @@ function createLabel(x, y, width, height, index, input) {
close.addEventListener("click", (e) => {
label.remove();
});
label.appendChild(close);
// Add the text
let text = document.createElement("p");
text.classList.add("label--text");
text.innerHTML = input;
label.appendChild(text);
label.appendChild(close);
return label;
}

@ -32,8 +32,6 @@ body {
position: absolute;
background-color: tomato;
box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.2);
overflow: hidden;
}
.label--number {
@ -61,26 +59,3 @@ body {
cursor: pointer;
}
.label--text {
margin: 1ch 0;
padding: 0 1ch;
overflow: hidden;
width: 100%;
height: 100%;
text-overflow: ellipsis;
}
.text-input {
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.text-input button {
background: none;
border: none;
cursor: pointer;
}

Loading…
Cancel
Save