From 62fe82b1709fc3c017ea8c4a360458bf3c6fc6ab Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 3 Oct 2024 18:15:14 +0200 Subject: [PATCH 01/10] refactor(core): move script tag from include Move + {# Bootstrap 4.6.2 bundle (without jQuery) #} + {# see https://getbootstrap.com/docs/4.6/getting-started/introduction/ #} + @@ -240,7 +245,6 @@ {% endblock footer %} {% block scripts %} - {% include "partials/bootstrap4_js.html" %} From 891ff506ed05adc10f25a0daf3ff067cc1655ae4 Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 3 Oct 2024 18:19:52 +0200 Subject: [PATCH 02/10] refactor(core): move script tag, update attributes Move + {% endblock %} @@ -245,7 +248,6 @@ {% endblock footer %} {% block scripts %} - - {% endblock %} + {% block scripts %}{% endblock %} {% block modal %} From 23590b1b421c4410cadedce5172552dd7580b5e1 Mon Sep 17 00:00:00 2001 From: KK Date: Wed, 9 Oct 2024 12:01:29 +0200 Subject: [PATCH 06/10] docs(core): add, update comments HTMX config Add to, update formatting of existing comments on HTMX swap config. --- apis_core/core/static/js/core.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apis_core/core/static/js/core.js b/apis_core/core/static/js/core.js index 6f5caa568..93388e024 100644 --- a/apis_core/core/static/js/core.js +++ b/apis_core/core/static/js/core.js @@ -12,9 +12,10 @@ function configMultiSelect() { * see also https://htmx.org/events/ */ function configHtmx() { + // DOM content swapping behaviour document.body.addEventListener('htmx:beforeSwap', function(event) { if (event.detail.xhr.status === 204) { - // Swap content even when the response is empty. + // swap even when the response is empty event.detail.shouldSwap = true; } }); From 57ff120c6f0f0dd94a864c013947fd086d8c17a1 Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 3 Oct 2024 18:33:27 +0200 Subject: [PATCH 07/10] refactor(core): move scroll button JS Move internal script from included partial template backtotopbtn.html to external core.js file. --- apis_core/core/static/js/core.js | 31 +++++++++++++++++++ .../core/templates/partials/backtotopbtn.html | 27 ---------------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/apis_core/core/static/js/core.js b/apis_core/core/static/js/core.js index 93388e024..48f259a0f 100644 --- a/apis_core/core/static/js/core.js +++ b/apis_core/core/static/js/core.js @@ -21,6 +21,36 @@ function configHtmx() { }); } +/* scroll-to-top button */ +function scrollButton() { + + //Get the button + let mybutton = document.getElementById("btn-back-to-top"); + + // When the user scrolls down 20px from the top of the document, show the button + window.onscroll = function () { + scrollFunction(); + }; + + function scrollFunction() { + if ( + document.body.scrollTop > 20 || + document.documentElement.scrollTop > 20 + ) { + mybutton.style.display = "block"; + } else { + mybutton.style.display = "none"; + } + } + // When the user clicks on the button, scroll to the top of the document + mybutton.addEventListener("click", backToTop); + + function backToTop() { + document.body.scrollTop = 0; + document.documentElement.scrollTop = 0; + } +} + document.addEventListener("readystatechange", (event) => { if (event.target.readyState === "interactive") { // equivalent to DOMContentLoaded; document has loaded, defered scripts @@ -30,5 +60,6 @@ document.addEventListener("readystatechange", (event) => { configMultiSelect(); configHtmx(); + scrollButton(); } }); diff --git a/apis_core/core/templates/partials/backtotopbtn.html b/apis_core/core/templates/partials/backtotopbtn.html index 5718b2466..cbb8bb5b6 100644 --- a/apis_core/core/templates/partials/backtotopbtn.html +++ b/apis_core/core/templates/partials/backtotopbtn.html @@ -12,30 +12,3 @@ id="btn-back-to-top"> - From a08172d8029cafdc58cd2ab595497fb154a46f4b Mon Sep 17 00:00:00 2001 From: KK Date: Wed, 9 Oct 2024 11:55:30 +0200 Subject: [PATCH 08/10] docs(core): update comments scroll button Improve wording, formatting of existing comments on scroll button JavaScript. --- apis_core/core/static/js/core.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apis_core/core/static/js/core.js b/apis_core/core/static/js/core.js index 48f259a0f..927b76fd3 100644 --- a/apis_core/core/static/js/core.js +++ b/apis_core/core/static/js/core.js @@ -24,14 +24,14 @@ function configHtmx() { /* scroll-to-top button */ function scrollButton() { - //Get the button + // get the button let mybutton = document.getElementById("btn-back-to-top"); - // When the user scrolls down 20px from the top of the document, show the button window.onscroll = function () { scrollFunction(); }; + // show button when user has scrolled down 20px from top of document function scrollFunction() { if ( document.body.scrollTop > 20 || @@ -42,7 +42,8 @@ function scrollButton() { mybutton.style.display = "none"; } } - // When the user clicks on the button, scroll to the top of the document + + // scroll back up on click on button mybutton.addEventListener("click", backToTop); function backToTop() { From 13ba98bbf338f7cef1f0caad9a016dc4363aef5d Mon Sep 17 00:00:00 2001 From: KK Date: Thu, 3 Oct 2024 18:43:12 +0200 Subject: [PATCH 09/10] feat(core): defer external scripts Set defer attribute on script tags for external scripts. --- apis_core/core/templates/base.html | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/apis_core/core/templates/base.html b/apis_core/core/templates/base.html index 3643f7bbf..03017a5b3 100644 --- a/apis_core/core/templates/base.html +++ b/apis_core/core/templates/base.html @@ -58,20 +58,26 @@ {% endblock styles %} {% block scriptHeader %} - + {# Bootstrap 4.6.2 bundle (without jQuery) #} {# see https://getbootstrap.com/docs/4.6/getting-started/introduction/ #} - - - + crossorigin="anonymous" + defer> + + + - - + crossorigin="anonymous" + defer> + + {% endblock %} From 8a890b9947248dbf62a686842bfc760b7b9bea2a Mon Sep 17 00:00:00 2001 From: KK Date: Wed, 9 Oct 2024 12:41:46 +0200 Subject: [PATCH 10/10] style(apis_relations): reformat internal JS Reformat JavaScript in {% object_relations as object_relations %} {% endblock scripts %}