From c54e11f25a3b250f37d02ba1595e8676c0ff6280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Wed, 22 Jan 2025 19:31:42 +0100 Subject: [PATCH] =?UTF-8?q?Uhlazen=C3=AD=20JavaScriptu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- korektury/static/korektury/opraf.css | 1 + korektury/static/korektury/opraf.js | 62 +++++++------------ .../korekturovatko/__edit_komentar.html | 2 +- .../korektury/korekturovatko/__oprava.html | 9 +-- 4 files changed, 27 insertions(+), 47 deletions(-) diff --git a/korektury/static/korektury/opraf.css b/korektury/static/korektury/opraf.css index 523f7a96..515415ca 100644 --- a/korektury/static/korektury/opraf.css +++ b/korektury/static/korektury/opraf.css @@ -80,6 +80,7 @@ img{background:white;} padding: 3px; border: 2px solid rgb(var(--rgb)); border-radius: 10px; + position: absolute; &:hover { border-width:3px; diff --git a/korektury/static/korektury/opraf.js b/korektury/static/korektury/opraf.js index 6b59b22e..5677deff 100644 --- a/korektury/static/korektury/opraf.js +++ b/korektury/static/korektury/opraf.js @@ -1,56 +1,40 @@ +const W_SKIP = 10; +const H_SKIP = 5; +const POINTER_MIN_H = 30; + function place_comments_one_div(img_id, comments) { - var img = document.getElementById("img-"+img_id); - if( img == null ) { - return; - } - var par = img.parentNode; - var w = img.clientWidth; - var h = img.clientHeight; - var w_skip = 10; - var h_skip = 5; - var pointer_min_h = 30; + const img = document.getElementById("img-"+img_id); + if( img == null ) return; + const comments_sorted = comments.sort((a, b) => a.y - b.y); - var bott_max = 0; - var comments_sorted = comments.sort(function (a,b) { - return a.y - b.y; + const par = img.parentNode; + const w = img.clientWidth; - }); + let bott_max = 0; for (const oprava of comments_sorted) { const x = oprava.x; const y = oprava.y; - const el = oprava.htmlElement; - const elp = oprava.pointer; + const htmlElement = oprava.htmlElement; + const pointer = oprava.pointer; - if( el == null || elp == null ) { - continue; - } + par.appendChild(pointer); + par.appendChild(htmlElement); - par.appendChild(elp); - par.appendChild(el); + const delta_y = (y > bott_max) ? 0: bott_max - y + H_SKIP; - var delta_y = (y > bott_max) ? 0: bott_max - y + h_skip; + pointer.style.left = x; + pointer.style.top = y; + pointer.style.width = w - x + W_SKIP; + pointer.style.height = POINTER_MIN_H + delta_y; - elp.style.left = x; - elp.style.top = y ; - elp.style.width = w - x + w_skip; - elp.style.height = pointer_min_h + delta_y; + htmlElement.style.left = w + W_SKIP; + htmlElement.style.top = y + delta_y; - el.pointer = elp; - el.img_id = img_id; - el.x = x - el.y = y - el.style.position = 'absolute'; - el.style.left = w + w_skip; - el.style.top = y + delta_y; - - var bott = el.offsetTop + el.offsetHeight; - bott_max = ( bott_max > bott ) ? bott_max : bott; + bott_max = Math.max(bott_max, htmlElement.offsetTop + htmlElement.offsetHeight); } - if( par.offsetHeight < bott_max ) { - par.style.height = bott_max; - } + if (par.offsetHeight < bott_max) par.style.height = bott_max; } function place_comments() { diff --git a/korektury/templates/korektury/korekturovatko/__edit_komentar.html b/korektury/templates/korektury/korekturovatko/__edit_komentar.html index 9de1d519..8d5b1771 100644 --- a/korektury/templates/korektury/korekturovatko/__edit_komentar.html +++ b/korektury/templates/korektury/korekturovatko/__edit_komentar.html @@ -38,7 +38,7 @@ //fill up comment form and show him function show_form(img_id, dx, dy, id, text, action) { - var img = document.getElementById("img-" + img_id); + const img = document.getElementById("img-" + img_id); if (commform._div.style.display !== 'none' && commform._text.value !== "" && !confirm("Zavřít předchozí okénko přidávání korektury / editace komentáře?")) return 1; diff --git a/korektury/templates/korektury/korekturovatko/__oprava.html b/korektury/templates/korektury/korekturovatko/__oprava.html index 3da50e03..6f0eb8ed 100644 --- a/korektury/templates/korektury/korekturovatko/__oprava.html +++ b/korektury/templates/korektury/korekturovatko/__oprava.html @@ -91,7 +91,7 @@ this.htmlElement.addEventListener('mouseout', _ => this.pointer.dataset.highlight = 'false'); opravy[this.id] = this; - comments[this.img_id].push(this); + if (this.img_id in comments) comments[this.img_id].push(this); else alert("Někdo korekturoval stranu, která neexistuje. Dejte vědět webařům :)"); } update(oprava_data) { @@ -116,9 +116,7 @@ #toggle_visibility(){ this.zobrazit = !this.zobrazit; this.htmlElement.dataset.opravazobrazit = String(this.zobrazit); - for (let i=0;i { if (!response.ok) {alert('Něco se nepovedlo:' + response.statusText);}