MediaWiki:Common.js: Difference between revisions

From Imperial Minerals Wiki
No edit summary
Tag: Reverted
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


function initMap() {
    var element = document.getElementById('map');
    var dataSrc = element.getAttribute('data-src');


// Assuming your div has an id 'map'
    if (dataSrc) {
var element = document.getElementById('map');
         var coordinates = dataSrc.split(/[;,]/).map(function(coord) {
 
// Check if the element has a data-src attribute
if (element && element.hasAttribute('data-src')) {
    // If data-src exists, proceed to display the map
    displayMap(element.getAttribute('data-src'));
} else {
    // If data-src doesn't exist, hide the div
    element.style.display = 'none';
}
 
function displayMap(coordinates) {
    // Your existing initMap and Google Maps API script inclusion code
    function initMap() {
         var coordinatesArray = coordinates.split(/[;,]/).map(function(coord) {
             return parseFloat(coord.trim());
             return parseFloat(coord.trim());
         });
         });


         var mapOptions = {
         var mapOptions = {
             center: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
             center: { lat: coordinates[0], lng: coordinates[1] },
             zoom: 15
             zoom: 4
         };
         };
         var map = new google.maps.Map(element, mapOptions);
         var map = new google.maps.Map(element, mapOptions);


         var marker = new google.maps.Marker({
         var marker = new google.maps.Marker({
             position: { lat: coordinatesArray[0], lng: coordinatesArray[1] },
             position: { lat: coordinates[0], lng: coordinates[1] },
             map: map,
             map: map,
             title: 'Marker Title'
             title: 'Marker Title'
         });
         });
    } else {
        // Add the 'no-data' class if data-src doesn't exist
        element.classList.add('no-data');
     }
     }
}
var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
script.async = true;
script.defer = true;
document.head.appendChild(script);
    if (document.body.classList.contains('page-Main_Page')) {
        if (document.cookie.indexOf('popupClosed=true') === -1) {
            var popup = document.createElement('div');
            popup.className = 'popup';
                    var popupContent = document.createElement('span');
        popup.innerHTML = '<span><h>Content Note</h><p>As a database of 19th-century material, some of the texts in this Wiki may contain racist, offensive, and discriminatory language and imagery.</p> <a class="button">okay</a></span>';


    var script = document.createElement('script');
            document.body.insertBefore(popup, document.body.firstChild);
    script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
 
    script.async = true;
            popup.style.display = 'block';
    script.defer = true;
 
    document.head.appendChild(script);
            popup.addEventListener('click', function () {
}
                popup.style.display = 'none';
                document.cookie = 'popupClosed=true; expires=' + new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toUTCString(); // Set cookie to expire in one year
            });
        }
    }

Latest revision as of 23:37, 27 March 2024

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

function initMap() {
    var element = document.getElementById('map');
    var dataSrc = element.getAttribute('data-src');

    if (dataSrc) {
        var coordinates = dataSrc.split(/[;,]/).map(function(coord) {
            return parseFloat(coord.trim());
        });

        var mapOptions = {
            center: { lat: coordinates[0], lng: coordinates[1] },
            zoom: 4
        };
        var map = new google.maps.Map(element, mapOptions);

        var marker = new google.maps.Marker({
            position: { lat: coordinates[0], lng: coordinates[1] },
            map: map,
            title: 'Marker Title'
        });
    } else {
        // Add the 'no-data' class if data-src doesn't exist
        element.classList.add('no-data');
    }
}


var script = document.createElement('script');
script.src = 'https://maps.googleapis.com/maps/api/js?key=AIzaSyBIrgq5dZQ8haJIfKHbGco90OpDwYLiXwA&callback=initMap';
script.async = true;
script.defer = true;
document.head.appendChild(script);



    if (document.body.classList.contains('page-Main_Page')) {
        if (document.cookie.indexOf('popupClosed=true') === -1) {
            var popup = document.createElement('div');
            popup.className = 'popup';

                    var popupContent = document.createElement('span');
        popup.innerHTML = '<span><h>Content Note</h><p>As a database of 19th-century material, some of the texts in this Wiki may contain racist, offensive, and discriminatory language and imagery.</p> <a class="button">okay</a></span>';

            document.body.insertBefore(popup, document.body.firstChild);

            popup.style.display = 'block';

            popup.addEventListener('click', function () {
                popup.style.display = 'none';
                document.cookie = 'popupClosed=true; expires=' + new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toUTCString(); // Set cookie to expire in one year
            });
        }
    }