diff --git a/umap/static/umap/js/components/fragment.js b/umap/static/umap/js/components/fragment.js new file mode 100644 index 00000000..652ca826 --- /dev/null +++ b/umap/static/umap/js/components/fragment.js @@ -0,0 +1,13 @@ +class UmapFragment extends HTMLElement { + connectedCallback() { + new L.U.Map(this.firstElementChild.id, JSON.parse(this.dataset.settings)) + } +} + +function register(Class, tagName) { + if ('customElements' in window && !customElements.get(tagName)) { + customElements.define(tagName, Class) + } +} + +register(UmapFragment, 'umap-fragment') diff --git a/umap/templates/umap/content.html b/umap/templates/umap/content.html index 29cc8329..1019bd6b 100644 --- a/umap/templates/umap/content.html +++ b/umap/templates/umap/content.html @@ -68,12 +68,6 @@ callback: function (data) { const container = this.parentNode container.innerHTML = data - Array.prototype.forEach.call( - container.querySelectorAll('script:not([type="application/json"])'), - function (item) { - eval(item.firstChild.textContent) - } - ) const more = document.querySelector('.more_button') if (more) { L.DomEvent.on(more, 'click', getMore, more) diff --git a/umap/templates/umap/js.html b/umap/templates/umap/js.html index 6f9cd75f..235f4a51 100644 --- a/umap/templates/umap/js.html +++ b/umap/templates/umap/js.html @@ -58,4 +58,5 @@ + {% endcompress %} diff --git a/umap/templates/umap/map_fragment.html b/umap/templates/umap/map_fragment.html index 9aef37c9..12ef96d1 100644 --- a/umap/templates/umap/map_fragment.html +++ b/umap/templates/umap/map_fragment.html @@ -1,10 +1,4 @@ {% load umap_tags %} -
- - - +