From 790dee2602010507dce6a3884444dcef86a1ebe1 Mon Sep 17 00:00:00 2001 From: frcroth Date: Wed, 9 Aug 2023 18:15:27 +0200 Subject: [PATCH 1/5] Add abbreviation explanations on mobile --- myhpi/core/markdown/utils.py | 8 ++++---- myhpi/static/js/myHPI.js | 5 +++++ myhpi/static/scss/myHPI.scss | 20 +++++++++++++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/myhpi/core/markdown/utils.py b/myhpi/core/markdown/utils.py index dd3e55a4..b095e51e 100644 --- a/myhpi/core/markdown/utils.py +++ b/myhpi/core/markdown/utils.py @@ -12,12 +12,12 @@ def render_markdown(text, context=None, with_abbreveations=True): """ if context is None or not isinstance(context, dict): context = {} - markdown_html, toc = _transform_markdown_into_html(text, with_abbreveations=with_abbreveations) + markdown_html, toc = _transform_markdown_into_html(text, with_abbreviations=with_abbreveations) sanitised_markdown_html = _sanitise_markdown_html(markdown_html) return mark_safe(sanitised_markdown_html), mark_safe(toc) -def _transform_markdown_into_html(text, with_abbreveations): +def _transform_markdown_into_html(text, with_abbreviations): from myhpi.core.models import AbbreviationExplanation markdown_kwargs = _get_markdown_kwargs() @@ -25,7 +25,7 @@ def _transform_markdown_into_html(text, with_abbreveations): MinuteExtension() ) # should be in settings.py, but module lookup doesn't work md = markdown.Markdown(**markdown_kwargs) - abbreveations = "\n\n" + ( + abbreviations = "\n\n" + ( "\n".join( [ f"*[{abbr.abbreviation}]: {abbr.explanation}" @@ -33,5 +33,5 @@ def _transform_markdown_into_html(text, with_abbreveations): ] ) ) - text = smart_str(text) + abbreveations if with_abbreveations else smart_str(text) + text = smart_str(text) + abbreviations if with_abbreviations else smart_str(text) return md.convert(text), md.toc diff --git a/myhpi/static/js/myHPI.js b/myhpi/static/js/myHPI.js index 7198c8ca..ea00e445 100644 --- a/myhpi/static/js/myHPI.js +++ b/myhpi/static/js/myHPI.js @@ -109,3 +109,8 @@ window.onresize = () => { adaptNavbarToWindowSize() updateNavbarPosition() } + +/* https://stackoverflow.com/questions/12539006/tooltips-for-mobile-browsers */ +// To enable tooltips on mobile, add tabindex=0 to abbr elements. +document.querySelectorAll("abbr") + .forEach(node => node.setAttribute("tabindex", "0")) diff --git a/myhpi/static/scss/myHPI.scss b/myhpi/static/scss/myHPI.scss index 1e4eccee..b5a8b466 100644 --- a/myhpi/static/scss/myHPI.scss +++ b/myhpi/static/scss/myHPI.scss @@ -286,4 +286,22 @@ h1.side-panel-title::after { margin-top: 50px; order: 3; } -} \ No newline at end of file +} + +@media (pointer: coarse), (hover: none) { + [title] { + position: relative; + display: inline-flex; + justify-content: center; + } + [title]:focus::after { + content: attr(title); + position: absolute; + top: 90%; + color: #000; + background-color: #fff; + border: 1px solid; + width: fit-content; + padding: 3px; + } + } From 37e3a27b0a05b0892406ef980e1923a0aaf672f2 Mon Sep 17 00:00:00 2001 From: abc013 Date: Tue, 13 Feb 2024 21:02:31 +0100 Subject: [PATCH 2/5] Remove js-way and add filter for showing abbreviations on mobile apps --- myhpi/core/templates/core/information_page.html | 2 +- myhpi/core/templates/core/minutes.html | 2 +- myhpi/core/templatetags/core_extras.py | 14 ++++++++++++++ myhpi/static/js/myHPI.js | 5 ----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/myhpi/core/templates/core/information_page.html b/myhpi/core/templates/core/information_page.html index f2257080..17bb54db 100644 --- a/myhpi/core/templates/core/information_page.html +++ b/myhpi/core/templates/core/information_page.html @@ -12,7 +12,7 @@

{{ page.title }}

- {{ parsed_md.0 }} + {{ parsed_md.0|touchify_abbrevations }}
diff --git a/myhpi/core/templates/core/minutes.html b/myhpi/core/templates/core/minutes.html index 3b4909a9..77a5f17c 100644 --- a/myhpi/core/templates/core/minutes.html +++ b/myhpi/core/templates/core/minutes.html @@ -11,7 +11,7 @@

{{ page.title }}

- {{ parsed_md.0 }} + {{ parsed_md.0|touchify_abbrevations }}
diff --git a/myhpi/core/templates/core/minutes.html b/myhpi/core/templates/core/minutes.html index 04ded6dc..6d6ddfd5 100644 --- a/myhpi/core/templates/core/minutes.html +++ b/myhpi/core/templates/core/minutes.html @@ -12,7 +12,7 @@

{{ page.title }}

- {{ parsed_md.0|touchify_abbrevations|tag_external_links }} + {{ parsed_md.0|touchify_abbreviations|tag_external_links }}