Szerkesztő:Nyenyec/nyenyeclib.js

A Wikipédiából, a szabad enciklopédiából

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Internet Explorer / Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
  • Opera: Nyomj Ctrl–F5-öt
//  Generates the box element containing the spec chars.
function createSpecCharBox() {
    var boxDiv = document.createElement("div");
    boxDiv.setAttribute('id', 'editMenu');
    // boxDiv.setAttribute('id', 'customBar');
    // boxDiv.setAttribute('style', 'margin-top:5px;border:1px solid #aaaaaa;padding:3px');

    var html = '<a href="http://hu.wikipedia.org/wiki/Wikipédia:Különleges_karakterek"' +
    ' title="Wikipédia:Különleges karakterek">Különleges karakterek:</a>:' +
    "<a href=\"javascript:insertTags('„','','')\">„</a> ·" +
    "<a href=\"javascript:insertTags('”','','')\">“</a> ·" +
    "<a href=\"javascript:insertTags('–','','')\">– <small>(gondolatjel)</small></a> ·" +
    "<a href=\"javascript:insertTags('„','”','')\">„”</a> ·" +
    "<a href=\"javascript:insertTags('»','«','')\">»«</a> ·" +
    "<a href=\"javascript:insertTags('²','','')\">²</a> " +
    "<a href=\"javascript:insertTags('³','','')\">³</a> " +
    "<a href=\"javascript:insertTags('½','','')\">½</a> ·" +
    "<a href=\"javascript:insertTags('€','','')\">€</a> ·" +
    "<a href=\"javascript:insertTags('í','','')\">í</a> ·" +
    "<a href=\"javascript:insertTags('[[',']]','')\">[[]]</a> " +
    "<a href=\"javascript:insertTags('|','','')\">|</a> " +
    "<a href=\"javascript:insertTags('{'+'{','}}','')\">{{}}</a> ·" +
    "<a href=\"javascript:insertTags('{'+'{en}}','','')\"><small>angol link</small></a> ·" +
    "<a href=\"javascript:insertTags('{'+'{' + 'torles}}','','')\"><small>törlésre javasolt</small></a> ·" +
    "<a href=\"javascript:insertTags('--\176\176\176\176','','')\"><small>aláírás</small></a> ·" +
    "<a href=\"javascript:translateInfoboxCountryEnHu()\"><small>ország</small></a> ·" +
    "<a href=\"javascript:fixLatin1Chars()\"><small>kalapos</small></a> ·" +
    "<a href=\"javascript:fixHungarianQuotes()\"><small>idézőjel</small></a> ·" +
    "<a href=\"javascript:fixExternalLinksSectionTitle()\"><small>külső</small></a> ·" +
    "<a href=\"javascript:translateDatesEnHu()\"><small>dátum</small></a> ·" +
    "<a href=\"javascript:insertCustomForm(customReplaceForm())\"><small>egyedi</small></a>"
    "</div>"; 

   return boxDiv;
}

function replaceRegexp(replaceWhat, replaceWith, modifiers) {
        if (modifiers == null) {
		modifiers = "";
	}
	var txtarea = document.editform.wpTextbox1;
	// IE
	if(document.selection  && !is_gecko) {
		var theSelection = document.selection.createRange().text;		
		txtarea.focus();
		theSelection = theSelection.replace(replaceWhat, replaceWith);
		document.selection.createRange().text = theSelection;
	// Mozilla
	} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
                // This is probably more complicated than it needs to be
 		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		var scrollTop=txtarea.scrollTop;

		var pattern = new RegExp(replaceWhat, modifiers);
		var myText = (txtarea.value).replace(pattern, replaceWith);

		txtarea.value = myText;		

		txtarea.focus();

		var cPos=startPos;
		txtarea.selectionStart=cPos;
		txtarea.selectionEnd=cPos;
		txtarea.scrollTop=scrollTop;

	// All others
	} else {
		alert("No support for this browser yet");
		return;
	}
	// reposition cursor if possible
	if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}

// Replaces Latin 1 chars with properly encoded Hungarian Latin 2 equivalents
function fixLatin1Chars() {	
	replaceRegexp("Õ", "\u0150", "g");
	replaceRegexp("Û", "Ű", "g");
	replaceRegexp("õ", "ő", "g");
        replaceRegexp("&#337;", "ő", "g");
	replaceRegexp("&#369;", "ű", "g");
	replaceRegexp("û", "ű", "g");
}


// Replaces English style "" quotes with Hungarian „”
function fixHungarianQuotes() {
	replaceRegexp("\"([^\"]*)\"", "„$1”", "mg");
}

// Replaces English style "" quotes with Hungarian „”
function fixExternalLinksSectionTitle() {
	replaceRegexp("=\\s*Külső linkek\\s*=", "=Külső hivatkozások=", "mg");
}

// Replace all occurences of a user-entered regexp with a user entered replacement
function customReplace() {
	var what = prompt('Cseréld ezt:');
	if (what != null) {
		var withWhat = prompt('Cseréld ezt: "' + what + '", erre:');
		if (withWhat != null) {
			replaceRegexp(what, withWhat, "gm");
		}
	}
}

// Translate dates from English format to Hungarian
// Currently it only handles linkified dates
function translateDatesEnHu() {
	var months = [
		["January", "január"],
		["February", "február"],
		["March", "március"],
		["April", "április"],
		["May", "május"],
		["June", "június"],
		["July", "július"],
		["August", "augusztus"],	
		["September", "szeptember"],
		["October", "október"],
		["November", "november"],
		["December", "december"]
	];

	for (var i = 0; i < months.length; i++) {
		var enMonth = months[i][0];
		var huMonth = months[i][1];
		// alert("Replacing " + enMonths + " with " + huMonth);
		// Replace "[[November 15]], [[2005]]" with "[[2005]]. [[november 15]]."
		// $1 = "15", $2 = "2005"
		replaceRegexp("\\[\\[" + enMonth + " (\\d+)\\]\\],?\\s*\\[\\[(\\d{4})\\]\\]", "[[$2]]. [[" + huMonth + " $1]].", "gm");
	}
}

// Translates an English country infobox to Hungarian
function translateInfoboxCountryEnHu() {
	var dict = [
		["Infobox Country", "Országtáblázat"],	
		["Infobox_Country", "Országtáblázat"],
		["native_name", "teljesnév"],		
		["image_flag", "zászlókép"],
		["image_coat", "címerkép"],
		["image_map", "elhelyezkedéskép"],
		["national_motto", "mottó"],
		["national_anthem", "himnusz"],
		["official_languages", "hivatalos_nyelvek"],
		["capital", "főváros"],
		["capitals_coordinates.*\$", ""],
		["government_type", "államforma"],
		["leader_titles", "államfő"],
		["leader_names", "jelenlegiállamfő"],
		["largest_city", "legnagyobbváros"],
		["area", "terület"],
		["area_rank", "területrangsorban"],
		["area_magnitude.*\$", ""],
		["percent_water", "víz"],
		["population_estimate", "népesség"],
		["population_estimate_year", "népesség_dátum"],
		["population_estimate_rank", "népességrangsorban"],
		["population_census.*\$", ""],
		["population_census_year.*\$", ""],
		["population_density", "népsűrűség"],
		["population_density_rank", "népsűrűségrangsorban"],
		["GDP_PPP_year", "GDP_dátum"],
		["GDP_PPP", "GDP"],
		["GDP_PPP_rank", "GDPrangsorban"],
		["GDP_PPP_per_capita", "egyfőrejutóGDP"],
		["GDP_PPP_per_capita_rank", "egyfőrejutóGDPrangsorban"],
		["sovereignty_type.*\$", ""],
		["established_events", "függetlenségesemény"],
		["established_dates", "függetlenségdátuma"],
		["currency", "pénznem"],
		["currency_code", "pénznemrövidítés"],
		["time_zone", "időzóna"],
		["utc_offset.*\$", ""],
		["time_zone_DST", "NYISZ"],
		["utc_offset_DST", ""],
		["cctld", "tld"],
		["calling_code", "hívókód"],
		["footnotes", "lábjegyzet"],
		["Federal republic", "szövetségi köztársaság"],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["", ""],
		["Declared", "kikiáltása"], 
		["Recognised", "elismerése"], 
		["English language", "angol nyelv"], 
		["French language", "francia nyelv"], 
		["Spanish language", "spanyol nyelv"], 
		["German language", "német nyelv"], 
		["million", "millió"]
	];

	for (var i = 0; i < dict.length; i++) {
		var pair = dict[i];
		replaceRegexp(pair[0], pair[1]);
	}

        // In Hungarian, we use &nbsp; for separating digits instead of ,
        replaceRegexp("(\\d+?),(\\d+?)", "$1&nbsp;$2", "g");
	// Decimal separator "." -> ","
	replaceRegexp("(\\d+?)\\.(\\d+?)", "$1,$2", "g");

	// In rankings, get rid of "st", "th", etc.
	replaceRegexp("(\\d+?)st", "$1", "g");
	replaceRegexp("(\\d+?)nd", "$1", "g");
	replaceRegexp("(\\d+?)rd", "$1", "g");
	replaceRegexp("(\\d+?)th", "$1", "g");

	// Get rid of $ prefix in GDP
	replaceRegexp("\\$(\\d+?)", "$1", "g")


        // Get rid of whitespace before "="
        replaceRegexp("(\\s+)=", " =", "g");

        translateDatesEnHu();
}

// Replace all occurences of a user-entered regexp with a user entered replacement
function customReplaceForm() {
  var form =
    'Cseréld ezt a reguláris kifejezést: <input id="customReplaceThis" type="text" size="40"> ' +
    'erre: <input id="customReplaceWith" type="text" size="40"> ' +
    '<input type="submit" value="Csere" onClick="javascript:performCustomReplace()">';
  return form;
}

function performCustomReplace() {
  var replaceThis = document.getElementById('customReplaceThis');
  var replaceWith = document.getElementById('customReplaceWith');
  replaceRegexp(replaceThis.value, replaceWith.value, "gm");
  deleteCustomForm();
}

function insertCustomForm(customForm) {
  var customBar = document.getElementById('editMenu');
  if (customBar == null) return;

  var replaceForm = document.createElement('div');
  replaceForm.setAttribute('id', 'customForm');
  replaceForm.setAttribute('style', 'margin-top:5px;border:1px solid #aaaaaa;padding:3px;text-align:center');
  replaceForm.innerHTML = 
    '<img src="http://upload.wikimedia.org/wikipedia/hu/b/bd/Close.png" align="right" ' +
    'style="margin:2px" onClick="javascript:deleteCustomForm()">' +
    customForm;
  
  var oldForm = document.getElementById('customForm');
  if (oldForm != null) {
    customBar.parentNode.replaceChild(replaceForm, oldForm);
  } else {
    customBar.parentNode.insertBefore(replaceForm, customBar);
  }
}

function deleteCustomForm() {
  var replaceForm = document.getElementById('customForm');
  if (replaceForm != null)
    replaceForm.parentNode.removeChild(replaceForm);
}

// Initializes edit box
function myOnloadHook() {
  // Textarea positioning doesn't work in Opera
  if (is_opera) return;

  // Find the element that comes right after the special character box
  var copywarn = document.getElementById('editpage-copywarn');
  if (copywarn == null) {
      // Not in edit mode
      return;
  }
  var specCharBox = createSpecCharBox();
  var par = copywarn.parentNode;

  par.insertBefore(specCharBox, copywarn);
  
  initjsDOMenu();
}

if (window.addEventListener) window.addEventListener("load", myOnloadHook, false);
else if (window.attachEvent) window.attachEvent("onload", myOnloadHook);