export and scroll

master
km0 3 years ago
parent 7366fb8972
commit 26f76ae1b1

@ -28,18 +28,32 @@
<button id="load-labels">Load</button> <button id="load-labels">Load</button>
</nav> </nav>
<aside class="info" id="info-panel"> <aside class="info" id="info-panel">
<button class="close">X</button> <div class="contents">
<h1 class="title">Concrete 🎏 Label</h1> <button class="close">X</button>
<p> <h1 class="title">Concrete 🎏 Label</h1>
What do we need to know: - text labels-contents - order - position - size - who <p>
wrote it ? (random id? name? nothing at all?) - timestamp ? - What do we need to know: - text labels-contents - order - position - size - who
</p> wrote it ? (random id? name? nothing at all?) - timestamp ? -
</p>
</div>
</aside> </aside>
<aside class="transcription" id="transcription-panel"> <aside class="transcription" id="transcription-panel">
<button class="close">X</button> <div class="contents">
<h1 class="title">Label Transcription</h1> <button class="close">X</button>
<ol class="labels-contents"></ol> <h1 class="title">Label Transcription</h1>
<button id="export-text">Export</button> <button id="export-text">Export</button>
<div class="options">
<div>
<input type="checkbox" id="checkJSON" name="export-json" checked />
<label for="export-json">JSON</label>
</div>
<div>
<input type="checkbox" id="checkText" name="export-text" checked />
<label for="export-text">TXT</label>
</div>
</div>
<ol class="labels-contents"></ol>
</div>
</aside> </aside>
</body> </body>
</html> </html>

@ -262,7 +262,7 @@ function drawLabel() {
labels.push(label); labels.push(label);
imageTarget.appendChild(label); imageTarget.appendChild(label);
createLabelTranscription(label); createLabelTranscription(input.value);
}) })
.catch((e) => {}) .catch((e) => {})
.then(() => { .then(() => {
@ -306,9 +306,9 @@ function createLabel(x, y, width, height, index) {
const transcriptionPanel = document.getElementById("transcription-panel"); const transcriptionPanel = document.getElementById("transcription-panel");
const transcriptionList = transcriptionPanel.querySelector("ol"); const transcriptionList = transcriptionPanel.querySelector("ol");
function createLabelTranscription(label) { function createLabelTranscription(text) {
let transcription = document.createElement("li"); let transcription = document.createElement("li");
transcription.innerHTML = label.querySelector(".label--text").innerHTML; transcription.innerHTML = text;
transcriptionList.appendChild(transcription); transcriptionList.appendChild(transcription);
} }
@ -364,6 +364,8 @@ function loadLabels() {
labelElement.classList.add("loaded"); labelElement.classList.add("loaded");
imageTarget.appendChild(labelElement); imageTarget.appendChild(labelElement);
createLabelTranscription(label.text);
}); });
}); });
} }

@ -226,7 +226,6 @@ body {
top: 0; top: 0;
z-index: 50; z-index: 50;
padding: 24px;
margin: 0; margin: 0;
width: 25%; width: 25%;
@ -239,6 +238,13 @@ body {
transition: transform 0.4s ease-out; transition: transform 0.4s ease-out;
} }
.info .contents,
.transcription .contents {
padding: 24px;
height: 100vh;
overflow-y: auto;
}
.transcription.active, .transcription.active,
.info.active { .info.active {
transform: translateX(0); transform: translateX(0);
@ -254,6 +260,7 @@ body {
padding: 0; padding: 0;
list-style-position: inside; list-style-position: inside;
font-size: 1.125rem; font-size: 1.125rem;
margin-bottom: 100px;
} }
#show-info, #show-info,
@ -320,3 +327,7 @@ nav > * {
img.hidden { img.hidden {
display: none; display: none;
} }
.transcription .options {
margin-top: 24px;
}

@ -1,11 +1,30 @@
const exportText = document.getElementById("export-text"); const exportButton = document.getElementById("export-text");
const imageElement = document.getElementById("background-image");
exportText.addEventListener("click", (e) => { const checkJSON = document.getElementById("checkJSON");
const checkTEXT = document.getElementById("checkText");
let fileUrl = imageElement.src;
let fileName = fileUrl.slice(fileUrl.lastIndexOf("/") + 1, fileUrl.length);
let fileTitle = fileName.slice(0, fileName.indexOf(".")) || "export";
console.log(document.getElementById("transcription-panel"));
exportButton.addEventListener("click", (e) => {
if (checkJSON.value) exportJSON();
if (checkTEXT.value) exportText();
});
function exportText() {
let text = document.querySelector("ol").innerText; let text = document.querySelector("ol").innerText;
let title = fileName.slice(0, fileName.indexOf(".")) || "export"; let title = fileTitle + ".txt";
title += ".txt";
download(text, title, "text/plain;charset=utf-8"); download(text, title, "text/plain;charset=utf-8");
}); }
function exportJSON() {
let title = fileTitle + ".json";
download(JSON.stringify(labelsObj), title, "application/json");
}
// https://stackoverflow.com/questions/13405129/javascript-create-and-save-file // https://stackoverflow.com/questions/13405129/javascript-create-and-save-file
// Thank you Kanchu! // Thank you Kanchu!

Loading…
Cancel
Save