MediaWiki:Common.js: Difference between revisions

From Firrhna Project Wiki
Jump to navigationJump to search
(Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: function getDictionaryResult() { var word = document.getElementById('dictWord').value; var inEnglish = document.getElementById('dictEnglish').checked; var result = document.getElementById('dictResult'); var target = '/faas/dict/'; if (inEnglish) target += 'eng/'; target += encodeURIComponent(word); target += '?bare'; var xhr = new XMLHttpRequest(); xhr.open('GET', target); xhr.onload...")
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 11: Line 11:
target += encodeURIComponent(word);
target += encodeURIComponent(word);
target += '?bare';
target += '?bare';
 
result.innerHTML = '...';
var xhr = new XMLHttpRequest();
var xhr = new XMLHttpRequest();
xhr.open('GET', target);
xhr.open('GET', target);
xhr.onload = function() {
xhr.onload = function() {
if (xhr.status === 200) {
if (xhr.status === 200) {
result.innerHTML = xhr.responseText;
var r = xhr.responseText;
r = r.replaceAll('<span class="felinese">', '<span style="font-family: \'Felinese\'; font-weight: bold; font-size: 150%;">');
r = r.replaceAll('<table>', '<table class="wikitable">');
result.innerHTML = r;
}
}
else {
else {
Line 30: Line 34:
var dictPlace = document.getElementById('dictionaryPlaceholder');
var dictPlace = document.getElementById('dictionaryPlaceholder');
if (dictPlace) {
if (dictPlace) {
dictPlace.innerHTML = '<form onsubmit="submitIt(); return false;">
dictPlace.innerHTML = '<form onsubmit="getDictionaryResult(); return false;">\n' +
<label> Word: <input type="text" id="dictWord"></label>
'<label> Word: <input type="text" id="dictWord"></label><br>\n' +
<label><input type="checkbox" id="dictEnglish"> Word is in English</label>
'<label><input type="checkbox" id="dictEnglish"> Word is in English</label><br>\n' +
<input type="submit" onclick="getDictionaryResult();" value="Look up">
'<input type="submit" onclick="getDictionaryResult();" value="Look up">\n' +
</form>
'</form>\n' +
<div id="result"></div>';
'<div id="dictResult"></div>';
}
}

Latest revision as of 21:39, 15 December 2023

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

function getDictionaryResult()
{
	var word = document.getElementById('dictWord').value;
	var inEnglish = document.getElementById('dictEnglish').checked;
	var result = document.getElementById('dictResult');

	var target = '/faas/dict/';
	if (inEnglish) target += 'eng/';
	target += encodeURIComponent(word);
	target += '?bare';
	result.innerHTML = '...';
	
	var xhr = new XMLHttpRequest();
	xhr.open('GET', target);
	xhr.onload = function() {
		if (xhr.status === 200) {
			var r = xhr.responseText;
			r = r.replaceAll('<span class="felinese">', '<span style="font-family: \'Felinese\'; font-weight: bold; font-size: 150%;">');
			r = r.replaceAll('<table>', '<table class="wikitable">');
			result.innerHTML = r;
		}
		else {
			result.innerHTML = 'Request failed. Returned status of ' + xhr.status;
		}
	};
	xhr.send();

	event.cancelBubble = true;
	return false;
}

var dictPlace = document.getElementById('dictionaryPlaceholder');
if (dictPlace) {
	dictPlace.innerHTML = '<form onsubmit="getDictionaryResult(); return false;">\n' +
		'<label> Word: <input type="text" id="dictWord"></label><br>\n' +
		'<label><input type="checkbox" id="dictEnglish"> Word is in English</label><br>\n' +
		'<input type="submit" onclick="getDictionaryResult();" value="Look up">\n' +
	'</form>\n' +
	'<div id="dictResult"></div>';
}