MediaWiki:Common.js

From Firrhna Project Wiki
Revision as of 20:57, 15 December 2023 by Kawa-neechan (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 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 = function() {
		if (xhr.status === 200) {
			result.innerHTML = xhr.responseText;
		}
		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="submitIt(); return false;">
	<label> Word: <input type="text" id="dictWord"></label>
	<label><input type="checkbox" id="dictEnglish"> Word is in English</label>
	<input type="submit" onclick="getDictionaryResult();" value="Look up">
</form>
<div id="result"></div>';
}