User:Gausie/newentrywizard-yi.js

// todo: clean, jQuerize, use langmetadata, let users extend this /* jshint sub:true, shadow:true, undef:true, unused:true, strict:true, forin:true, latedef:true */ /* global jQuery */ //

const elementId = "gausie-newentrywizard-yi";

var necdata = { pos: "noun", pos2: "Noun" }; var necdefs = [ ['', [],		[]	] ]; var necpost = [];

for (var i = 5; i <= 19; ++i) { necpost[i] = []; }

var neccode = 'yi'; var necpostlangtext = [];

var title = mw.config.get('wgTitle');

var necinfls = { noun: [, ['Gender', , [ ['masculine', '|g=m'], ['feminine', '|g=f'], ['neutral', '|g=n'] ]]]	};

/*

Notes: necfunction fills in the edit box necfunction2 creates the main menu stuff inside the span necfunction3 doesn't exist necfunction4 goes to necfunction5 (don't remember what this was for) necfunction5 creates the inflections options by filling in necinfls necfunction6 does some extra junk for the infl options input boxes necdefupdate makes the definitions/example sentence options necpostbox makes the extra junk ("More details") work (i think)

The necinfls object works like this: The first part is the stuff that comes at the beginning of the template, the second is the stuff at the end, the third onward are the available parameters of the template and what stuff they produce. Each template parameter is an array, which contains the word that shows up at the beginning of the section, then a blank value, and then subarrays of each option. Each subarray contains the text that shows up in the editor, followed by the text that shows up in the textbox (the wikimarkup). Some onclick javascript can be added to an option as the third parameter in the array. If the option is an input box, the first parameter should be "input", followed by the editor text (DON'T leave this blank or the whole thing will blow up), followed by the pre-inputbox-value wikimarkup, followed by post-inputbox-value wikimarkup, followed by any extra js.



var necetym; var necpron; var necheadingorder = ['Usage notes', 'Inflection', 'Conjugation', 'Declension', 'Quotations', 'Synonyms', 'Antonyms', 'Hypernyms', 'Hyponyms', 'Meronyms', 'Holonyms', 'Derived terms', 'Related terms', 'Coordinate terms', 'Descendants', 'Translations', 'See also', 'External links', 'Categories', 'Images']; var necinputadvanced = ""; var necposlist = ['Noun', 'Verb', 'Adjective', 'Adverb', 'Pronoun', 'Conjunction', 'Interjection', 'Preposition', 'Proper noun', 'Article', 'Prepositional phrase', 'Contraction', 'Prefix', 'Suffix', 'Symbol', 'Letter', 'Idiom', 'Phrase'];

function necfunction2 { /* CREATE OPTIONS */ var x = "Language code: <input type=text value='en' id='necinput' onKeyUp='neccode=this.value;necfunction;necfunction4;necfunction' onblur=if (necCleanLangCode(this.value)){this.value=necCleanLangCode(this.value)};neccode=this.value;document.getElementById('nectransspan').style.display=((this.value=='en')?:'none');if (/^[a-z]{2,3}(-[a-z\-]{1,7})?$/.test(this.value)){document.getElementById('neclangerror').style.display='none'}else{document.getElementById('neclangerror').style.display=};necfunction;necfunction4;necfunction;necdefupdate title='The two or three letter ISO-639 language code'> ERROR: INVALID LANGUAGE CODE Part of speech: ";

for (var i = 0; i < 4; ++i) { x += "" + necposlist[i] + ", "; }

x += " Other: Select ";

for (var i = 0; i < necposlist.length; ++i) { if (i > 3) { x += " " + necposlist[i] + " "; }	}

x += "  More details: Usage notes, Synonyms, Translations, More: Select ";

for (var i = 0; i < necheadingorder.length; ++i) { if (i != 0 && i != 5 && i != 15) { x += "" + necheadingorder[i] + " "; }	}

x += " Definition:   Further information: Another definition</a>,  <a href=javascript: id=necetymbutton onclick=document.getElementById('necetymspan').style.display=;necetym=document.getElementById('necetyminput').value;necfunction;this.style.fontWeight='bold' title='Add etymology section'>Etymology</a>, <a href=javascript: id=necpronbutton onclick=document.getElementById('necpronspan').style.display=;necpron=document.getElementById('necproninput').value;necfunction;this.style.fontWeight='bold' title='Add pronunciation section'>Pronunciation</a>. Etymology: <a href=javascript: onclick=necetym=undefined;document.getElementById('necetymspan').style.display='none';necfunction;document.getElementById('necetymbutton').style.fontWeight= title='Delete etymology section'>(delete)</a> <textarea id=necetyminput onKeyUp=necetym=this.value;necfunction>  Pronunciation: <a href=javascript: onclick=necpron=undefined;document.getElementById('necpronspan').style.display='none';necfunction;document.getElementById('necpronbutton').style.fontWeight='' title='Delete pronunciation section'>(delete)</a> <textarea id=necproninput onKeyUp=necpron=this.value;necfunction> <a href=/w/index.php?title=User_talk:Gausie/newentrywizard-yi.js&action=edit&section=new title='Give feedback'>Give feedback</a> ";

document.getElementById("editform").insertBefore(document.getElementById(elementId), document.getElementById("editform").firstChild); document.getElementById(elementId).innerHTML = x;

if (document.URL.match("&section=new")) { document.getElementById("wpSummaryLabel").parentNode.removeChild(document.getElementById("wpSummaryLabel")); document.getElementById("wpSummary").parentNode.removeChild(document.getElementById("wpSummary")); } }

// Fill in the edit box. function necfunction { var k = "";

if (document.URL.match("&section=new")) { k += "\n\n"; } else { var neceditsummary = "(NEC) +" + neccode + ":" + necdata['pos'] + ": "; //edit summary

for (var i = 0; i < necdefs.length; ++i) { neceditsummary += ((i != 0) ? ', ' : '') + necdefs[i][0]; }

document.getElementById("wpSummary").value = neceditsummary; }

k += "==getByCode==";

for (var i = 0; i < necpost[19].length; ++i) { k += "\n"; }

k += "\n\n";

if (necetym != undefined) { k += "===Etymology===\n" + necetym + "\n\n"; }

if (necpron != undefined) { k += "===Pronunciation===\n" + necpron + "\n\n"; }

k += "===" + necdata['pos2'] + "===\n";

if (neccode != '' && necinfls && necinfls[necdata['pos']] && necinfls[necdata['pos']][2]) { if (necdata[neccode + "-" + necdata['pos'] + "2"] != "Advanced") { if (necinfls[necdata['pos']][0] != undefined) { k += necinfls[necdata['pos']][0]; }

var x = necinfls[necdata['pos']];

for (var z = 0; z < x.length; ++z) { if (z <= 1) { continue; }

var zz = neccode + "-" + necdata['pos'] + z;

for (var y = 0; y < x[z][2].length; ++y) // search for inflections {					if (x[z][2][y][0] != "input" && necdata[zz] == x[z][2][y][0]) // is selected option, not input box {						k += x[z][2][y][1]; break; }

if (x[z][2][y][0] == "input" && necfunction7(x[z][2], necdata[zz]) == false) { k += x[z][2][y][2] + necdata[zz]; }				}			}

if (necinfls[necdata['pos']][1] != undefined) { k += necinfls[necdata['pos']][1]; }		} else { k += necinputadvanced; }	} else { if (necinputadvanced) { k += necinputadvanced; } else { if (neccode != '' && necinfls && necinfls[necdata['pos']]) { k += necinfls[necdata['pos']][0];

k += necinfls[necdata['pos']][1]; } else { k += ''; }		}	}

k += "\n";

for (var i = 0; i < necdefs.length; ++i) { k += "\n# " + necdefs[i][0];

for (var l = 0; l < necdefs[i][1].length; ++l) { k += "\n#:" + necdefs[i][1][l][0].replace(new RegExp("(" + title + ")", "ig"), "$1") + "";

if (neccode != "en" && necdefs[i][1][l][1] && (new LangMetadata).guessScript(neccode) != 'Latn') { k += "\n#::" + necdefs[i][1][l][1] + ""; }

if (neccode != "en") { k += "\n#::" + necdefs[i][1][l][2] + ""; }		}

for (var l = 0; l < necdefs[i][2].length; ++l) { k += "\n#*" + necdefs[i][2][l][0] + ", " + necdefs[i][2][l][1] + ", " + necdefs[i][2][l][2] + "";

if (necdefs[i][2][l][3]) { k += ", " + necdefs[i][2][l][3]; }

if (necdefs[i][2][l][4]) { k += ", page";

if (necdefs[i][2][l][4].match(/(-|–)/)) { k += "s"; }

k += " " + necdefs[i][2][l][4]; }

k += "\n#*:"; k += necdefs[i][2][l][5].replace(new RegExp("(" + title + ")", "ig"), "$1");

if (neccode != "en") { k += "\n#*::" + necdefs[i][2][l][6]; }		}	}

/* SUBHEADERS */ for (var o = 0; o <= 3; ++o) { if (necpost[o] != undefined) { k += "\n\n====" + necheadingorder[o] + "====\n" + necpost[o]; }	}

if (necpost[4] != undefined) { k += "\n\n====Quotations====\n" + necpost[4]; }

for (var o = 5; o <= 17; ++o) { if (necpost[o][0] != undefined) { k += "\n\n====" + necheadingorder[o] + "====" }

if (o < 11 || o == 13) { for (var i = 0; i < necpost[o].length; ++i) { k += "\n* ";

for (var u = 0; u < necpost[o][i].length; ++u) { if (u != 0) { if (u != 1) { k += ", "; }

k += ""; }				}			}		} else if (o == 14) { for (var i = 0; i < necpost[o].length; ++i) { k += "\n* getByCode: "; }		} else if (o == 15) { for (var i = 0; i < necpost[15].length; ++i) { k += "\n\n\n"; }		} else if (o == 16 || o == 17) { for (var i = 0; i < necpost[o].length; ++i) { k += "\n* " + necpost[o][i]; }		} else { for (var i = 0; i < necpost[o].length; ++i) { k += "\n* "; }		}	}

for (var i = 0; i < necpost[18].length; ++i) { k += "\n"; }

$(document.editform.wpTextbox1).val(k); }

function necCleanLangCode(lang) // taken from wt:edit {	return null; }

function necfunction4 { if (!neccode) { neccode = ''; }

if (neccode && necinfls && necinfls[necdata['pos']] != undefined && necinfls[necdata['pos']][2] != undefined) { necfunction5(necinfls[necdata['pos']]); } else { var qq = neccode + "-" + necdata['pos'] + '2'; var xx = "<span class=msgfornonnewbies ";

if (necinputadvanced) { xx += "style='font-weight:bold' "; }

xx += "> Wikicode: <input type=text value='" + necinputadvanced + "' onKeyUp=\"necinputadvanced=this.value;if (this.value){this.parentNode.style.fontWeight='bold'}else{this.parentNode.style.fontWeight=''};necfunction\" /> "; document.getElementById("necinfls").innerHTML = xx; necfunction; } }

function necfunction5(a) { /* INFLECTION OPTIONS */

var q = ""; for (var r = 0; r < a.length; ++r) { if (r <= 1) { continue; }		var qq = neccode + "-" + necdata['pos'] + r;		if (necdata[qq] == undefined) { if (a[r][2][0][0] == 'input') { necdata[qq] = '' } else { necdata[qq] = a[r][2][0][0] }		}		q += " " + a[r][0] + ": ";

for (var i = 0; i < a[r][2].length; ++i) { if (a[r][2][i][0] != 'input') { q += "<a href=javascript: id='necinput" + qq + a[r][2][i][0] + "' onclick=\"";				if (a[r][2][i][2]) {					q += a[r][2][i][2] + ";"				}				q += "necdata[\'" + qq + "\']=\'" + a[r][2][i][0] + "\';necfunction4;necfunction\">" + a[r][2][i][0] + "</a>"; if (i != a[r][2].length - 1) { q += ", " }			} else { q += "<span id='necinput" + qq; if (necdata[qq] != "Advanced" && necfunction7(a[r][2], necdata[qq]) == false) { q += necdata[qq] }				q += "'>" + a[r][2][i][1] + "<input type=text value='' id='"; q += neccode + "-" + necdata['pos'] + "-" + r + "-" + i;				q += "' onKeyUp="; if (a[r][2][i][4]) { q += a[r][2][i][4] + ";" }

q += "necfunction6('" + qq + "','" + neccode + "-" + necdata['pos'] + "-" + r + "-" + i + "');";

q += "necfunction /> "; if (i != a[r][2].length - 1) { q += ", " }			}		}

/* ADVANCED OPTIONS */ if (r == 2) { q += "<span id='necinput" + qq + "Advanced' class=msgfornonnewbies>, Wikicode: <input type=text value='" + necinputadvanced + "' onKeyUp=necinputadvanced=this.value;document.getElementById('necinput" + qq + "'+necdata['" + qq + "']).style.fontWeight='';necdata['" + qq + "']='Advanced';document.getElementById('necinput" + qq + "'+necdata['" + qq + "']).style.fontWeight='bold';necfunction /> "; }	}

document.getElementById("necinfls").innerHTML = q;

for (var r = 0; r < a.length; ++r) { if (r <= 1) { continue; }

var qq = neccode + "-" + necdata['pos'] + r;		document.getElementById('necinput' + qq + necdata[qq]).style.fontWeight = 'bold';

if (document.getElementById('necinput' + qq + necdata[qq]).childNodes[1] && necdata[qq] != 'Advanced' && necfunction7(a[r][2], necdata[qq]) == false) { document.getElementById('necinput' + qq + necdata[qq]).childNodes[1].value = necdata[qq]; }	} }

function necdefupdate { /* DEFINITIONS */ var def = ""; for (var i = 0; i < necdefs.length; ++i) { def += "Definition: <input size=50 type=text value='" + necdefs[i][0] + "' onKeyUp=necdefs[" + i + "][0]=this.value;necfunction />"; if (i > 0) { def += "<a href=javascript:necdefs.splice(" + i + ",1);necdefupdate;necfunction title='Delete this definition'>(–)</a>"; }		def += "<a href=javascript:necdefs[" + i + "][1].push([,,]);necdefupdate;necfunction title='Add example sentence'>(+example sentence)</a><a href=javascript:necdefs[" + i + "][2].push([,,,,,,]);necdefupdate;necfunction title='Add quotation'>(+quotation)</a>"; for (var l = 0; l < necdefs[i][1].length; ++l) // Example sentences {			def += " Example sentence: <input type=text size=40 value='" + necdefs[i][1][l][0] + "' onKeyUp=necdefs[" + i + "][1][" + l + "][0]=this.value;necfunction /><a href=javascript:necdefs[" + i + "][1].splice(" + l + ",1);necdefupdate;necfunction title='Delete this example sentence'>(–)</a>"; if (neccode != "en") { if ((new LangMetadata).guessScript(neccode) != 'Latn') { def += " Transliteration: <input type=text size=40 value='" + necdefs[i][1][l][1] + "' onKeyUp=necdefs[" + i + "][1][" + l + "][1]=this.value;necfunction />"; }				def += " Translation: <input type=text size=40 value='" + necdefs[i][1][l][2] + "' onKeyUp=necdefs[" + i + "][1][" + l + "][2]=this.value;necfunction />"; }		}		for (var l = 0; l < necdefs[i][2].length; ++l) // Quotations {			var x = ['Year', 'Author', 'Source title', 'Publisher', 'Page(s)']; var z = [4, 20, 20, 20, 5]; //sizes def += " "; for (var y = 0; y < x.length; ++y) { def += x[y] + ": <input type=text size=" + z[y] + " value='" + necdefs[i][2][l][y] + "' onKeyUp=necdefs[" + i + "][2][" + l + "][" + y + "]=this.value;necfunction /> " }			def += " Quotation: <input type=text size=40 value='" + necdefs[i][2][l][5] + "' onKeyUp=necdefs[" + i + "][2][" + l + "][5]=this.value;necfunction /><a href=javascript:necdefs[" + i + "][2].splice(" + l + ",1);necdefupdate;necfunction title='Delete this quotation'>(–)</a>"; if (neccode != "en") { def += " Translation: <input type=text size=40 value='" + necdefs[i][2][l][6] + "' onKeyUp=necdefs[" + i + "][2][" + l + "][6]=this.value;necfunction />" }		}		def += " "; }	document.getElementById('necdefs').innerHTML = def; }

function necpostbox(q) { if (q != undefined) { if ((q > 5 && q <= 10) || q == 13 || q == 14 || q == 19) { necpost[q][necpost[q].length] = [, ] } else if ((q > 10 && q < 13) || q > 15) { necpost[q][necpost[q].length] = '' } else { necpost[q] = '' }	}	var m = "";

/* USAGE NOTES, INFLECTION TABLES */ for (var o = 0; o <= 4; o++) { if (necpost[o] != undefined) { m += " " + necheadingorder[o] + ": <a href=javascript:necpost[" + o + "]=undefined;"; if (!o) { m += "document.getElementById('necquotbutton').style.fontWeight='';"; }			m += "necpostbox;necfunction title='Delete section'>(delete)</a> <textarea onKeyUp=necpost[" + o + "]=this.value;necfunction>" + necpost[o] + "  "; }	}	/* NYMS */ for (o = 5; o < 14; o++) { if (necpost[o][0] != undefined) { m += " " + necheadingorder[o] + ": <a id=nec" + necheadingorder[o] + "button href=javascript:necpost[" + o + "][necpost[" + o + "].length]=[,];necpostbox;necfunction title='add section'>(add section)</a>  " } else if (o == 5) { document.getElementById('necSynonymsbutton').style.fontWeight = '' }

for (var i = 0; i < necpost[o].length; ++i) { m += " Gloss: <input type=text value='" + necpost[o][i][0] + "' onKeyUp=necpost[" + o + "][" + i + "][0]=this.value;necfunction /> " + necheadingorder[o] + ": "; for (var u = 0; u < necpost[o][i].length; ++u) { if (u != 0) { if (u != 1) { m += ", "; }					m += "<input type=text size=5 value='" + necpost[o][i][u] + "' onKeyUp=necpost[" + o + "][" + i + "][" + u + "]=this.value;necfunction />"; }			}			m += "<a href=javascript:necpost[" + o + "][" + i + "].push('');necpostbox;necfunction title='Add " + necheadingorder[o].substr(0, necheadingorder[o].length - 1).toLowerCase + "'>(+)</a>"; if (necpost[o][i].length > 2) { m += "<a href=javascript:necpost[" + o + "][" + i + "].splice(" + (necpost[o][i].length - 1) + ",1);necpostbox;necfunction title='Delete " + necheadingorder[o].substr(0, necheadingorder[o].length - 1).toLowerCase + "'>(–)</a>" }			m += "<a href=javascript:necpost[" + o + "].splice(" + i + ",1);necpostbox;necfunction title='Remove section'>(remove section)</a> "; }		if (o == 10) { o = 12 }	}

/* DERIVED TERMS, RELATED TERMS, SEE ALSO, EXTERNAL LINKS */ for (o = 11; o <= 17; o++) { if (necpost[o][0] != undefined) { m += " " + necheadingorder[o] + ": <a href=javascript:necpost[" + o + "].push('');necpostbox;necfunction>(new)</a> "; }

for (var i = 0; i < necpost[o].length; ++i) { m += " <input type=text value='" + necpost[o][i] + "' onKeyUp=necpost[" + o + "][" + i + "]=this.value;necfunction /><a href=javascript:necpost[" + o + "].splice(" + i + ",1);necpostbox;necfunction title='Delete'>(–)</a> " }		if (o == 12) { o = 15 }	}

/* DESCENDANTS */

if (necpost[14][0] != undefined) { m += " " + necheadingorder[14] + ": <a href=javascript:necpost[14].push([,]);necpostbox;necfunction title='Add new descendant'>(new)</a> "; }

for (var i = 0; i < necpost[14].length; ++i) { m += " Language: <input type=text value='" + necpost[14][i][0] + "' onKeyUp=necpost[14][" + i + "][0]=this.value;necfunction onblur=if (necCleanLangCode(this.value)){this.value=necCleanLangCode(this.value)};necpost[14][" + i + "][0]=this.value;necfunction /> Word: <input type=text value='" + necpost[14][i][1] + "' onKeyUp=necpost[14][" + i + "][1]=this.value;necfunction /><a href=javascript:necpost[14].splice(" + i + ",1);necpostbox;necfunction title='Delete'>(–)</a> " }

/* TRANSLATIONS */ if (necpost[15][0] != undefined) { m += " Translations section: <a href=javascript:necpost[15].push('');necpostbox;necfunction title='Add translations section'>(add section)</a> " } else { document.getElementById('nectransbutton').style.fontWeight = '' }	for (var i = 0; i < necpost[15].length; ++i) { m += " Gloss: <input type=text value='" + necpost[15][i] + "' onKeyUp=necpost[15][" + i + "]=this.value;necfunction /><a href=javascript:necpost[15].splice(" + i + ",1);necpostbox;necfunction title='Delete'>(–)</a> " }

if (necpost[18][0] != undefined) { for (var i = 0; i < necpost[18].length; ++i) { m += " Category:<input type=text value='" + necpost[18][i] + "' onKeyUp=necpost[18][" + i + "]=this.value;necfunction /><a href=javascript:necpost[18].splice(" + i + ",1);necpostbox;necfunction title='Remove category'>(–)</a>"; if (i == 0) { m += "<a href=javascript:necpost[18].push('');necpostbox;necfunction title='Add new category'>(+new category)</a>" }			m += " " }	}

if (necpost[19][0] != undefined) { for (var i = 0; i < necpost[19].length; ++i) { m += " File name:<input type=text value='" + necpost[19][i][0] + "' onKeyUp=necpost[19][" + i + "][0]=this.value;necfunction /> Caption:<input type=text value='" + necpost[19][i][1] + "' onKeyUp=necpost[19][" + i + "][1]=this.value;necfunction /><a href=javascript:necpost[19].splice(" + i + ",1);necpostbox;necfunction title='Remove image'>(–)</a>"; if (i == 0) { m += "<a href=javascript:necpost[19].push([,]);necpostbox;necfunction title='Add new image'>(+new image)</a>" }			m += " " }	}

document.getElementById('necpostbox').innerHTML = m; }

function necfunction6(cc, dd) { document.getElementById('necinput' + cc + necdata[cc]).style.fontWeight = ''; necdata[cc] = document.getElementById(dd).value; document.getElementById(dd).parentNode.setAttribute('ID', 'necinput' + cc + document.getElementById(dd).value); document.getElementById('necinput' + cc + necdata[cc]).style.fontWeight = 'bold'; }

function necfunction7(qw, er) { var qwe = false;

for (var ty in qw) { if (er == qw[ty][0]) { qwe = true; }	}

return qwe; }

jQuery(document).ready(function necload {	if (document.getElementById(elementId)) {		necfunction2;		necdefupdate;		necfunction;		necfunction4;		necfunction;	} });

//