Merge pull request #1516 from umap-project/umap-components

Set a umap-fragment web component for lists
This commit is contained in:
David Larlet 2024-01-10 20:35:11 -05:00 committed by GitHub
commit 08e50567de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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/components/fragment.js" defer></script>
{% endcompress %}

View file

@ -1,10 +1,4 @@
{% load umap_tags %}
<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 data-settings='{{ map_settings|notag|safe }}'>
<div id="{{ unique_id }}" class="map_fragment"></div>
</umap-fragment>