Fix scripts not running in widgets

This commit is contained in:
Mark Veidemanis 2022-08-26 07:20:30 +01:00
parent 95f00eface
commit 996463b869
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 30 additions and 23 deletions

View File

@ -22,7 +22,7 @@
<script defer src="{% static 'js/htmx.min.js' %}" integrity="sha384-cZuAZ+ZbwkNRnrKi05G/fjBX+azI9DNOkNYysZ0I/X5ZFgsmMiBXgDZof30F5ofc" crossorigin="anonymous"></script>
<script defer src="{% static 'js/remove-me.js' %}" integrity="sha384-6fHcFNoQ8QEI3ZDgw9Z/A6Brk64gF7AnFbLgdrumo8/kBbsKQ/wo7wPegj5WkzuG" crossorigin="anonymous"></script>
<script defer src="{% static 'js/hyperscript.min.js' %}" integrity="sha384-6GYN8BDHOJkkru6zcpGOUa//1mn+5iZ/MyT6mq34WFIpuOeLF52kSi721q0SsYF9" crossorigin="anonymous"></script>
<script src="{% static 'js/bulma-tagsinput.min.js' %}" integrity="sha384-GmnKCsPJIPPZbNVXpkGRmKdxOa0PQLnOM/hQLIHvMRERySuyvFqKGc76iHTGUY+d" crossorigin="anonymous"></script>
<script src="{% static 'js/bulma-tagsinput.min.js' %}"></script>
<script src="{% static 'js/jquery.min.js' %}"></script>
<script src="{% static 'js/gridstack-all.js' %}"></script>
<script defer src="{% static 'js/magnet.min.js' %}"></script>

View File

@ -96,16 +96,18 @@
</script>
{% if table %}
<script>
//var contents = $("#drilldown-widget").outerHTML;
var contents = document.getElementById("drilldown-widget");
var grid = document.getElementById("grid-stack-main").gridstack;
grid.addWidget(contents.innerHTML);
contents.outerHTML = "";
//grid.compact();
// because we remove the element the JS runs in
// so we need to run it again here
// initTabs("{{ unique }}");
//var contents = $("#drilldown-widget").outerHTML;
var contents = document.getElementById("drilldown-widget");
var scripts = contents.getElementsByTagName("script");
var grid = document.getElementById("grid-stack-main").gridstack;
grid.addWidget(contents.innerHTML);
contents.outerHTML = "";
// restore scripts that aren't going to be run
for (var i = 0; i < scripts.length; i++) {
eval(scripts[i].innerHTML);
}
</script>
{% endif %}
{% endblock %}

View File

@ -1,7 +1,10 @@
{% load static %}
<script>
grid.removeWidget("drilldown-widget-results");
if (typeof grid != "undefined") {
grid.removeWidget("drilldown-widget-results");
}
</script>
<div id="drilldown-widget" style="display: none;">
<div id="drilldown-widget-results" class="grid-stack-item" gs-w="10" gs-h="30" gs-y="10" gs-x="1">
<div class="grid-stack-item-content">
@ -53,15 +56,17 @@
</div>
</div>
<script>
console.log("RUNS");
//var contents = $("#drilldown-widget").outerHTML;
var contents = document.getElementById("drilldown-widget");
var grid = document.getElementById("grid-stack-main").gridstack;
grid.addWidget(contents.innerHTML);
contents.outerHTML = "";
// grid.compact();
// because we remove the element the JS runs in
// so we need to run it again here
// initTabs("{{ unique }}");
</script>
if (typeof grid != "undefined") {
//var contents = $("#drilldown-widget").outerHTML;
var contents = document.getElementById("drilldown-widget");
var scripts = contents.getElementsByTagName("script");
var grid = document.getElementById("grid-stack-main").gridstack;
grid.addWidget(contents.innerHTML);
contents.outerHTML = "";
// restore scripts that aren't going to be run
for (var i = 0; i < scripts.length; i++) {
eval(scripts[i].innerHTML);
}
}
</script>