MediaWiki:Gadget-DefSideBoxes.js

Hello, you have come here looking for the meaning of the word MediaWiki:Gadget-DefSideBoxes.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word MediaWiki:Gadget-DefSideBoxes.js, but we will also tell you about its etymology, its characteristics and you will know how to say MediaWiki:Gadget-DefSideBoxes.js in singular and plural. Everything you need to know about the word MediaWiki:Gadget-DefSideBoxes.js you have here. The definition of the word MediaWiki:Gadget-DefSideBoxes.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofMediaWiki:Gadget-DefSideBoxes.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
// Newer version of User:Yair rand/editor.js
// <nowiki>

var autoTranslitScripts = {
	"Geor": true
};

window.makedefsidebox = function(q) {
	function clickiconfunction() {
		var moreoptions, originalHeight, buttons;

		function uncollapse() {
			$(moreoptions).slideUp();
			$("body").off("click", uncollapse);
		}
		editdefinition(q);
		if ($('>.addusexbutton', q).length === 0) {
			buttons = q.insertBefore(newNode('div', {
				'class': 'addusexbutton'
			}, newNode('a', '+Add example sentence', {
				'click': function() {
					setupusexadder(q);
				}
			}), newNode('a', '+Add quotation', {
				'click': function() {
					setupquoteadder(q);
				}
			}), newNode('a', 'More ►', {
				'click': function() {
					$(moreoptions).slideDown();
					setTimeout(function() {
						$("body").click(uncollapse);
					}, 16);
				}
			}), newNode('span', {
				'style': 'display:inline-block;'
			}, moreoptions = newNode('ul', newNode('li', q.className ? newNode('a', 'Edit gloss', {
				'click': function() {
					editgloss(q);
				}
			}) : newNode('a', 'Add gloss', {
				'click': function() {
					addgloss(q);
				}
			})), newNode('li', newNode('a', q.className ? undefined : {
				'class': 'DSBinactive',
				'title': 'Please add a gloss before adding synonyms.'
			}, {
				'click': function() {
					setupnymadder(q, "Synonyms");
				}
			}, 'Add synonyms')), newNode('li', newNode('a', q.className ? undefined : {
				'class': 'DSBinactive',
				'title': 'Please add a gloss before adding antonyms.'
			}, {
				'click': function() {
					setupnymadder(q, "Antonyms");
				}
			}, 'Add antonyms')), newNode('li', newNode('a', {
				'href': mw.config.get('wgScript') + '?title=User_talk:Yair_rand/editor2.js&action=edit&section=new'
			}, 'Give feedback on this tool')), newNode('li', newNode('a', {
				click: function() {
					$.cookie("DisableYREdit", 1, {
						path: '/'
					});
					location.href = location.href;
				}
			}, 'Disable this tool'))))), $('>dl,>ul,>ol', q) || null);
		}
	}
	q.insertBefore(
		newNode('span', {
			'class': 'defEditButton'
		}, newNode('span', {
			'click': clickiconfunction,
			'title': 'Edit'
		})), q.firstChild);
	return clickiconfunction;
}

function setupusexadder(qq) {
	var x, y;
	var usexform;
	var findsubdef = (qq.parentNode.parentNode.nodeName.toLowerCase() == "li" ? "#" : "") + (qq.parentNode.parentNode.parentNode.parentNode.nodeName.toLowerCase() == "li" ? "#" : "")
	editor = new Editor()
	findlang(qq.parentNode, function(findlang_) {
		var findscript = (new LangMetadata()).getScripts(findlang_),
			selectedscript = findscript || "Latn";
		if (qq.getElementsByTagName('dl') && qq.getElementsByTagName('dl').parentNode == qq) x = qq.getElementsByTagName('dl');
		else if ($(">ul", qq).length > 0) x = qq.insertBefore(newNode('dl'), $(">ul", qq));
		else x = qq.appendChild(newNode('dl'));


		x.appendChild(y = newNode('dd'))

		new AdderWrapper(new Editor(), {
			'createForm': function() {
				var x, i = 0,
					y = function() {
						selectedscript = this.value;
						usexform.getElementsByTagName('dd').style.display = this.value == 'Latn' ? 'none' : 'block'
					}
				if (findscript.length > 1) {
					for (x = newNode('select', {
							'name': 'script',
							'change': y
						}); i < findscript.length; i++) {
						x.appendChild(newNode('option', {
							'value': findscript
						}, findscript))
					}
				} else {
					x = newNode('input', {
						'name': 'script',
						'value': findscript || "Latn",
						'style': "width:50px;",
						'change': y
					})
				}
				return usexform = newNode('form', {
					'style': 'display:inline;'
				}, newNode('input', {
					'size': 100,
					'placeholder': 'Example sentence',
					'name': 'examplesentence'
				}), newNode('span', {
					'style': 'display:' + (findscript.length == 1 ? "none" : "inline") + ";"
				}, 'Script: ', x), newNode('div', {
					'class': "DSBRedButton",
					'click': function() {
						usexform.style.display = 'none'
					}
				}, newNode('div', 'Cancel')), newNode('div', {
					'class': "DSBGreenButton",
					'click': function() {
						usexform.onsubmit()
					}
				}, newNode('div', "Preview ►")), newNode('input', {
					'type': 'submit',
					'style': 'visibility:hidden;width:0px;'
				}), newNode('dl', (findlang_ == "en" ? {
					'style': 'display:none;'
				} : ''), newNode('dd', 'Transliteration: ', ((findscript == 'Latn' || !findscript) ? {
					'style': 'display:none;'
				} : ''), newNode('input', {
					'size': '100px',
					name: 'transliteration'
				})), newNode('dd', 'Translation: ', newNode('input', {
					'size': '100px',
					name: 'translation'
				}))))
			},
			'fields': {
				'examplesentence': function(txt, error) {
					return util.validateNoWikisyntax('example sentence', true)(txt, error)
				},
				'transliteration': function(txt, error) {
					return txt || '';
				},
				'translation': function(txt, error) {
					if (findlang_ != "en") {
						return util.validateNoWikisyntax('translation', true)(txt, error);
					}
					return '';
				},
				'script': util.validateNoWikisyntax('script', true)
			},
			'onsubmit': function(values, render) {
				var renderWikitext = "";
				if (findlang_ === "en")
					renderWikitext = "''" + values.examplesentence + "''";
				else {
					renderWikitext = "{" + "{ux|" + findlang_ + "|" + values.examplesentence + "|" + values.translation;

					if (values.script) {
						renderWikitext += "|sc=" + values.script;
						if (!(values.script in autoTranslitScripts) && values.transliteration)
							renderWikitext += "|tr=" + values.transliteration;
					}
					renderWikitext += "}}";
				}



				render(renderWikitext, function(newhtml) {

					var findnumberofheaders = findnumberofheaders_(qq);
					var findnumberofdefs = findnumberofdefs_(qq);
					var usextobeadded = newNode('span')
					usextobeadded.innerHTML = newhtml.replace(/<p>|<\/p>/g, '');
					editor.addEdit({
						edit: function(wikitext) {

							var usexWikitext = renderWikitext;

							wikitext = wikitext.replace(RegExp(
								"(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "*?)\n(?!#" + findsubdef + ":)|$"), "$1\n#" + findsubdef + ":" + usexWikitext + "\n");
							ccc = wikitext;
							return wikitext;
						},
						redo: function() {
							usexform.parentNode.appendChild(usextobeadded);
							usextobeadded.style.display = 'block';
							usexform.style.display = "none";
							y.style.display = 'block'
						},
						undo: function() {
							usexform.parentNode.removeChild(usextobeadded);
							usexform.style.display = "inline";
						},
						summary: "+usex: " + values.examplesentence
					}, usextobeadded)

				})
			}
		}, y)
		usexform.firstChild.focus()
	})
}


window.editdefinition = function(qq) {

	(new Editor).withCurrentText(function(wikitext) {
		if (qq.YREditing) {
			return
		}
		qq.YREditing = true;
		var findnumberofheaders = findnumberofheaders_(qq),
			findnumberofdefs = findnumberofdefs_(qq)
		var temporarydefholder = qq.insertBefore(newNode('span', {
			'style': 'display:none;'
		}), qq.childNodes.nodeName.toLowerCase() != "form" ? qq.childNodes : qq.childNodes)
		while (qq.childNodes && qq.childNodes.nodeName != "DL" && qq.childNodes.nodeName != "UL" && qq.childNodes.nodeName != "OL" && qq.childNodes.className != "HQToggle" && qq.childNodes.className != "addusexbutton")
			temporarydefholder.appendChild(qq.childNodes);
		if (qq.childNodes != temporarydefholder) temporarydefholder.insertBefore(qq.childNodes, temporarydefholder.firstChild);
		var defform
		var olddef = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?)"), '').match(/^(\{\{senseid\|*\}\})?\s?(.*)/)
		new AdderWrapper(new Editor(), {
			'createForm': function() {
				return defform = newNode('form', {
					'style': 'width:100%;display:inline-block;margin-bottom:-6px;'
				}, newNode('table', {
					'style': 'width:100%;'
				}, newNode('tr', newNode('td', newNode('input', {
						'style': 'height:17px;width:100%;',
						'name': 'definition',
						'size': 80,
						'value': olddef
					})
					// newNode('input',{type:'submit',value:'Preview'}),
					// newNode('input',{type:'button',value:'Cancel',click:function(){temporarydefholder.style.display='inline';defform.style.display='none';qq.YREditing = false}})
				), newNode('td', {
					'style': 'white-space:nowrap;'
				}, newNode('div', {
					'class': "DSBRedButton"
				}, newNode('div', {
					click: function() {
						temporarydefholder.style.display = 'inline';
						defform.style.display = 'none';
						qq.YREditing = false
					}
				}, "Discard Changes")), newNode('div', {
					'class': "DSBGreenButton"
				}, newNode('div', {
					click: function() {
						defform.onsubmit()
					}
				}, "Preview Changes ►"))))))
			},
			'fields': {
				'definition': function(txt, error) {
					return txt || error("Please specify a definition.")
				}
			},
			'onsubmit': function(values, render) {
				render(values.definition, function(newhtml) {

					editor = new Editor()
					var findnumberofdefs = findnumberofdefs_(qq) // apparently this is sometimes necessary
					var addedspan = newNode('span')
					addedspan.innerHTML = newhtml
					var updatecatscallback;
					editor.addEdit({
						edit: function(wikitext) {
							wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?(\{\{senseid\\|*\}\})*?)(?!{" + "{senseid\\|).*"), "$1" + values.definition);
							ccc = wikitext;
							return wikitext
						},
						redo: function() {
							defform.parentNode.insertBefore(addedspan, defform);
							defform.style.display = temporarydefholder.style.display = 'none';
							updatecatscallback = window.tabbedLanguages && updateCategories(findtopli(defform.parentNode).parentNode.parentNode, values.definition, olddef)
							qq.YREditing = false;
						},
						undo: function() {
							defform.parentNode.removeChild(addedspan);
							defform.style.display = "inline";
							defform.firstChild.firstChild.firstChild.firstChild.value = olddef;
							updatecatscallback && updatecatscallback();
							qq.YREditing = true;
						},
						summary: "def: " + values.definition
					}, addedspan)


				})


			}
		}, qq, qq.childNodes.nodeName.toLowerCase() != "form" ? qq.childNodes : qq.childNodes)

	})

}

function findtopli(li) {
	for (; li.parentNode.parentNode.nodeName.toLowerCase() == "li";) {
		li = li.parentNode.parentNode;
	}
	return li;
}

function findnumberofheaders_(tosearchfrom) {
	tosearchfrom = findtopli(tosearchfrom).parentNode;
	while (!tosearchfrom.nodeName.match(/^h\d$/i))
		tosearchfrom = tosearchfrom.previousSibling;
	return Number(tosearchfrom.lastChild.getElementsByTagName('a').href.match(/\d*$/))
}

function findnumberofdefs_(tosearchfrom) {
	var findnumberofdefs = ,
		tosearchfrom_, findnumberofpredefs = 0,
		result;
	// subdefinitions
	while (tosearchfrom.nodeName.toLowerCase() == "li") {
		tosearchfrom_ = tosearchfrom;
		findnumberofdefs.splice(0, 0, 0);
		while (tosearchfrom) {
			if (tosearchfrom.nodeName.toLowerCase() == "li") findnumberofdefs++;
			tosearchfrom = tosearchfrom.previousSibling;
		}
		tosearchfrom = tosearchfrom_.parentNode.parentNode;
	}
	// in case of any def lists before the current def list under the same header
	for (tosearchfrom_ = tosearchfrom_.parentNode.previousSibling; !tosearchfrom_.nodeName.match(/^h\d$/i); tosearchfrom_ = tosearchfrom_.previousSibling) {
		if (tosearchfrom_.nodeName.toLowerCase() == "ol") findnumberofpredefs += 1;
	}
	result = "(*?\n#*?\n(?!#)){" + findnumberofpredefs + "}";
	for (var i = 0; i < findnumberofdefs.length; i++) {
		result += "(*?\n" + Array(i + 2).join("#") + "(?!)){" + findnumberofdefs + "}";
	}
	return result;
}


function findlang(tosearchfrom, callback) {
	var tosearchfrom_, findlang__
	if (tosearchfrom.parentNode.nodeName.toLowerCase() == "li") tosearchfrom = findtopli(tosearchfrom.parentNode).parentNode;
	if (tosearchfrom.parentNode.className == "languageContainer") {
		if (tosearchfrom.parentNode.id == "Englishcontainer") return callback("en");
	} else {
		tosearchfrom_ = tosearchfrom;
		while (tosearchfrom_.nodeName.toLowerCase() != "h2")
			tosearchfrom_ = tosearchfrom_.previousSibling;
		if (tosearchfrom_.lastChild.innerHTML == "English") return callback("en");
	}
	tosearchfrom_ = tosearchfrom;
	while (tosearchfrom_ && !/^h\d$/i.test(tosearchfrom_.nodeName) && tosearchfrom_.className != "fakeheader")
		tosearchfrom_ = tosearchfrom_.previousSibling;
	while (tosearchfrom_ && tosearchfrom_.nodeName.toLowerCase() != "p" && tosearchfrom_.className != "fakeheader")
		tosearchfrom_ = tosearchfrom_.nextSibling;
	if (tosearchfrom_ && tosearchfrom_.className != "fakeheader" && tosearchfrom_.firstChild && (tosearchfrom_.firstChild.lang || (tosearchfrom_.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.lang) || (tosearchfrom_.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.firstChild && tosearchfrom_.firstChild.firstChild.firstChild.lang))) {
		return callback(tosearchfrom_.firstChild.lang || tosearchfrom_.firstChild.firstChild.lang || tosearchfrom_.firstChild.firstChild.firstChild.lang)
	}

	if (tosearchfrom.parentNode.className == "languageContainer") findlang__ = tosearchfrom.parentNode.id.split("container");
	else {
		while (tosearchfrom.nodeName.toLowerCase() != "h2")
			tosearchfrom = tosearchfrom.previousSibling;
		findlang__ = (findlang__ = tosearchfrom.getElementsByTagName("span")).innerText || findlang__.textContent
	}

	window.languagecodefinder_preload = window.languagecodefinder_preload || mw.loader.getScript('https://en.wiktionary.orghttps://en.wiktionary.org/w/index.php?title=User:Yair_rand/languagecodefinder.js&action=raw&ctype=text/javascript');

	window.languagecodefinder_preload.always( function() {
		window.languagenametocode && languagenametocode && callback(languagenametocode)
	});
}


function setupquoteadder(q) {
	findlang(q.parentNode, function(findlang_) {
		var z;
		if (!$(".HQToggle a", q)) {
			z = q.appendChild(document.createElement("ul"))
			setupHiddenQuotes(q);
		} else {
			z = $(">ul", q);
		}
		if (z.style.display == 'none') {
			$(".HQToggle a", q).click();
		}
		var zz = z.appendChild(document.createElement("li")),
			quoteform;
		var findsubdef = q.parentNode.parentNode.nodeName.toLowerCase() == "li" ? "#" : "",
			editor = new Editor();
		new AdderWrapper(editor, {
			'createForm': function() {
				return quoteform = newNode('form', {
					'style': 'display:inline;'
				}, 'Year: ', newNode('input', {
					'name': 'year',
					'size': 4
				}), ' Author: ', newNode('input', {
					'name': 'author',
					'size': 20
				}), ' Source title: ', newNode('input', {
					'name': 'source',
					'size': 20
				}), ' Publisher: ', newNode('input', {
					'name': 'publisher',
					'size': 20
				}), ' Page(s): ', newNode('input', {
					'name': 'page',
					'size': 5
				}), newNode('dl', newNode('dd', 'Quotation: ', newNode('input', {
					'name': 'quotation',
					'size': 40
				}), newNode('div', {
					'class': "DSBRedButton",
					'click': function() {
						z.removeChild(zz)
					}
				}, newNode('div', 'Cancel')), newNode('div', {
					'class': "DSBGreenButton",
					'click': function() {
						quoteform.onsubmit()
					}
				}, newNode('div', "Preview ►")), newNode('input', {
					'type': 'submit',
					'style': 'visibility:hidden;width:0px;'
				}), newNode('dl', {
					'style': 'display:' + (findlang_ == "en" ? "none" : "block")
				}, newNode('dd', 'Translation: ', newNode('input', {
					'size': 40,
					'name': 'translation'
				}))))))
			},
			'fields': {
				'quotation': util.validateNoWikisyntax('quotation', true),
				'year': util.validateNoWikisyntax('year', true),
				'author': function(t) {
					return t
				},
				'source': function(t) {
					return t ? ", ''" + t + "''" : ''
				},
				'publisher': function(t) {
					return t ? ", " + t : ''
				},
				'page': function(t) {
					return t ? (/\-/.test(t) ? "pages " + t : "page " + t) : t
				},
				'translation': function(t) {
					return t
				}
			},
			'onsubmit': function(values, render) {
				var topline = "'''" + values.year + "'''" + (values.author ? ", " + values.author : '') + values.source + values.publisher + (values.page ? ", " + values.page : '')
				render(topline + "\n:" + values.quotation + (values.translation ? "\n:" + values.translation : ""), function(newhtml) {
					var findnumberofheaders = findnumberofheaders_(q),
						findnumberofdefs = findnumberofdefs_(q),
						quotetobeadded = newNode('span', {
							'style': 'display:block;'
						});
					quotetobeadded.innerHTML = newhtml.replace(/\<p\>|\<\/p\>/g, '');
					editor.addEdit({
						'edit': function(wikitext) {
							return ccc = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "*?)\n(?!#" + findsubdef + ")|$"), "$1\n#" + findsubdef + "*" + topline + "\n#" + findsubdef + "*:" + values.quotation + (values.translation ? "\n#" + findsubdef + "*:" + values.translation : '') + '\n')
						},
						'redo': function() {
							quoteform.style.display = 'none';
							quotetobeadded.style.display = 'block';
							zz.appendChild(quotetobeadded)
						},
						'undo': function() {
							quoteform.style.display = 'inline';
							zz.removeChild(quotetobeadded)
						},
						'summary': '+quote: "' + values.quotation + '"- ' + values.source
					}, quotetobeadded)
				})
			}
		}, zz)
	})
}


window.addPOSHeader = function(cancelhover) {
	var bodyContent = $(".mw-content-ltr");
	if (!defeditoptions.addingPOS) {
		defeditoptions.addingPOS = true;
		editor = new Editor()
		var headerLevel = (window.languageContainers && languageContainers && languageContainers.firstChild) || bodyContent.firstChild;
		var ii;
		var temp, temp_;
		var theform;
		var findnumberofheaders;
		var addedwikitext;
		var prefakeheaders;
		var currentFocus;
		var langNames = ,
			docLink, docExists = {};
		if (window.loadedTabs) {
			langNames = tabbedLanguages;
		} else {
			mw.util.$content.find("h2>.mw-headline").each(function() {
				langNames.push($(this).text())
			})
		}
		var langNameCodes;
		new mw.Api().get({
			"action": "expandtemplates",
			"format": "json",
			"text": "{{#invoke:languages/javascript-interface|GetAllData}}",
			"prop": "wikitext"
		}).done(function(r){
			if(r.expandtemplates && r.expandtemplates.wikitext){
				langNameCodes = JSON.parse(r.expandtemplates.wikitext);
			}
		});
		
		function updateDocLink() {
			var pos = theform.getElementsByTagName("input").value;
			pos = (({
				Adjective: "adj",
				Adverb: "adv",
				Interjection: "interj",
				Preposition: "prep",
				Pronoun: "pron",
				Conjunction: "con",
				Contraction: "cont",
				Determiner: "det"
			}) || pos.toLowerCase());
			if (!langNameCodes || !pos || !theform.getElementsByTagName("input").value) {
				return;
			}
			var currentLang = window.loadedTabs ? theform.parentNode.id.split("container") : (function() {
				for (var s = theform; s && s.nodeName != "H2"; s = s.previousSibling);
				return s && s.lastChild && (s.lastChild.innerText || s.lastChild.textContent)
			})();
			var docName = langNameCodes + "-" + pos;
			if (docExists === false) {
				return docLink.style.display = 'none';
			}
			if (docExists === true) {
				docLink.style.display = 'inline';
				docLink.href = mw.config.get("wgArticlePath").replace("$1", "Template:" + docName + "/doc");
				return;
			}
			if (docExists === 'l') {
				docLink.style.display = 'none';
				return;
			}
			docExists = 'l';
			new mw.Api().get({
				action: 'query',
				prop: 'info',
				titles: 'Template:' + docName + '/documentation'
			}).then(function(r) {
				docExists = r.query.pages.length == 1;
				updateDocLink();
			});
		}

		var poslist = '\nNoun\nVerb\nAdjective\nAdverb\nPronoun\nConjunction\nInterjection\nPreposition\nProper noun\nArticle\nPrepositional phrase\nAcronym\nAbbreviation\nInitialism\nContraction\nPrefix\nSuffix\nSymbol\nLetter\nLigature\nIdiom\nPhrase\nNumber\nNumeral\nCardinal number\nOrdinal number\nCardinal numeral\nOrdinal numeral\nPersonal pronoun\nDeterminer\nDemonstrative determiner\nClitic\nInfix\nInterfix\nAffix\nCircumfix\nCircumposition\nCounter\nKanji\nKanji reading\nHanja reading\nHirigana letter\nKatakana letter\nPinyin\nHan character\nHanzi\nHanja\nProverb\nExpression\nParticle\nInfinitive particle\nPossesive adjective\nPostposition\nPhrasal verb\nParticiple\nGerund\nInterrogative auxiliary verb\nPronominal adverb\nAdnominal\nAbstract pronoun\nConjunction particle\nCombining form\nRoot\nPinyin syllable\nSyllable\nHirigana character\nKatakana character\nJyutping syllable\nGismu\nLujvo\nBrivla\nClassifier\nPredicative\nMeasure word\nCorrelative\nPreverb\nPrenoun\nNoun stem\nNoun class\nCombined-kana character\nCmavo\n';
		while (headerLevel.nextSibling) {
			if (/^h$/i.test(headerLevel.nodeName) && !/Etymology|Pronunciation|Alternative\sforms/.test(headerLevel.innerHTML)) {
				headerLevel = headerLevel.nodeName.toLowerCase();
				break;
			}
			headerLevel = headerLevel.nextSibling
		}

		currentBoxToBeAdded = newNode('div', {
			'style': 'position:fixed;top:500px;'
		})
		new AdderWrapper(editor, {
			createForm: function() {
				return theform = newNode('form', currentFocus = newNode('input', {
					'style': 'font-size: 0.8em;font-size: ' + ((headerLevel == 'h3') ? '132%' : '116%') + ';font-weight: bold;font-family: sans-serif;width:auto;',
					'placeholder': 'Part of speech',
					'rows': 1,
					'name': 'pos',
					focus: function() {
						currentFocus = this
					}
				}), newNode('input', {
					'type': 'submit',
					'value': 'Preview'
				}), newNode('input', {
					'type': 'button',
					'value': 'Cancel',
					click: function() {
						theform.style.display = 'none';
						hoverNewPOS(null);
						defeditoptions.addingPOS = false;
						document.onmousemove = null;
						document.body.style.cursor = '';
					}
				}), newNode('br'), newNode('input', {
					'style': 'width:300px;font-family:monospace;',
					'placeholder': '{\{head}}',
					'name': 'inflline',
					focus: function() {
						currentFocus = this
					}
				}), docLink = newNode('a', {
					style: "margin-left:5px;display:none;",
					'target': '_blank'
				}, "Help?"), newNode('ol', newNode('li', newNode('input', {
					'size': 100,
					'disabled': 'disabled'
				}))))
			},
			fields: {
				'pos': function(txt, error) {
					return poslist.indexOf('\n' + txt + '\n') > -1 ? txt : error('Please select a valid part of speech.')
				},
				'inflline': function(txt, error) {
					return txt || "{" + "{head}}"
				}
			},
			onsubmit: function(values, render) {
				addedwikitext = '{' + '{subst:=}}==' + (headerLevel == 'h4' ? '=' : '') + values.pos + (headerLevel == 'h4' ? '=' : '') + '===\n' + values.inflline
				hoverNewPOS(null);
				document.onmousemove = null;
				defeditoptions.addingPOS = false;
				document.body.style.cursor = '';
				render(addedwikitext, function(res) {
					theform.style.display = 'none'
					temp = document.createDocumentFragment();
					temp.appendChild(temp_ = newNode('div', {
						'class': 'fakeheader'
					}));
					temp_.innerHTML = res;
					temp.appendChild(newNode('ol', newNode('li', ' ', newNode('span'))));
					theform.parentNode.insertBefore(temp, theform);

					prefakeheaders = 0
					findnumberofheaders = theform.previousSibling.previousSibling;
					while (true) {
						if (findnumberofheaders.previousSibling) {
							findnumberofheaders = findnumberofheaders.previousSibling;
							if (/h/i.test(findnumberofheaders.nodeName)) {
								findnumberofheaders = Number(findnumberofheaders.lastChild.getElementsByTagName('a').href.split("section="));
								break;
							}
							findnumberofheaders.className == 'fakeheader' && prefakeheaders++;
						} else {
							findnumberofheaders.parentNode.insertBefore(newNode('h2', languageHeaderEditButtons.cloneNode(true), {
								'style': 'display:none;'
							}), findnumberofheaders);
						}
					}

					var updatecatscallback;
					editor.addEdit({
						'edit': function(wikitext) {
							return ccc = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}(*?\n\\{\\{subst:\\=\\}\\}==" + (headerLevel == 'h4' ? '=' : '') + "){" + prefakeheaders + "}*?(?=(\n=|\n----|\n\\{\\{subst:\\=\\}\\}==" + (headerLevel == 'h4' ? '=' : '') + "|$)))"), "$1\n" + addedwikitext + "\n\n# {" + "{rfdef}}\n")
						},
						'redo': function() {
							theform.style.display = 'none';
							theform.parentNode.insertBefore(temp, theform);
							updatecatscallback = window.tabbedLanguages && updateCategories(theform.parentNode, addedwikitext)
						},
						'undo': function() {
							theform.style.display = 'block';
							temp.appendChild(temp_);
							temp.appendChild(theform.previousSibling);
							updatecatscallback && updatecatscallback()
						},
						'summary': '+pos ' + values.pos
					}, temp_)

					makedefsidebox(theform.previousSibling.firstChild)();

					editor.withCurrentText(function() {
						theform.previousSibling.getElementsByTagName('input').value = '';
						theform.previousSibling.getElementsByTagName('input').focus()
					})
				})
			}
		}, currentBoxToBeAdded)

		cancelhover || setUpBoxToBeAdded();
		theform.firstChild.focus()

		function hoverNewPOS(thefunction) {
			for (var ii = bodyContent.getElementsByTagName(headerLevel), i = 0; i < ii.length; i++) {
				if (!/^Etymology|Pronunciation|Alternative\sforms$/.test(ii.firstChild.innerHTML))(ii.parentNode.className == 'fakeheader' ? ii.parentNode : ii).onmouseover = thefunction;
			}
			if (window.tabbedLanguages) {
				for (var i = 0; i < languageContainers.length; i++)
					languageContainers.lastChild.onmouseover = thefunction;
			} else {
				ii = bodyContent.getElementsByTagName('hr');
				for (var i = 0; i < ii.length; i++)
					ii.onmouseover = thefunction;
			}
		}

		function hoverNewPOS_() {
			currentBoxToBeAdded.style.display = 'none';
			this.parentNode.insertBefore(theform, this);
			currentFocus.focus();
			updateDocLink()
		}

		cancelhover || hoverNewPOS(hoverNewPOS_);

		// autocomplete pos field
		theform.firstChild.onkeydown = function(e) {
			if ((e || event).keyCode == 9) {
				theform.getElementsByTagName("input").focus();
				return false
			}
		}
		theform.firstChild.onkeyup = function(e) {
			if (this.value != this.value.charAt(0).toUpperCase()) this.value = this.value.charAt(0).toUpperCase() + this.value.substr(1);
			e = (e || event).keyCode;
			if (!(e >= 33 && e <= 40) && e != 8 && e != 46 && e != 27 && e != 16 && this.value) {
				if (poslist.indexOf('\n' + this.value) > -1) {
					if (this.setSelectionRange) this.setSelectionRange(*"))], this.value.length);
					else if (this.createTextRange) {
						var z = this.createTextRange();
						z.moveEnd('character', 0 - z.move('character', *"))]) + this.value.length);
						z.select()
					}
				}
				updateDocLink()
			}
		}

	}
}

window.updateCategories = function(container, newvalue, oldvalue) {
	var addedCategories = ,
		removedCategories = 
	new mw.Api().get({
		action: "parse",
		prop: "categorieshtml",
		title: mw.config.get('wgPageName'),
		text: newvalue
	}).then(function(r) {
		var e = r.parse.categorieshtml.match(/\<li.*?\/li\>/g);
		var d = container.lastChild.lastChild;
		var f = document.createElement('ul');
		for (var i = 0; e && i < e.length; i++) {
			f.innerHTML = e;
			if (d.innerHTML.indexOf(f.firstChild.innerHTML) == -1) {
				addedCategories.push(d.insertBefore(f.lastChild, d.lastChild))
			}
		}
		oldvalue && new mw.Api().get({
			action: "parse",
			prop: "categorieshtml",
			title: mw.config.get('wgPageName'),
			text: oldvalue
		}).then(function(o) {
			e = o.parse.categorieshtml.match(/\<li.*?\/li\>/g)
			for (var i = 0; e && i < e.length; i++) {
				f.innerHTML = e;
				if (r.parse.categorieshtml.indexOf(f.firstChild.innerHTML) == -1 && d.innerHTML.indexOf(f.firstChild.innerHTML) != -1) {
					var lis = d.getElementsByTagName('li')
					for (var ii = 0; ii < lis.length; ii++) {
						if (lis.firstChild.innerHTML == f.firstChild.firstChild.innerHTML) {
							removedCategories.push(lis);
							lis.style.display = 'none';
							break;
						}
					}
				}
			}
		})
	});
	return function() {
		for (var i = 0; i < addedCategories.length; i++) {
			container.lastChild.lastChild.removeChild(addedCategories)
		}
		for (var i = 0; i < removedCategories.length; i++) {
			removedCategories.style.display = '';
		}
	}
}

function addgloss(qq) {
	var senseidform;
	findlang(qq.parentNode, function(findlang_) {
		if (qq.addinggloss) {
			return
		}
		qq.addinggloss = true;
		editor = new Editor();
		new AdderWrapper(editor, {
			'createForm': function() {
				return senseidform = newNode('form', {
					'style': 'display:inline; padding-right:20px;'
				}, newNode('input', {
					'size': 30,
					'name': 'senseid'
				}), newNode('input', {
					'type': 'submit',
					'value': 'Add'
				}), newNode('input', {
					'type': 'button',
					'value': 'Cancel',
					'click': function() {
						qq.removeChild(senseidform);
						qq.addinggloss = false
					}
				}), newNode('a', {
					href: 'https://dictious.com/en/Help:Glosses'
				}, 'Help?!'))
			},
			'fields': {
				'senseid': util.validateNoWikisyntax('gloss', true)
			},
			'onsubmit': function(values) {
				var findnumberofheaders = findnumberofheaders_(qq)
				var findnumberofdefs = findnumberofdefs_(qq)
				senseidform.lastChild.innerHTML = '';
				var nymB = qq.getElementsByTagName('li')
				editor.addEdit({
					edit: function(wikitext) {
						wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + ") ?"), "$1{" + "{senseid|" + findlang_ + "|" + values.senseid + "}}");
						return ccc = wikitext;
					},
					redo: function() {
						senseidform.style.display = "none";
						$().removeClass('DSBinactive');
						nymB.firstChild.title = nymB.nextSibling.firstChild.title = ''
					},
					undo: function() {
						senseidform.style.display = "inline";
						$().addClass('DSBinactive');
						nymB.firstChild.title = 'Please add a gloss before adding synonyms.';
						nymB.nextSibling.firstChild.title = 'Please add a gloss before adding antonyms.'
					},
					summary: "+senseid: " + values.senseid
				})
			}
		}, qq, qq.childNodes)
		senseidform.firstChild.focus()
		editor.withCurrentText(function(wikitext) {
			wikitext = wikitext.match("==" + (window.loadedTabs ? tabbedLanguages : $(findtopli(qq).parentNode).prevUntil("h2").eq(-1).prev().find(".mw-headline").text()) + "==\n+?(----|$)");
			if (!wikitext) return;
			var senses = '',
				matches = wikitext.match(/(\{\{sense\||\{\{trans-top\|)+(?=\}\})/g)
			if (!matches) return;
			for (var ms = 0; ms < matches.length; ms++) {
				senses += "\n" + matches.split("|")
			}
			if (!senses) return;
			senseidform.firstChild.onkeyup = function(e) {
				e = (e || event).keyCode;
				if (!(e >= 33 && e <= 40) && e != 8 && e != 46 && e != 27 && e != 16 && this.value) {
					if (senses.indexOf('\n' + this.value) > -1) {
						if (this.setSelectionRange) this.setSelectionRange(*")).toString().substr(1)], this.value.length);
						else if (this.createTextRange) {
							var z = this.createTextRange();
							z.moveEnd('character', 0 - z.move('character', *")).toString().substr(1)]) + this.value.length);
							z.select()
						}
					}
				}
			}
		})
	})
}

function editgloss(qq) {

	editor = new Editor()
	editor.withCurrentText(function(wikitext) {
		if (qq.editinggloss) {
			return
		}
		qq.editinggloss = true;
		var findnumberofheaders = findnumberofheaders_(qq)
		var findnumberofdefs = findnumberofdefs_(qq)
		var senseidform;
		var oldsenseid;
		new AdderWrapper(editor, {
			'createForm': function() {
				var thisId = "a" + String(Math.random()).replace(".", "")
				oldsenseid = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?)"), '').match(/^\{\{senseid\|*\|(*)/)
				return senseidform = newNode('form', {
					'style': 'display:inline; padding-right:20px; '
				}, newNode('input', {
					'size': 30,
					'name': 'senseid',
					'value': oldsenseid
				}), newNode('input', {
					'type': 'checkbox',
					'id': thisId,
					'name': 'changematching',
					style: 'display:' + (window.tabbedLanguages ? 'inline' : 'none')
				}), newNode('label', {
					'for': thisId,
					style: 'display:' + (window.tabbedLanguages ? 'inline' : 'none')
				}, 'Edit matching glosses'), newNode('input', {
					'type': 'submit',
					'value': 'Change'
				}), newNode('input', {
					'type': 'button',
					'value': 'Cancel',
					'click': function() {
						qq.editinggloss = false;
						qq.removeChild(senseidform);
					}
				}), newNode('a', {
					href: 'https://dictious.com/en/Help:Glosses'
				}, 'Help?!'))
			},
			'fields': {
				'senseid': util.validateNoWikisyntax('gloss', true),
				'changematching': 'checkbox'
			},
			'onsubmit': function(values) {
				var ttables = ,
					sensetemps = ,
					backups = ;
				if (values.changematching) {
					ttables = jQuery(".NavHead", languageContainers).filter(function() {
						if (this.parentNode.getElementsByTagName("table").className != "translations") return false;
						for (var i = 0; i < this.childNodes.length; i++) {
							if (this.childNodes.nodeType == 3 || this.childNodes.className == 'wt-edit-recurse') {
								return (this.childNodes.nodeValue || this.childNodes.innerHTML) == oldsenseid;
							}
						}
					})
					sensetemps = jQuery(".qualifier-content", languageContainers).filter(function() {
						return this.parentNode.nextSibling.nextSibling.className == "ib-colon" && this.innerHTML == oldsenseid;
					})
				}
				editor.addEdit({
					edit: function(wikitext) {
						wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "\\s?(\{\{senseid\\|*\\|))*"), "$1" + values.senseid);
						if (values.changematching) {
							var asd = wikitext.match('==' + tabbedLanguages + '==\n+?(\n==|$)');
							wikitext = wikitext.replace(asd, asd.replace(RegExp("\\{\\{(sense|trans-top)\\|" + oldsenseid + "\\}\\}", "g"), "{\{$1\|" + values.senseid + "}}"))
						}
						return ccc = wikitext
					},
					redo: function() {
						senseidform.style.display = "none";
						for (var i = 0; i < ttables.length; i++) {
							backups.push(document.createDocumentFragment());
							while (ttables.childNodes) {
								backups.appendChild(ttables.childNodes);
							}
							ttables.appendChild(document.createTextNode(values.senseid))
						}
						for (var i = 0; i < sensetemps.length; i++) {
							backups.push(document.createDocumentFragment());
							backups.appendChild(sensetemps.firstChild);
							sensetemps.appendChild(document.createTextNode(values.senseid))
						}
					},
					undo: function() {
						senseidform.style.display = "inline";
						for (var i = 0; i < ttables.length; i++) {
							ttables.removeChild(ttables.childNodes);
							ttables.appendChild(backups.shift())
						}
						for (var i = 0; i < sensetemps.length; i++) {
							sensetemps.removeChild(sensetemps.firstChild)
							sensetemps.appendChild(backups.shift())
						}
					},
					summary: "senseid: " + values.senseid
				})
			}
		}, qq, qq.childNodes)
		senseidform.firstChild.focus()
	})
}


function setupnymadder(qq, nymtype) {
	var passtheseheaders = "Usage notes|Inflection|Conjugation|Declension|Quotations",
		nymtypelist = 
	for (var x = 0; nymtypelist != nymtype; x++)
		passtheseheaders += "|" + nymtypelist;
	if (qq.parentNode.parentNode.nodeName.toLowerCase() == "li") qq = qq.parentNode.parentNode;
	var findnumberofheaders = findnumberofheaders_(qq)
	var findnumberofdefs = findnumberofdefs_(qq.parentNode.getElementsByTagName('li'))
	for (var findheaderlevel = qq.parentNode; !/^h\d$/i.test(findheaderlevel.nodeName); findheaderlevel = findheaderlevel.previousSibling);
	findheaderlevel = Number(findheaderlevel.nodeName.match(/\d/));
	var senseidencoded = 
	editor = new Editor()
	editor.withCurrentText(function(wikitext) {

		// Find nym header, or add it if it doesn't exist
		var qqq = qq.parentNode;

		while (!((qqq.className == "fakesubheader" || /h\d/i.test(qqq.nodeName)) && !qqq.innerHTML.match(passtheseheaders) || qqq.className == "printfooter" || qqq.className == "fakeheader" || qqq.className == "catlinks")) {
			qqq = qqq.nextSibling
		}
		if (!qqq.innerHTML.match(nymtype)) {
			qqq = qqq.parentNode.insertBefore(newNode('div', {
				'class': 'fakesubheader'
			}, newNode('h' + (findheaderlevel + 1), nymtype)), qqq);
		}
		// relevant vars: 
		//  findheaderlevel is the the headerlevel of the most recent header above the ol
		//  qq is still the li itself
		//  qqq is the (possibly newly added) nym header
		// find all relevant senseids, make an array of them, the whole template in each
		var senseid = wikitext.replace(
			RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + ")"), '').replace(/\n\n*$/, '').match(/\{\{senseid\|*\|*/g)

		if (!senseid) {
			alert("No glosses were found. Click \"Add gloss\" to attach a gloss to the definition before adding " + nymtype.toLowerCase() + ".");
			return
		}

		// run through senseids, checking for a corresponding span id'd nymtype-langcode-id, adding them encased in an li in a soon-to-be-parsed temp variable if not found, otherwise suppressing new form creation
		temp = ""
		var nymformexists = 
		for (var i = 0; i < senseid.length; i++) {
			if (document.getElementById(senseidencoded = nymtype + "-" + encodeURIComponent(senseid.split("|") + "-" + senseid.split("|")).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%/g, '.'))) {
				nymformexists = true
			} else {
				temp += "* {" + "{sense|" + senseid.split("|") + "}} <span id='" + nymtype + "-" + senseid.split("|") + "-" + senseid.split("|") + "'></span>\n"
			}

		}
		new mw.Api().parse(temp, {
					title: mw.config.get('wgPageName'), 
					pst: true, //pst makes subst work as expected
					disablelimitreport: true
				}).then(function(res) {
			var qqqq = newNode('span')
			qqqq.innerHTML = res
			qqqq = qqq.parentNode.insertBefore(qqqq.firstChild, qqq.nextSibling) // the ul containing the form-holder spans, right below the nym header
			for (var i = 0; i < senseid.length; i++) {
				if (!nymformexists) {
					setupnymadder2(i, senseid, wikitext)
				}
			}
			if (qqqq.getElementsByTagName && qqqq.getElementsByTagName('li').length == 0) {
				qqqq.parentNode.removeChild(qqqq)
			}
			scroll(0, jQuery(qqq).offset().top)
		});

	})

	function setupnymadder2(i, senseid, wikitext) {

		var nymtype2 = nymtype.slice(0, -1).toLowerCase()
		var x = document.getElementById(senseidencoded);

		var theform
		new AdderWrapper(editor, {
			'createForm': function() {
				return theform = newNode('form', {
					'style': 'display:inline;'
				}, newNode('input', {
					'name': 'nym'
				}), newNode('input', {
					'value': 'Add',
					'type': 'submit'
				}))
			},
			'fields': {
				'nym': util.validateNoWikisyntax(nymtype2, true)
			},
			'onsubmit': function(values, render) {
				theform.getElementsByTagName('input').value = ""
				var firstnym = !theform.parentNode.parentNode.getElementsByTagName('a')
				var addedwikitext = (firstnym ? '' : ', ') + "{" + "{l|" + senseid.split("|") + "|" + values.nym + "}}"
				render(addedwikitext, function(res2) {
					var nodeToInsert = newNode('span')
					nodeToInsert.innerHTML = res2
					editor.addEdit({
						edit: function(wikitext) {
							// unindent
							findnumberofdefs = findnumberofdefs_(qq.parentNode.getElementsByTagName('li'))

							if (wikitext.substr(wikitext.length - 1, 1) != "\n") {
								wikitext += "\n"
							}

							if (!wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + ")"), '').replace(RegExp("(\n(=|\\{\\{subst:=\\}\\})={" + (findheaderlevel - 1) + "}*$)"), '').match(RegExp(nymtype + "={" + findheaderlevel + "}"))) {
								wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "*?(\n(?=(\\{\\{subst:=\\}\\}|=)=+(?=)(?!(" + passtheseheaders + ")))|$))"), "$1{" + "{subst:=}}===" + (findheaderlevel == 4 ? "=" : "") + nymtype + (findheaderlevel == 4 ? "=" : "") + "====\n\n")
							}



							if (firstnym) {
								var passthesesenseids = ;
								for (var ii = 0; ii < i; ii++) {
									passthesesenseids.push("\\* \\{\\{sense\\|" + senseid.split("|") + "\\}\\}")
								}
								wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}" + findnumberofdefs + "*?=" + nymtype + "=+*?\n" + (passthesesenseids.length > 0 ? "(?!(" + passthesesenseids.join("|") + ")))" : ")")), "$1* {" + "{sense|" + senseid.split("|") + "}} " + addedwikitext + "\n")
							} else {
								wikitext = wikitext.replace(RegExp("(^*?((^|\n)=*?){" + findnumberofheaders + "}*?=" + nymtype + "=+*?\\{\\{sense\\|" + senseid.split("|") + "\\}\\}.*)"), "$1" + addedwikitext)
							}



							return ccc = wikitext;

						},
						redo: function() {
							theform.parentNode.parentNode.insertBefore(nodeToInsert, theform.parentNode)
						},
						undo: function() {
							theform.parentNode.parentNode.removeChild(nodeToInsert)
						},
						summary: "+" + nymtype2 + " ]"
					}, nodeToInsert)
				})
			}
		}, x)



		// sort the lis
		var passthesesenseids = ;
		for (var ii = 0; ii < i; ii++) {
			passthesesenseids.push(senseid.split("|"))
		}
		for (var xx = x.parentNode.parentNode.nextSibling; xx.nextSibling && !/h\d/i.test(xx.nodeName) && xx.className != "fakesubheader" && xx.nodeName.toUpperCase() != "UL"; xx = xx.nextSibling);
		if (xx.nodeName.toUpperCase() == "UL") {
			var xxx = xx.getElementsByTagName('li')
			for (var xxxx = xxx.length; xxxx--;) {
				var xxxxx = xxx.getElementsByTagName("span")
				if (xxxxx && xxxxx.innerHTML == senseid.split("|")) {
					x.parentNode.parentNode.removeChild(x.parentNode);
					xxx.appendChild(x);
					break;
				}
				if (xxxxx && passthesesenseids.length && RegExp(passthesesenseids.join("|")).test(xxxxx.innerHTML)) {
					xxx ? xx.insertBefore(x.parentNode, xxx) : xx.appendChild(x.parentNode);
					break;
				}
			}
			if (xxxx == -1) {
				xx.insertBefore(x.parentNode, xx.firstChild)
			}
		}

	}


}


jQuery(document).ready(function() {
	var disablebutton = document.getElementById('YRDefsideboxes-disable-button');
	if (disablebutton) {
		disablebutton.innerHTML = "";
		var toggle = newNode('span', {
			click: function() {
				if ($.cookie("DisableYREdit")) {
					$.cookie("DisableYREdit", null, {
						path: "/"
					})
					toggle.innerHTML = "Disable definition editing options."
				} else {
					$.cookie("DisableYREdit", 1, {
						expires: 30,
						path: "/"
					})
					toggle.innerHTML = "Enable definition editing options."
				}
			}
		}, ($.cookie("DisableYREdit") ? "Enable" : "Disable") + " definition editing options.")
		disablebutton.appendChild(toggle);
	}
	if (mw.config.get('wgAction') == 'view' && (mw.config.get('wgNamespaceNumber') == 0 || mw.config.get('wgPageName') == "Wiktionary:Sandbox") && !/&printable=yes|&diff=|&oldid=/.test(window.location.search) && !$.cookie("DisableYREdit") && !window.DisableYREdit && !window.loadedYREdit) {
		window.loadedYREdit = true;
		for (var ols = document.getElementsByTagName('ol'), ii = 0; ii < ols.length; ii++) {
			if (ols.className != "references") {
				for (var lis = ols.getElementsByTagName('li'), i = 0; i < lis.length; i++) {
					if (lis.parentNode == ols && ols.parentNode.parentNode.nodeName != "UL") makedefsidebox(lis);
				}
			}
		}

		mw.util.addPortletLink('p-tb', 'javascript:addPOSHeader()', 'Add part of speech');
		defsidebuttons = 
		defeditoptions = {
			addingPOS: false
		}
	}
})

// </nowiki>