MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 5: | Line 5: | ||
const title = mw.config.get('wgPageName'); | const title = mw.config.get('wgPageName'); | ||
if (title && title.startsWith('Dashboard:')) { | if (title && title.startsWith('Dashboard:')) { | ||
// | // Only purge once per load | ||
if (!window.location.search.includes(' | if (!window.location.search.includes('purged=1')) { | ||
// Perform a silent purge via AJAX | |||
$.post(mw.util.wikiScript('api'), { | |||
action: 'purge', | |||
titles: title, | |||
format: 'json' | |||
}).always(function () { | |||
// Reload the dashboard normally, but mark it as purged | |||
const url = mw.util.getUrl(title, { purged: 1 }); | |||
window.location.replace(url); | |||
}); | |||
} | } | ||
} | } | ||
}); | }); | ||
/************************************************************ | /************************************************************ | ||
Revision as of 21:25, 14 February 2026
/************************************************************
* 1. AUTO‑PURGE FOR ALL DASHBOARD:* PAGES
************************************************************/
$(function () {
const title = mw.config.get('wgPageName');
if (title && title.startsWith('Dashboard:')) {
// Only purge once per load
if (!window.location.search.includes('purged=1')) {
// Perform a silent purge via AJAX
$.post(mw.util.wikiScript('api'), {
action: 'purge',
titles: title,
format: 'json'
}).always(function () {
// Reload the dashboard normally, but mark it as purged
const url = mw.util.getUrl(title, { purged: 1 });
window.location.replace(url);
});
}
}
});
/************************************************************
* 2. AUTOMATIC GEOCODING (your existing code, unchanged)
************************************************************/
$(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() {
console.log("Address changed:", addr.val());
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);
}
});
});
});
/************************************************************
* 3. OSM LINK BELOW LONGITUDE FIELD (your existing code)
************************************************************/
$(function() {
const lat = $('input[name="Place[latitude]"]');
const lon = $('input[name="Place[longitude]"]');
// Add a small container under the longitude field
const linkBox = $('<div id="pf-osm-link" style="margin-top:4px;"></div>');
lon.closest('td').append(linkBox);
function updateOSMLink() {
const la = lat.val();
const lo = lon.val();
if (la && lo) {
const url = 'https://www.openstreetmap.org/?mlat=' + la + '&mlon=' + lo;
linkBox.html('<a href="' + url + '" target="_blank">View on OpenStreetMap</a>');
} else {
linkBox.empty();
}
}
// Update whenever coordinates change
lat.on('change keyup', updateOSMLink);
lon.on('change keyup', updateOSMLink);
// Initial update (for editing existing pages)
updateOSMLink();
});