MediaWiki:Common.js: Difference between revisions
From Jcastle.info
No edit summary Tag: Reverted |
No edit summary Tags: Manual revert Reverted |
||
Line 4: | Line 4: | ||
$(function () { | $(function () { | ||
if (mw.config.get('wgAction') === 'formedit') { | if (mw.config.get('wgAction') === 'formedit') { | ||
console.log("📄 GPS helper active on Semantic Form edit page"); | |||
setTimeout(function () { | setTimeout(function () { | ||
var | var latText = mw.util.$content.find('.mediaexif-gpslatitude').text().trim(); | ||
var | var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); | ||
console.log("📡 Raw GPS strings:", latText, lonText); | |||
if (!latText || !lonText) { | |||
console.log("❌ GPSLatitude or GPSLongitude not found."); | |||
return; | |||
} | |||
// If already decimal, just combine them | |||
var latDec = parseFloat(latText); | var latDec = parseFloat(latText); | ||
var lonDec = parseFloat(lonText); | var lonDec = parseFloat(lonText); | ||
if (isNaN(latDec) || isNaN(lonDec)) return; | if (isNaN(latDec) || isNaN(lonDec)) { | ||
console.log("❌ GPS values not decimal numbers."); | |||
return; | |||
} | |||
var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); | var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); | ||
var $ | var $input = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); | ||
if ($ | if ($input.length === 0) { | ||
console.log("⚠️ GPS input field not found."); | |||
return; | |||
} | |||
var $button = $('<button>') | var $button = $('<button>') | ||
.text("📋 Insert EXIF GPS | .text("📋 Insert EXIF GPS") | ||
.attr("type", "button") | .attr("type", "button") | ||
.css({ marginLeft: "0.5em", fontSize: "90%" }) | .css({ marginLeft: "0.5em", fontSize: "90%" }) | ||
.click(function () { | .click(function () { | ||
$ | $input.val(gpsValue).focus(); | ||
alert("✅ GPS inserted: " + gpsValue); | |||
alert("GPS | |||
}); | }); | ||
$ | $input.after($button); | ||
}, 500); | }, 500); | ||
} | } | ||
}); | }); |
Revision as of 10:41, 18 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */ mw.loader.load('//use.fontawesome.com/053a76b93c.js'); $(function () { if (mw.config.get('wgAction') === 'formedit') { console.log("📄 GPS helper active on Semantic Form edit page"); setTimeout(function () { var latText = mw.util.$content.find('.mediaexif-gpslatitude').text().trim(); var lonText = mw.util.$content.find('.mediaexif-gpslongitude').text().trim(); console.log("📡 Raw GPS strings:", latText, lonText); if (!latText || !lonText) { console.log("❌ GPSLatitude or GPSLongitude not found."); return; } // If already decimal, just combine them var latDec = parseFloat(latText); var lonDec = parseFloat(lonText); if (isNaN(latDec) || isNaN(lonDec)) { console.log("❌ GPS values not decimal numbers."); return; } var gpsValue = latDec.toFixed(6) + ", " + lonDec.toFixed(6); var $input = $('input.pfCoordsInput[name="Castle Photo[GPSLocation]"]'); if ($input.length === 0) { console.log("⚠️ GPS input field not found."); return; } var $button = $('<button>') .text("📋 Insert EXIF GPS") .attr("type", "button") .css({ marginLeft: "0.5em", fontSize: "90%" }) .click(function () { $input.val(gpsValue).focus(); alert("✅ GPS inserted: " + gpsValue); }); $input.after($button); }, 500); } });