Set a umap-fragment web component for lists

This commit is contained in:
David Larlet 2024-01-09 14:45:16 -05:00
parent 4b34a7d300
commit 7b5b5b1b22
No known key found for this signature in database
GPG key ID: 3E2953A359E7E7BD
4 changed files with 17 additions and 15 deletions

View file

@ -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')

View file

@ -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)

View file

@ -58,4 +58,5 @@
<script src="{{ STATIC_URL }}umap/js/umap.share.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.ui.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.components.js" defer></script>
{% endcompress %}

View file

@ -1,10 +1,4 @@
{% load umap_tags %}
<umap-fragment data-settings='{{ map_settings|notag|safe }}'>
<div id="{{ unique_id }}" class="map_fragment"></div>
<!-- djlint:off -->
<script type="text/javascript">
// Wait for JS modules to be loaded
window.addEventListener('DOMContentLoaded', (event) => {
new L.U.Map("{{ unique_id }}", {{ map_settings|notag|safe }})
});
</script>
<!-- djlint:on -->
</umap-fragment>