From 99ef84a6c7f65a62051619044d4779a5a2115b64 Mon Sep 17 00:00:00 2001 From: frederik Date: Sun, 17 Aug 2025 12:35:48 +0200 Subject: [PATCH] shorten displayed text if needed --- scripts/overview.php | 15 ++++++++++++++- scripts/todays_detections.php | 19 ++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/scripts/overview.php b/scripts/overview.php index b5fd20f..d5ccca9 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -300,9 +300,22 @@ if (get_included_files()[0] === __FILE__) { } + function shorten(u) { + if (u.length < 48) { + return u; + } + uend = u.slice(u.length - 16); + ustart = u.substr(0, 32); + var shorter = ustart + '...' + uend; + return shorter; + } + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { + let text_display = shorten(text); + let authorlink_display = shorten(authorlink); + let licenseurl_display = shorten(licenseurl); document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text_display+"
Author link: "+authorlink_display+"
License URL: "+licenseurl_display+"
"; last_photo_link = text; showDialog(); } diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index 142bcba..efa5a9b 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -397,13 +397,22 @@ if (get_included_files()[0] === __FILE__) { } + function shorten(u) { + if (u.length < 48) { + return u; + } + uend = u.slice(u.length - 16); + ustart = u.substr(0, 32); + var shorter = ustart + '...' + uend; + return shorter; + } + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { + let text_display = shorten(text); + let authorlink_display = shorten(authorlink); + let licenseurl_display = shorten(licenseurl); document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; - - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; - + document.getElementById('modalText').innerHTML = "

Image link: "+text_display+"
Author link: "+authorlink_display+"
License URL: "+licenseurl_display+"
"; last_photo_link = text; showDialog(); }