The below script shows in the location plugin the tooltip permanently and give them colors to sort them according to their type(events, venues, etc), I’m working on a legend and maybe a filter.
The situation is that It does work, but only after I refresh the page, it does not work when landing on the page from the url.
There is no differences in the errors in the console in both cases and adding a higher delay to the function does not change a thing.
Has anyone ever experienced this when adding js to the header from the edit theme menu and found a solution?
<script>
document.addEventListener('DOMContentLoaded', function() {
// Apply CSS to change the alt text style
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = `
/* Ensure alt text is bold, underlined, and has conditional color */
.leaflet-marker-pane img[alt] {
font-weight: bold !important; /* Make text bold */
text-decoration: underline !important; /* Underline the text */
white-space: nowrap; /* Prevent the text from wrapping to a new line */
}
`;
document.head.appendChild(style);
// Give the page a moment to load and the images to be rendered
setTimeout(function() {
var images = document.querySelectorAll('.leaflet-marker-pane img');
images.forEach(function(img) {
var title = img.getAttribute('title');
if (title) {
title = title.length > 10 ? title.substring(0, 10) + '..' : title;
img.setAttribute('alt', title);
img.setAttribute('title', title);
if (title.includes('/')) {
img.style.color = 'white';
} else {
img.style.color = 'black';
}
}
img.setAttribute('src', '');
});
}, 1000); // Delay execution by 1 second (1000 ms)
});
</script>
Good to know, I won’t bother using an adapted window.location.reload(true) in the header for an ember.js framework which might have been a solution for this.
Is the header field being deprecated out of security reasons? The thing is that it is still convenient to test vanilla javascript in it.
ok als javascript in headers binnenkort verouderd is, moet ik een paar dingen aanpassen, misschien kan dit header-veld een melding bevatten over deze aankomende situatie.
Ik denk dat het zijn redenen heeft, maar het kan jammer zijn, aangezien scripts in headers nuttig zijn en snelle aanpassingen voor beheerders mogelijk maken, zoals: het sluiten van evenementregistratie wanneer een specifiek aantal wordt bereikt door een javascript-functie voor een specifieke categorie.
sorry I answered to you instead of Jay who says that scripts are going to be deprecated, I imagine he is speaking about header scripts that are just very convenient to use for quick modifications just like in any website CMS.
Ik heb eigenlijk een oplossing gevonden die alleen de “map”-pagina opnieuw laadt telkens wanneer je erop gaat.
Ik vraag me nu af of dit de moeite waard is om hier met anderen te delen als header-scripts verouderd zullen zijn? Het script in dit bericht maakt kleurencategorieën mogelijk volgens de inhoud van een evenementtitel op de kaart, dit zou snel veranderbaar moeten zijn, niet via de API-functie.
Ik denk dat u mij verkeerd begrepen heeft. Ik bedoelde dat script-tags in de header zoals \u003cscript type=\"text/discourse-plugin\"\u003e en \u003cscript type=\"text/x-handlebars\"\u003e verouderd zijn, niet normale \u003cscript\u003e-tags.
ja, bedankt voor de verduidelijking, ik ben blij dat we javascript kunnen plaatsen, bekijk de code die ik heb achtergelaten als je tijd hebt, deze kan nog steeds nuttig zijn in ember-omgevingen, het laadt de pagina opnieuw, zodat de js wordt toegepast. Het is niet het mooiste, maar het werkt goed voor de kaartpluginpagina!