User:Dunee/modern.js

function createSpecCharBox { var boxDiv = document.createElement("div");

var innerText = 'Különleges karakterek::' + "„ ·" + "“ ·" + "– (gondolatjel)  ·" + "„” ·" + "»« ·" + "² " + "³</a> " + "½</a> ·" + "€</a> ·" + "í</a> ·" + "</a> " + "|</a> " + " – </a> ·" + " kalapos </a> ·" + " idézőjel </a> ·" + " ";

boxDiv.innerHTML = innerText; 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("ő", "ő", "g"); replaceRegexp("ű", "ű", "g"); replaceRegexp("ű", "ű", "g"); }

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

// 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  for separating digits instead of , replaceRegexp("(\\d+?),(\\d+?)", "$1 $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; }

// 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); }

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