diff --git a/apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_form.html b/apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_form.html index 2aa40d5e9..ac3ce74d4 100644 --- a/apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_form.html +++ b/apis_core/apis_relations/templates/apis_core/apis_entities/abstractentity_form.html @@ -11,125 +11,129 @@ {% block scripts %} {{ block.super }} {% object_relations as object_relations %} {% endblock scripts %} diff --git a/apis_core/core/static/js/core.js b/apis_core/core/static/js/core.js index 4773e09ad..927b76fd3 100644 --- a/apis_core/core/static/js/core.js +++ b/apis_core/core/static/js/core.js @@ -1,7 +1,66 @@ -//script that converts the multi select element -$(document).ready(function() { - $('select.selectmultiple').multiselect({ - includeSelectAllOption: true, - enableFiltering: true - }); -}) +/* config for bootstrap-multiselect widget, +see also https://davidstutz.github.io/bootstrap-multiselect/#configuration-options +*/ +function configMultiSelect() { + $('select.selectmultiple').multiselect({ + includeSelectAllOption: true, + enableFiltering: true + }); +} + +/* config HTMX events, +* 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 even when the response is empty + event.detail.shouldSwap = true; + } + }); +} + +/* scroll-to-top button */ +function scrollButton() { + + // get the button + let mybutton = document.getElementById("btn-back-to-top"); + + window.onscroll = function () { + scrollFunction(); + }; + + // show button when user has scrolled down 20px from top of document + function scrollFunction() { + if ( + document.body.scrollTop > 20 || + document.documentElement.scrollTop > 20 + ) { + mybutton.style.display = "block"; + } else { + mybutton.style.display = "none"; + } + } + + // scroll back up on click on button + 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 + // have downloaded and executed, sub-resources may not be ready yet + } else if (event.target.readyState === "complete") { + // fired when fully loaded, incl. sub-resources and async scripts + + configMultiSelect(); + configHtmx(); + scrollButton(); + } +}); diff --git a/apis_core/core/templates/base.html b/apis_core/core/templates/base.html index cd0991c71..03017a5b3 100644 --- a/apis_core/core/templates/base.html +++ b/apis_core/core/templates/base.html @@ -58,12 +58,26 @@ {% endblock styles %} {% block scriptHeader %} - - - - - - + + {# Bootstrap 4.6.2 bundle (without jQuery) #} + {# see https://getbootstrap.com/docs/4.6/getting-started/introduction/ #} + + + + + + + {% endblock %} @@ -239,18 +253,7 @@ {% endblock footer %} - {% block scripts %} - {% include "partials/bootstrap4_js.html" %} - - - {% endblock %} + {% block scripts %}{% endblock %} {% block modal %} 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"> - diff --git a/apis_core/core/templates/partials/bootstrap4_js.html b/apis_core/core/templates/partials/bootstrap4_js.html deleted file mode 100644 index efdd42aea..000000000 --- a/apis_core/core/templates/partials/bootstrap4_js.html +++ /dev/null @@ -1,4 +0,0 @@ -{# the bootstrap 4.6.2 javascript, as suggested on https://getbootstrap.com/docs/4.6/getting-started/introduction/ #} -