Jump to content

MediaWiki:Common.js: Difference between revisions

From Costa Sano MediaWiki
No edit summary
No edit summary
Line 1: Line 1:
console.log("Common.js loaded");
console.log("Common.js loaded");
 
console.log("typeof $ is:", typeof $);
// The form is already present in the DOM, so we can run immediately
console.log("typeof jQuery is:", typeof jQuery);
$(function() {
    const addr = $('input[name="Place[address]"]');
    const lat  = $('input[name="Place[latitude]"]');
    const lon  = $('input[name="Place[longitude]"]');
 
    console.log("Address fields found:", addr.length);
 
    if (addr.length === 0) {
        console.log("Address field not found");
        return;
    }
 
    addr.on('change', function() {
        const q = encodeURIComponent(addr.val());
        if (!q) return;
 
        const url = 'https://nominatim.openstreetmap.org/search?format=json&q=' + q;
 
        $.getJSON(url, function(data) {
            if (data && data.length > 0) {
                lat.val(data[0].lat);
                lon.val(data[0].lon);
            }
        });
    });
});

Revision as of 14:59, 14 February 2026

console.log("Common.js loaded");
console.log("typeof $ is:", typeof $);
console.log("typeof jQuery is:", typeof jQuery);