Difference between revisions of "MediaWiki:Common.js"

From Hitchwiki
Jump to navigation Jump to search
(do something with <map> see https://github.com/Hitchwiki/hitchwiki/issues/214)
Line 7: Line 7:
 
   $('#mw-input-wpExpiry')[0].value = 'infinite';
 
   $('#mw-input-wpExpiry')[0].value = 'infinite';
 
}
 
}
 +
 +
 +
document.addEventListener("DOMContentLoaded", function() {
 +
    // Find all map elements in the document
 +
    const mapElements = document.querySelectorAll("map[lat][lng][zoom]");
 +
 +
    mapElements.forEach((mapElement) => {
 +
        // Extract the map attributes
 +
        const lat = parseFloat(mapElement.getAttribute("lat"));
 +
        const lon = parseFloat(mapElement.getAttribute("lng"));
 +
        const zoom = parseInt(mapElement.getAttribute("zoom"), 10);
 +
        const width = 300; // Set width for the static map display
 +
        const height = 300; // Set height for the static map display
 +
       
 +
        // Create a container div for the static map
 +
        const mapContainer = document.createElement("div");
 +
 +
        // Call the function to create the static map inside the container
 +
        createStaticMap(mapContainer, lat, lon, zoom, width, height);
 +
 +
        // Create an anchor element that wraps the map container
 +
        const mapLink = document.createElement("a");
 +
        mapLink.href = `https://hitchmap.com/#location,${lat},${lon},${zoom}`;
 +
        mapLink.appendChild(mapContainer);
 +
 +
        // Replace the original <map> element with the link containing the map container
 +
        mapElement.replaceWith(mapLink);
 +
    });
 +
});

Revision as of 13:45, 17 November 2024

/* Any JavaScript here will be loaded for all users on every page load. */

/* https://github.com/Hitchwiki/hitchwiki/issues/23 */
if ($('body.mw-special-Block').length) { 
  $('#mw-input-wpDisableEmail').click();
  $('#mw-input-wpHardBlock').click();
  $('#mw-input-wpExpiry')[0].value = 'infinite';
}


document.addEventListener("DOMContentLoaded", function() {
    // Find all map elements in the document
    const mapElements = document.querySelectorAll("map[lat][lng][zoom]");

    mapElements.forEach((mapElement) => {
        // Extract the map attributes
        const lat = parseFloat(mapElement.getAttribute("lat"));
        const lon = parseFloat(mapElement.getAttribute("lng"));
        const zoom = parseInt(mapElement.getAttribute("zoom"), 10);
        const width = 300; // Set width for the static map display
        const height = 300; // Set height for the static map display
        
        // Create a container div for the static map
        const mapContainer = document.createElement("div");

        // Call the function to create the static map inside the container
        createStaticMap(mapContainer, lat, lon, zoom, width, height);

        // Create an anchor element that wraps the map container
        const mapLink = document.createElement("a");
        mapLink.href = `https://hitchmap.com/#location,${lat},${lon},${zoom}`;
        mapLink.appendChild(mapContainer);

        // Replace the original <map> element with the link containing the map container
        mapElement.replaceWith(mapLink);
    });
});