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)
(JavaScript parse error: Parse error: Missing ) in parenthetical in file 'MediaWiki:Common.js' on line 15)
Line 8: Line 8:
 
}
 
}
  
 +
/** doesn't work yet,
 +
* JavaScript parse error: Parse error: Missing ) in parenthetical in file 'MediaWiki:Common.js' on line 15
  
 
document.addEventListener("DOMContentLoaded", function() {
 
document.addEventListener("DOMContentLoaded", function() {
Line 36: Line 38:
 
     });
 
     });
 
});
 
});
 +
 +
**/

Revision as of 13:46, 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';
}

/** doesn't work yet,
 * JavaScript parse error: Parse error: Missing ) in parenthetical in file 'MediaWiki:Common.js' on line 15

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);
    });
});

**/