From 26f76ae1b1df96d377837801f17c471374387fce Mon Sep 17 00:00:00 2001 From: "kam (from the studio)" Date: Wed, 24 Nov 2021 18:32:32 +0100 Subject: [PATCH] export and scroll --- index.html | 34 ++++++++++++++++++++++++---------- labels.js | 8 +++++--- style.css | 13 ++++++++++++- text-export.js | 29 ++++++++++++++++++++++++----- 4 files changed, 65 insertions(+), 19 deletions(-) diff --git a/index.html b/index.html index d5548d2..fb342e7 100644 --- a/index.html +++ b/index.html @@ -28,18 +28,32 @@ diff --git a/labels.js b/labels.js index 9eaeac3..9ace71f 100644 --- a/labels.js +++ b/labels.js @@ -262,7 +262,7 @@ function drawLabel() { labels.push(label); imageTarget.appendChild(label); - createLabelTranscription(label); + createLabelTranscription(input.value); }) .catch((e) => {}) .then(() => { @@ -306,9 +306,9 @@ function createLabel(x, y, width, height, index) { const transcriptionPanel = document.getElementById("transcription-panel"); const transcriptionList = transcriptionPanel.querySelector("ol"); -function createLabelTranscription(label) { +function createLabelTranscription(text) { let transcription = document.createElement("li"); - transcription.innerHTML = label.querySelector(".label--text").innerHTML; + transcription.innerHTML = text; transcriptionList.appendChild(transcription); } @@ -364,6 +364,8 @@ function loadLabels() { labelElement.classList.add("loaded"); imageTarget.appendChild(labelElement); + + createLabelTranscription(label.text); }); }); } diff --git a/style.css b/style.css index ea52269..57bb4ab 100644 --- a/style.css +++ b/style.css @@ -226,7 +226,6 @@ body { top: 0; z-index: 50; - padding: 24px; margin: 0; width: 25%; @@ -239,6 +238,13 @@ body { transition: transform 0.4s ease-out; } +.info .contents, +.transcription .contents { + padding: 24px; + height: 100vh; + overflow-y: auto; +} + .transcription.active, .info.active { transform: translateX(0); @@ -254,6 +260,7 @@ body { padding: 0; list-style-position: inside; font-size: 1.125rem; + margin-bottom: 100px; } #show-info, @@ -320,3 +327,7 @@ nav > * { img.hidden { display: none; } + +.transcription .options { + margin-top: 24px; +} diff --git a/text-export.js b/text-export.js index 4ae4f0f..97fb067 100644 --- a/text-export.js +++ b/text-export.js @@ -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 title = fileName.slice(0, fileName.indexOf(".")) || "export"; - title += ".txt"; + let title = fileTitle + ".txt"; 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 // Thank you Kanchu!