User:AlefZet/wikificator.js
Wikipedia дан
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.
/* See also [[MediaWiki:Monobook.js]] // ЕСКЕРТУ! Әмірді өзгерткенде [[Wikipedia:Уикилендіргіш]] бетіне анықтамасын енгізу ұмытпаңыз. <pre><nowiki> Insert code of templates per fall menue (idea from [[:he:MediaWiki:Summary]]) */ // TODO: recheck inventory of templates var tpl = { // "<TEMPLATE-ID>" : ["<LEFT>", "<CONTENT>", "<RIGHT>", "<SHOWN TEXT>"], "wikify" : ["{"+"{wikify", "", "}}", "Уикилендіру керек"], "stub" : ["{"+"{stub", "", "}}", "Бітеме"], "todo" : ["{"+"{Пішім|", "пішімдеу", "}}", "Пішім"], "delete" : ["{"+"{Db|", "себебі", "}}", "Жою"], /* TODO "vfd" : ["{"+"{vfd", "", "}}", "vfd ?"], */ "disam" : ["'''", "Ескерту", "''' мына беттерге жату мүмкін:"+ "\n"+ "\n* "+ "\n* "+ "\n* "+ "\n"+ "\n{"+"{ескерту}}", "Нақты емес бет"], /* TODO "to-disam" : ["{"+"{към пояснение|{"+"{SUBST:PAGENAME}}|", "{"+"{SUBST:PAGENAME}}", " (пояснение)}}", "Към пояснение"], */ "cat" : ["["+"[Category:", "Санат", "]]", "Санат"], "cat-info" : ["{"+"{Санат мағлұматы|", "Мақала атауы", "}}", "Санат мағлұматы"], "ext-links" : ["\n== Сыртқы сілтемелер =="+ "\n"+ "\n* [http://", "torap.kz Сыртқы сілтеме", "]", "Сыртқы сілтемелер"], "see-also" : ["\n== Тағы қараңыз =="+ "\n"+ "\n* ["+"[", "Мақала атауы", "]]", "Тағы қараңыз"], /* TODO "references" : ["\n== Түсіндірмелер =="+ "\n"+ "\n* ["+"[", "Мақала атауы", "]]", "Тағы қараңыз"],*/ "license" : ["{"+"{лицензиясыз|~~~~", "", "}}", "Лицензиясыз"], "bio-info" : ["{"+"{Тұлға|"+ "\n аты-тегі = "+ "\n| суреті = dot.png"+ "\n| сипаттамасы = "+ "\n| төл аты-тегі = "+ "\n| туған күн-айы =[[]] [[]]"+ "\n| туған мекені =[[]], [[]]"+ "\n| ажал күн-айыи =[[]] [[]]"+ "\n| ажал мекені =[[]], [[]]"+ "\n", "", "}}", "Өмірбаян мағлұматы"], "film-info" : ["{"+"{Филм"+ "\n| Title = "+ "\n| OrigTitle = "+ "\n| Image = [[Image:|200px]]"+ "\n| Genre = [[]]"+ "\n| Dir = [[|]]"+ "\n| Producer = [[|]]"+ "\n| Script = [[|]]"+ "\n| Actors = [[|]]<br />[[|]]<br />[[|]]<br />[[|]]"+ "\n| Music = [[|]]"+ "\n| Cameraman = [[|]]"+ "\n| Prod = [[]]"+ "\n| Budget = 000 млн. $"+ "\n| Country = [[]]"+ "\n| Time = 00 мин."+ "\n| Year = [[0000]]"+ "\n| imdb_id = 0000000"+ "\n", "", "}}", "Филм мағлұматы"], "company-info" : ["{"+"{Компания мағлұматы|"+ "\n атауы = "+ "\n| лого = dot.png"+ "\n| құрылған = ?"+ "\n| қала = [[]]"+ "\n| ел = [[]]"+ "\n| заети = ?"+ "\n| өнімдері = [[]]"+ "\n| торап = ?"+ "\n", "", "}}", "Компания мағлұматы"] /* TODO "ekip" : ["{"+"{Екип отбор|"+ "\n дом-тяло=orange"+ "\n|дом-ръкави=orange"+ "\n|дом-шорти=black"+ "\n|дом-чорапи=orange"+ "\n"+ "\n|гост-тяло=green"+ "\n|гост-ръкави=green"+ "\n|гост-шорти=black"+ "\n|гост-чорапи=green "\n", "", "}}", "Екип отбор"], */ }; // Generate fall menue with templates function makeTemplateSelectBox() { var box = document.createElement("select"); box.onchange = function() { if (this.value != "") { var el = tpl[this.value]; insertTags(el[0], el[2], el[1]); this.selectedIndex=0; } return false; }; box.appendChild( newOption("", "Үлгі кірістіру…") ); for (var i in tpl) { box.appendChild( newOption(i, tpl[i][3]) ); } return box; } function newOption(val, text) { var o = document.createElement("option"); o.value = val; o.appendChild( document.createTextNode(text) ); return o; } // data for generate additional buttons for insertTags() // TODO: recheck inventory of buttons var customInsButtons = [ // LEFT_TEXT RIGHT_TEXT MIDDLE_TEXT TITLE SHOW_TEXT [" ", "", "", "+жырылмайтын кемтік", "nbsp"], ["|", "", "", "+тік сызық — |", " | "], ["", "́", "", "+екпін — ұ́", " ́ "], ["{"+"{", "}}", "", "+үлгі жақшалары", "{{}}"], ["-"+"{", "}-", "", "+өңдетуден шығару", "-{}-"], ["[["+"|", "]]", "", "+ішкі сілтеме", "[[|]]"], ["[[en:", "]]", "en", "+ағылшыншаға уики-ара", "en:"], ["{{"+"Polytonic|", "}}", "", "+көпүндік грек әріпі", "ᾠ"], ["{{"+"Unicode|", "}}", "", "+юникод нышаны", "uni"], ["{{"+"IPA|", "}}", "", "+айтылуы (IPA)", "IPA"], ["[[Category:", "]]", "", "+санат", "cat"], ["[[Commons:", "]]", "", "+ортақ қоры", "com"], ["[[wikt:", "]]", "", "+сөздік", "wkt"], ["dot.png", "", "", "+dot.png — мөлдір пиксел", "dot"], ["<ref>", "</ref>", "", "+түсіндірме", "ref"], ["<noinclude>", "</noinclude>", "", "Мәтінді кірістірмеу", "no"], ["<includeonly>", "</includeonly>", "", "Тек осыны кірістіру", "inc"] ]; // Names of elements of additional symbols var charsElemId = "extraChars"; var existChars = false; // for sure remove symbols // Generate and add additional symbols in the element $charsElemId // TODO: recheck inventory of symbols function addChars() { // Init var if ( existChars ) { return; } var chars = [ ['ѣ', 'ѫ', 'ѭ', 'ѧ', 'ѩ', 'Ї', 'Ҁ', 'Ѹ', 'Ѡ', 'Ѻ', 'Ъ', 'І', 'Ҍ', 'Ѩ', 'Ѭ', 'Ѯ', 'Ѵ', 'Ѥ', 'Ѿ'], ['*', '~', '|', '[', ']'], ['α', 'β', 'γ', 'δ', 'ε', 'ζ', 'η', 'θ', 'ι', 'κ', 'λ', 'μ', 'ν', 'ξ', 'ο', 'π', 'ρ', 'σ', 'ς', 'τ', 'υ', 'φ', 'χ', 'ψ', 'ω', 'Γ', 'Δ', 'Θ', 'Λ', 'Ξ', 'Π', 'Σ', 'Φ', 'Ψ', 'Ω'], ['∫', '∑', '∏', '√', '−', '±', '∞', '≈', '~', '∝', '≡', '≠', '≤', '≥', '×', '·', '÷', '∂', '′', '″', '∇', '∮', '⊥', '‰', '°', '∴', 'ℵ', 'ℋ', '℧', '№', '^', '¹', '²', '³', '½', '¼', '¾', '∈', '∉', '∩', '∪', '⊂', '⊃', '⊆', '⊇', '∧', '∨', 'ø', '¬', '∃', '∀', '⇒', '⇐', '⇓', '⇑', '⇔', '→', '←', '↓', '↑', '↔', '⇄', '⇆', '⇋', '⇌', 'ℕ', 'ℤ', 'ℚ', 'ℝ', 'ℂ', '∅', '⋮', '⋯'], ['™', '©', '®', '¢', '€', '¥', '£', '¤', '¿', '¡', '«', '»', '§', '¶', '†', '‡', '•', '♀', '♂', '…', '¨'], ['Á', 'á', 'É', 'é', 'Í', 'í', 'Ó', 'ó', 'Ú', 'ú', 'À', 'à', 'È', 'è', 'Ì', 'ì', 'Ò', 'ò', 'Ù', 'ù', 'Â', 'â', 'Ê', 'ê', 'Î', 'î', 'Ô', 'ô', 'Û', 'û', 'Ä', 'ä', 'Ë', 'ë', 'Ï', 'ï'], ['Ö', 'ö', 'Ü', 'ü', 'ß', 'Ã', 'ã', 'Ñ', 'ñ', 'Õ', 'õ', 'Ç', 'ç', 'Ģ', 'ģ', 'Ķ', 'ķ', 'Ļ', 'ļ', 'Ņ', 'ņ', 'Ŗ', 'ŗ', 'Ş', 'ş', 'Ţ', 'ţ', 'Ć', 'ć', 'Ĺ', 'ĺ', 'Ń', 'ń', 'Ŕ', 'ŕ', 'Ś', 'ś', 'Ý', 'ý', 'Ź'], ['ź', 'Đ', 'đ', 'Ů', 'ů', 'Č', 'č', 'Ď', 'ď', 'Ľ', 'ľ', 'Ň', 'ň', 'Ř', 'ř', 'Š', 'š', 'Ť', 'ť', 'Ž', 'ž', 'Ǎ', 'ǎ', 'Ě', 'ě', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ā', 'ā', 'Ē', 'ē', 'Ī', 'ī', 'Ō', 'ō', 'Ū'], ['ū', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'Ĉ', 'ĉ', 'Ĝ', 'ĝ', 'Ĥ', 'ĥ', 'Ĵ', 'ĵ', 'Ŝ', 'ŝ', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ă', 'ă', 'Ğ', 'ğ', 'Ŭ', 'ŭ', 'Ċ', 'ċ', 'Ė', 'ė', 'Ġ', 'ġ', 'İ', 'ı', 'Ż', 'ż', 'Ą', 'ą', 'Ę', 'ę', 'Į'], ['į', 'Ų', 'ų', 'Ł', 'ł', 'Ő', 'ő', 'Ű', 'ű', 'Ŀ', 'ŀ', 'Ħ', 'ħ', 'Ð', 'ð', 'Þ', 'þ', 'Œ', 'œ', 'Æ', 'æ', 'Ø', 'ø', 'Å', 'å'] ]; var cont = ''; var len = chars.length; for (var i in chars) { for (var j in chars[i]) { cont += "<a href=\"javascript:insertTags('"+chars[i][j]+"', '', '')\" "+ 'title="Нышан кірістіру „'+chars[i][j]+'“">'+chars[i][j]+'</a> '; } if (i != len-1) { cont += '· '; } } document.getElementById(charsElemId).innerHTML = cont; existChars = true; } /* hide/show the element */ function toggleElemDisplay(elemId) { var elem = document.getElementById(elemId); elem.style.display = elem.style.display == 'none' ? '' : 'none'; } // data for more buttons by var customMiscButtons = [ // CODE_TEXT TITLE SHOWN_TEXT // call the Wikificator ["Wikify()", "Уикилендіру", "wikify()"], // additional symbols /* ["addChars(); toggleElemDisplay('"+charsElemId+"');", "Қосымша нышандар", "Тағы…"] */ ]; // Add a new buttons and other stuff function setupCustomEditTools() { var toolbar = document.getElementById("toolbar"); // Check is initialized toolbar, if not it, than return if ( !toolbar ) { return; } toolbar.className += " buttonlinks"; var tools = document.createElement("div"); tools.id = "custombuttons"; for (var i in customInsButtons) { var el = customInsButtons[i]; var title = el[3]; if ( title.charAt(0) == "+" ) { title = "Кірістіру: " + title.substr(1); } addCustomButton(tools, {"href": "javascript:insertTags('"+el[0] +"','"+el[1]+"','"+ el[2]+"')", "title": title, "innerHTML": el[4]}); } for (var i in customMiscButtons) { var el = customMiscButtons[i]; addCustomButton(tools, {"href":"javascript:"+el[0], "title":el[1], "innerHTML":el[2]}); } // falling menue with templates toolbar.appendChild( makeTemplateSelectBox() ); toolbar.appendChild(tools); // elent of additional symbols var chbox = document.createElement("div"); chbox.id = charsElemId; chbox.style.display = "none"; toolbar.appendChild(chbox); } function addCustomButton(box, item) { var b = document.createElement("a"); for (var attr in item) { b[attr] = item[attr]; } box.appendChild(b); box.appendChild( document.createTextNode(" ") ); } // BEGIN code borrowed mostly from [[:ru:MediaWiki:Wikificator.js]] var txt; var wmFullText = 'Уикилендіргіш мақаланың БАРЛЫҚ мәтінің. Жалғастырамыз ба?'; var wmCantWork = 'Wikificator cannot work in your browser'; var wmWontWork = 'Wikificator will not work in Netscape 4.x and less'; var wmCategoryNS = 'Санат'; var wmTemplateNS = 'Үлгі'; var wmUserNS = 'Қатысушы'; var wmImageNS = 'Сурет'; var wmMediaNS = 'Таспа'; var wmLocaleNS = new Array ( wmCategoryNS, wmTemplateNS, wmUserNS, wmImageNS, wmMediaNS ); var wmEnNS = new Array ( 'Category', 'Template', 'User', 'Image', 'Media'); if (window.event){ document.onkeypress = pressed; } function pressed() //On Ctrl+Enter (MSIE) {key = window.event.keyCode;if (key==10){Wikify();}} //====================================== function Wikify() { check_regexp(); // Check whether regular expressions are supported document.editform.wpTextbox1.focus(); var txtarea = document.editform.wpTextbox1; if(document.selection && !is_gecko)/* IE */ { txt = " "+document.selection.createRange().text; if (txt == " ") {all_text();} // If nothing was selected; else{ Process(); txt = txt.substr (1, txt.length-1); document.selection.createRange().text = txt; } } else if((txtarea.selectionStart || txtarea.selectionStart == '0')&&(navigator.productSub>20031000)) /*Gecko-browsers older then 10.2003*/ { var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; var scrollTop=txtarea.scrollTop; txt = " "+(txtarea.value).substring(startPos, endPos); if (txt == " ") {all_text();} // If nothing was selected; else{ Process(); txt = txt.substr (1, txt.length-1); txtarea.value = txtarea.value.substring(0, startPos) + txt + txtarea.value.substring(endPos, txtarea.value.length); txtarea.focus(); } } else{if (confirm(wmFullText)) {all_text();}} // Other browsers } //====================================== function all_text()// Process all text { txt = " "+document.editform.wpTextbox1.value; Process(); txt = txt.substr (1, txt.length-1); document.editform.wpTextbox1.value=txt; } //====================================== function check_regexp()// Check whether regular expressions are supported { var reg1 = "code"; reg1 = reg1.replace(/d/g, "r"); if (reg1 != "core"){alert(wmCantWork);exit;} b_ver = navigator.appVersion.substr (0, 1); if (navigator.appName=="Netscape"&&b_ver<5){alert(wmWontWork);exit;} return ; } function Process() // We have 3 more pairs of safe chars in \x1A — \x1F ! { //var nowiki = ReplaceElements( '\<math\>(.|\r|\n)+?\<\/math\>, "\x03", "\x04" ); //That variant will make ReplaceTags() function unnecessary, but it's so ugly... var nowiki = ReplaceTags( 'nowiki', "\x03", "\x04" ); var pre = ReplaceTags( 'pre', "\x12", "\x13" ); var math = ReplaceTags( 'math', "\x05", "\x06" ); var gallery = ReplaceTags( 'gallery', "\x14", "\x15" ); // Exclude lines starting with space f_space = txt.substr (0, 1) txt = txt.substr (1, txt.length-1) var sp_lines = ReplaceElements( "^( )(.+)$", "\x16", "\x17" ); txt = f_space + txt // Process default namespaces /* ProcessNS( wmEnNS , wmLocaleNS ); */ // disabled prior namespace localization var templates = ReplaceElements( "\\{\\{(.|\\r|\\n)+?\\}\\}","\x18", "\x19" ); var links = ReplaceElements( "(\\[\\[)(.*?)(\\||\\]\\])", "\x10", "\x11" ); HTML2Wiki(); ProcessTypography(); // Exclude all text in quotes after "=" sign var equals = ReplaceElements( '(=)(\\s?)(\\' + '")(.*?)(\\")', "\x0E", "\x0F"); var tags = ReplaceElements( "<([^>]*?)>", "\x01", "\x02"); //alert(txt); RestoreElements( tags, "\x01", "\x02"); RestoreElements( equals, "\x0E", "\x0F"); RestoreElements( links, "\x10", "\x11" ); RestoreElements( templates,"\x18", "\x19" ); RestoreElements( sp_lines, "\x16", "\x17" ); RestoreElements( gallery, "\x14", "\x15" ); RestoreElements( math, "\x05", "\x06" ); RestoreElements( pre, "\x12", "\x13" ); RestoreElements( nowiki, "\x03", "\x04" ); } function HTML2Wiki() { // Replace <b>, <strong> tags with ''' and <i>, <em> with '' txt = txt.replace(/\<\/?(b|strong)\>/gim, "\'\'\'") txt = txt.replace(/\<\/?(i|em)\>/gim, "\'\'") // Replace <hr> tag with ----, improve <hr> and <br> tags txt = txt.replace(/\<hr ?\/?\>/gi, "----") txt = txt.replace(/\<hr ([^\>\/]+?) ?\/?\>/gi, "<hr $1 />") txt = txt.replace(/\<br\/?\>/gi, "<br />") txt = txt.replace(/\<br ([^\>\/]+?) ?\/?\>/gi, "<br $1 />") } // Process default namespaces function ProcessNS( En_NS_List, Loc_NS_List ) { for (i=0; i < En_NS_List.length; i++) { //alert("(\\[\\[)(:?)(" + En_NS_List[i] + "|" + //Loc_NS_List[i] + ")(:)( *)"); txt = txt.replace( new RegExp( "(\\[\\[:?)(" + En_NS_List[i] + "|" + Loc_NS_List[i] + "):( *)" , "gi" ), "$1" + Loc_NS_List[i] + ":"); } } //====================================== // Replace '<replaced_tag> ... </replaced_tag>' (<nowiki> <br/> </nowiki>) // with 'opepening_char + tag's counter + closing_char' ('\x03'+1'+'\x04') //====================================== function ReplaceTags(replaced_tag, op_char, cl_char ) // @replaced_tag - tag to be replaced // @op_char, @cl_char (opening & closing chars) - "Save pair" of // unicode unprintable characters, that will be used in replacement { var counter = 0; //tags counter // RegExp pattern var pattern = "\\<" + replaced_tag + "\\>(.|\r|\n)+?\<\\/" + replaced_tag + "\\>"; // RegExp template to be replaced (multiline text between // <replaced_tag> and </replaced_tag> case sensitive tags) var replaced_regexp = new RegExp(pattern , "im") // Buffer for replaced matches storage. It's array of matching substrings - // multiline text between <replaced_tag> and </replaced_tag> case sensitive tags () matches_buffer = txt.match( new RegExp(pattern , "gim") ); // while some substring of txt matches replaced_regexp... while (replaced_regexp.test(txt)) { txt = txt.replace(replaced_regexp, op_char + ++counter + cl_char ); } return matches_buffer; } //====================================== // Replace '<replaced_tag> ... </replaced_tag>' (<nowiki> <br/> </nowiki>) // with 'opepening_char + tag's counter + closing_char' ('\x03'+1'+'\x04') //====================================== function ReplaceElements( req_exp, op_char, cl_char ) // @req_exp - reqular expression to be replaced // @op_char, @cl_char (opening & closing chars) - "Save pair" of // unicode unprintable characters, that will be used in replacement { var counter = 0; //tags counter // RegExp template to be replaced (multiline, case sensitive) var replaced_regexp = new RegExp( req_exp , "m" ) // Buffer for replaced matches storage. It's array of matching substrings. // (multiline, case sensitive, global) matches_buffer = txt.match( new RegExp( req_exp , "gm" ) ); // while some substring of txt matches replaced_regexp... while (replaced_regexp.test(txt)) { //alert(txt.match(replaced_regexp)); txt = txt.replace(replaced_regexp, op_char + ++counter + cl_char ); } return matches_buffer; } //====================================== // Restore text that was by replacing 3 chars with substring from array //====================================== function RestoreElements( replaced_buffer, op_char, cl_char ) // @replaced_buffer - array of replaced substrings. // @op_char, @cl_char (opening & closing chars) - "Save pair" // to be replaced with <replaced_tag> and </replaced_tag> accordingly { var counter = 0; //tags counter // RegExp template to be replaced (3 chars: tag's counter // surrunded by "safe pair") var replaced_regexp = new RegExp("\\" +op_char+ "([0-9]*)\\" +cl_char ); //replaced_regexp = /\x03([0-9]*)\x04/ // while some substring of txt matches replaced_regexp... while (replaced_regexp.test(txt)) { txt = txt.replace(replaced_regexp, replaced_buffer[counter++]); } return txt; } /*************************************************** Typographical considerations ***************************************************/ function ProcessTypography() { // Insert spaces in titles txt = txt.replace(/^(=+)([ \t\f\v]*)(.*?)([ \t\f\v]*)(=+)$/gm, "$1 $3 $1") //====================================== // Use 1 character to display square and cube txt = txt.replace(/(<sup>2<\/sup>|²)/g, "²"); txt = txt.replace(/(<sup>3<\/sup>|³)/g, "³"); txt = txt.replace(/(\^2)(\D)/g, "²$2"); txt = txt.replace(/(\^3)(\D)/g, "³$2"); //====================================== // Correct year ranges txt = txt.replace(/(\(|\s)(\[?\[?[12]?\d{3}\]?\]?)[\u00A0 ]?(-|--|–|—) ?(\[?\[?[12]?\d{3}\]?\]?)(\W)/g, "$1$2—$4$5") txt = txt.replace(/(\[?\[?[12]?\d{3}\]?\]?) ?(г\.|гг\.)/g, "$1\u00A0$2") // Correct century ranges txt = txt.replace(/(\(|\s)(\[?\[?[IVX]{1,5}\]?\]?)[\u00A0 ]?(-|--|–|—) ?(\[?\[?[IVX]{1,5}\]?\]?)(\W)/g, "$1$2—$4$5") txt = txt.replace(/(\[?\[?[IVX]{1,5}\]?\]?) ?(в\.|вв\.)/g, "$1\u00A0$2") //====================================== // Replace right HTML symbols with wrong ones in order to process everithing txt = txt.replace(/–/g, "-") txt = txt.replace(/(«|»|“|”|„|\&((la|ra|bd|ld)quo|#132|#147|#148|quot);)/g, "\"") //====================================== // Replace double hyphen with a dash txt = txt.replace(/(--)(\[\[User|\~\~\~)/g, "—$2") //====================================== // Replace set of 'less then' or 'greater then' symbols (<< or >>) with usual double quotes txt = txt.replace(/(<<)(\S.+\S)(>>)/g, "\"$2\"") //====================================== // Process degree sign "°", "+-" and "~=" txt = txt.replace(/(\+[--])|(±)/g, "±") txt = txt.replace(/(~=)/g, "≈") txt = txt.replace(/\°/g, "°") txt = txt.replace(/([ =≈≠≤≥<>("'|]|^)([+±−\-]?\d+?(?:[.,]\d+?)?)(([ °^*]| [°^*])[CС])(?=[ "').,;!?|]|$)/gm, "$1$2\u00A0°C") txt = txt.replace(/([ =≈≠≤≥<>("'|]|^)([+±−\-]?\d+?(?:[.,]\d+?)?)(([ °^*]| [°^*])F)(?=[ "').,;|!?]|$)/gm, "$1$2\u00A0°F") //====================================== // Replace "...", "…" and "…" with ellipsis txt = txt.replace(/(\.{3}|\&(hellip|#133);)/g, '…') // Apostrophe handler txt = txt.replace(/([\wа-яА-ЯёЁӘәІіҢңҒғҮүҰұҚқӨөҺһ])'([\wа-яА-ЯёЁӘәІіҢңҒғҮүҰұҚқӨөҺһ])/g, "$1ʼ$2") // Minus handler txt = txt.replace(/(sup\>|sub\>|\s)-(\d)/g, "$1−$2") //====================================== // Replace hyphens and en dashes with normal dashes txt = txt.replace(/\&(#151|[nm]dash);/g, "—") txt = txt.replace(/( |[\f\n\r\t\v\u00A0\u2028\u2029])(-|--|–) /g, "$1— ") txt = txt.replace(/(\d)--(\d)/g, "$1—$2") // Insert non-braiking space before dashes txt = txt.replace(/(\S) (-|--|–|—) (\S)/g, "$1\u00A0— $3") //====================================== // Special characters: ©, ®, ™, §, €, ¥ и £. txt = txt.replace(/\©/gi, "©") txt = txt.replace(/(\(r\)|\®)/gi, "®") txt = txt.replace(/(\((tm|тм)\)|\™)/gi, "™") txt = txt.replace(/(\(p\)|\§)/gi, "§") txt = txt.replace (/\€/gi, "€") txt = txt.replace (/\¥/gi, "¥") txt = txt.replace (/\£/gi, "£") //====================================== /* // Correct the reductions txt = txt.replace(/(Т|т)\. ?е\./g, "$1о есть") txt = txt.replace(/(Т|т)\. ?к\./g, "$1ак как") txt = txt.replace(/(В|в) т\. ?ч\./g, "$1 том числе") txt = txt.replace(/и т\. ?д\./g, "и\u00A0т\.\u00A0д\.") txt = txt.replace(/и т\. ?п\./g, "и\u00A0т\.\u00A0п\.") txt = txt.replace(/(Т|т)\. ?н\./g, "$1\.\u00A0н\.") txt = txt.replace(/н\. ?э\./g, "н\.\u00A0э\.") txt = txt.replace(/(Д|д)(о|\.) н\. ?э\./g, "$1о\u00A0н\.\u00A0э\.") txt = txt.replace(/(\d) (тыс)([^\.А-Яа-яЁё])/g, "$1\u00A0$2.$3") txt = txt.replace(/(\d) (млн|млрд|трлн)([^А-Яа-яЁё])/g, "$1\u00A0$2$3") */ // Insert missing and delete unnecessary spaces txt = txt.replace(/([А-Я]\.) ?([А-Я]\.) ?([А-Я][а-я])/g, "$1\u00A0$2\u00A0$3") txt = txt.replace(/([А-Я]\.)([А-Я]\.)/g, "$1 $2") txt = txt.replace(/^([#\*:]+)([ \t\f\v]*)([^ \t\f\v\*#:])/gm, "$1 $3") txt = txt.replace(/([а-я])(\.)([А-ЯA-Z])/g, "$1$2 $3") txt = txt.replace(/([а-яa-z\)\»\“\"\]])(\s*)(\,)([а-яa-z\(\«\„\"\[])/g, "$1$3 $4") txt = txt.replace(/([а-яa-z\)\»\“\"\]])(\s)([\,\;])(\s)([а-яa-z\(\«\„\"\[])/g, "$1$3 $5") txt = txt.replace(/([^%\/\w]\d+?(?:[.,]\d+?)?) ?([%‰])(?!-[А-Яа-яЁёӘәІіҢңҒғҮүҰұҚқӨөҺһ])/g, "$1\u00A0$2") txt = txt.replace(/(\d) ([%‰])(?=-[А-Яа-яЁёӘәІіҢңҒғҮүҰұҚқӨөҺһ])/g, "$1$2") txt = txt.replace(/([№§])(\s*)(\d)/g, "$1\u00A0$3") txt = txt.replace(/(^|[^ \t])([ \t]+)($|\n)/gm, "$1$3") txt = txt.replace(/(\()( +)/g, "$1"); txt = txt.replace(/( +)(\))/g, "$2"); //====================================== // Avoid double spaces txt = txt.substr (1, txt.length-1); txt = txt.replace(/(\S)([ \t]{2,})([\S\r])/g, "$1 $3") txt = " " + txt //====================================== // Replace double quotes ("") with double angle quotes («») txt = txt.replace(/([\x01-(\s\|\"]|\/|\+)(\")([^\"]{0,})([^\s\"(])(\")/g, "$1«\$3\$4»") // Quotations in quotes if (/"/.test(txt)) { txt = txt.replace(/([\x01(\s\"])(\")([^\"]{0,})([^\s\"(])(\")/g, "\$1«\$3\$4»") while (/(«)([^»]*)(«)/.test(txt)) txt = txt.replace(/(«)([^»]*)(«)([^»]*)(»)/g, "\$1\$2„\$4“") } } hookEvent("load", setupCustomEditTools); //========================================================================================== //========================= Translit Code ================================================== //========================================================================================== var output_array = ('А_Ә_Б_Ц_Ч_Д_Е_Ф_Г_Ғ_Ы_І_И_Ж_К_Қ_Л_М_Н_Ң_О_Ө_П_Р_С_Ш_Т_Ұ_Ү_В_У_Х_Й_З_Э_Ю_Я_а_ә_б_ц_ч_цһ_д_е_ф_г_ғ_гһ_һ_ы_і_и_ж_к_л_м_н_ң_нг_о_ө_п_қ_р_с_ш_т_ұ_ү_в_у_х_й_з_э_ю_я_Ч_Ғ_Ң_Ш_Ю_Я_Ә_Э_Ы_Ө_Ү_ә_э_ы_ө_ү_ь_ъ_щ').split('_'); var input_array = ('A_А\'_B_C_Цh_D_E_F_G_Гh_І\'_I_І\"_J_K_Q_L_M_N_Нg_O_О\'_P_R_S_Сh_T_U_Ұ\'_V_W_X_Y_Z_Е\'_Йu_Йa_a_а\'_b_c_цh_цH_d_e_f_g_гh_гH_h_і\'_i_і\"_j_k_l_m_n_нg_нG_o_о\'_p_q_r_s_сh_t_u_ұ\'_v_w_x_y_z_е\'_йu_йa_ЦH_ГH_НG_СH_ЙU_ЙA_А`_Е`_І`_О`_Ұ`_а`_е`_і`_о`_ұ`_#_ь#_|').split('_'); //0 - english, 1 - cyrillic (standard) var language = 1; //=========================================================================================== function changelanguage() { var lang = document.getElementById('lang'); if (language==1) { language=0; lang.value="Ctrl+Alt Lat"; document.editform.wpTextbox1.focus(); return; } if (language==0) { language=1; lang.value="Ctrl+Alt Cyr"; document.editform.wpTextbox1.focus(); return; } } function add_button() { var toolbar = document.getElementById('toolbar'); if (!toolbar) return false; var textbox = document.getElementById('wpTextbox1'); if (!textbox) return false; if (!document.selection && textbox.selectionStart == null) return false; var but = document.createElement("input"); but.type='button'; but.name='lang'; but.id='lang'; but.className='translitbutton'; but.onclick=changelanguage; toolbar.appendChild(but); changelanguage(); } if (navigator.appName == 'Microsoft Internet Explorer' ) addLoadEvent(add_button); document.onkeydown = function AkeyIsDown() { if (event.ctrlKey && event.altKey) {changelanguage();event.returnValue=false;} } //------------------------------------------------------------------------------------------ document.onkeypress= function ConvertInRealTime() { if (document.activeElement!=document.editform.wpTextbox1) return; if (!language) return; //the entered character var code = event.keyCode; txt=String.fromCharCode(code); //make selection cursor_pos_selection = document.selection.createRange(); //delete something selected before cursor_pos_selection.text=""; //get the previous character cursor_pos_selection.moveStart("character",-1); pretxt = cursor_pos_selection.text; if (pretxt.length>1) {pretxt="";} event.keyCode = 0; if (pretxt!="I") result=Convert(pretxt+txt); else result=pretxt+txt; //delete the previous symbol if it is exists (if the entered symbol is not the first one) if (pretxt!="") { cursor_pos_selection.select(); cursor_pos_selection.collapse();} with(document.selection.createRange()) {text = result; collapse(); select()} return; } //----------------------------------------------------------------------------------------- function Convert(text) { var i,text1; for(i=0;i<output_array.length;i++) if(text==input_array[i]) return output_array[i]; text1=text.substr(1,1); for(i=0;i<output_array.length;i++) if(text1==input_array[i]) return text.substr(0,1)+output_array[i]; return text; } //========================================================================================= //========================= End of Translit Code ========================================== //========================================================================================= /* </nowiki></pre> */