انتقل إلى المحتوى

مستخدم:ASammour/en-ar.js

من ويكيبيديا، الموسوعة الحرة

ملاحظة: بعد الحفظ، قد يلزمك إفراغ الكاش لرؤية التغييرات.

/*إضافة لإخفاء جملة هل تقصد عند حذف النص من مربع النص*/
$(".oo-ui-textInputWidget [type='search']").keyup(function(e) {
     if (e.keyCode == 8) {
         $('#didyoumeanr').empty();
     }
 });

 $("#searchInput").keyup(function(e) {
     if (e.keyCode == 8) {
         $('#didyoumean').empty();
     }
 });
 
 
/*إضافة زر إلى صندوق الأدوات ليُتيح تحويل الأحرف الإنجليزية إلى العربية*/
(function(mw, $, undefined) {
    var customizeBetaToolbar = function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            'group': 'insert',
            'tools': {
                'en-ar': {
                    label: 'الإنجليزية إلى العربية',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/d/d8/Toolbaricon_bold_E.png',
                    action: {
                        type: 'callback',
						/*عند الضغط على الزر سيقوم باساتبدال المحدد بالنص العربي*/
                        execute: function(context) {
                        	/*عملية الاستبدال*/
                            $('#wpTextbox1').val(
                                $('#wpTextbox1').val().replace(getInputSelection($("#wpTextbox1")),
                                    replaceEnChars(getInputSelection($("#wpTextbox1")))));

                        }
                    }

               /*زر خاص بالتحويل من العربية إلى الإنجليزية*/
                },'ar-en': {
                    label: 'العربية إلى الإنجليزية',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/8/81/Toolbaricon_bold_A-1.png',
                    action: {
                        type: 'callback',
						/*عند الضغط على الزر سيقوم باساتبدال المحدد بالنص الإنجليزي*/
                        execute: function(context) {
                        	/*عملية الاستبدال*/
                            $('#wpTextbox1').val(
                                $('#wpTextbox1').val().replace(getInputSelection($("#wpTextbox1")),
                                    replaceArChars(getInputSelection($("#wpTextbox1")))));

                        }
                    }
                }
            }
        });
    };


    if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
        mw.loader.using('user.options', function() {
            if (mw.user.options.get('usebetatoolbar')) {
                mw.loader.using('ext.wikiEditor', function() {
                    $(customizeBetaToolbar);
                });
            } else {
                $(customizeOrigToolbar);
            }
        });
    }
})(mediaWiki, jQuery);

/*نهاية الزر*/


/*النمط الخاص باللغة العربية*/
var arabic = /[\u0600-\u06FF]/;

/*افحص الحروف المدخلة في صندوق البحث عندما يتم إدخال أي حرف ، أو إزالته من الصندوق*/
$('#searchInput').keyup(updateCount);
$('#searchInput').keydown(updateCount);

$(".oo-ui-textInputWidget [type='search']").ready(results);
$(".oo-ui-textInputWidget [type='search']").keydown(results);
$(".oo-ui-textInputWidget [type='search']").keyup(results);


$("#searchInput").after('<br><br><div style = "color:blue;position:absolute; left:-1%;top:-120%;" id= "didyoumean"></div>');
$("#searchText").after('<div style = "color:blue;position:absolute; left:22%;top:15%;" id= "didyoumeanr"></div>');

/*الاستبدال في صفحة نتائج البحث*/
function results() {
    var cs = $(".oo-ui-textInputWidget [type='search']").val().length;
    var searchKey = $(".oo-ui-textInputWidget [type='search']").val();
    if (!(arabic.test(searchKey)) & cs > 4) {
        $("#didyoumeanr").html("هل تقصد: <u><a style = 'color:red;' id = 'suggestr'>" + replaceEnChars(searchKey) + "</a>        </u>");
        $('#suggestr').on('click', function() {
            var input = $(".oo-ui-textInputWidget [type='search']");
            input.val(replaceEnChars(searchKey));
            $("#didyoumeanr").empty();
        });
    }
}

/*جلب النص المحدد*/
function getInputSelection(elem) {
    if (typeof elem != "undefined") {
        s = elem[0].selectionStart;
        e = elem[0].selectionEnd;
        return elem.val().substring(s, e);
    } else {
        return '';
    }
}

/*الاستبدال في صندوق البحث العادي*/
function updateCount() {
    var cs = $(this).val().length;
    var searchKey = $(this).val();
    if (!(arabic.test(searchKey)) & cs > 4) {
        $("#didyoumean").html("هل تقصد: <u><a style = 'color:red;' id = 'suggest'>" + replaceEnChars(searchKey) + "</a>        </u>");
        $('#suggest').on('click', function() {
            var input = $("#searchInput");
            input.val(replaceEnChars(searchKey));
            $("#didyoumean").empty();
        });
    }
}



/*هنا يتم الاستبدال*/
function replaceEnChars(text) {
    text = text.replace(/q/gi, 'ض');
    text = text.replace(/w/gi, 'ص');
    text = text.replace(/e/gi, 'ث');
    text = text.replace(/r/gi, "ق");
    text = text.replace(/t/gi, "ف");
    text = text.replace(/y/g, "غ");
    text = text.replace(/u/gi, "ع");
    text = text.replace(/i/gi, "ه");
    text = text.replace(/o/gi, "خ");
    text = text.replace(/p/gi, "ح");
    text = text.replace(/\[/gi, "ج");
    text = text.replace(/]/gi, "د");
    text = text.replace(/a/gi, "ش");
    text = text.replace(/s/gi, "س");
    text = text.replace(/d/gi, "ي");
    text = text.replace(/f/gi, "ب");
    text = text.replace(/g/gi, "ل");
    text = text.replace(/h/g, "ا");
    text = text.replace(/H/g, "أ");
    text = text.replace(/Y/g, "إ");
    text = text.replace(/j/gi, "ت");
    text = text.replace(/k/gi, "ن");
    text = text.replace(/l/gi, "م");
    text = text.replace(/;/gi, "ك");
    text = text.replace(/'/gi, "ط");
    text = text.replace(/`/gi, "ذ");
    text = text.replace(/z/gi, "ئ");
    text = text.replace(/x/gi, "ء");
    text = text.replace(/c/gi, "ؤ");
    text = text.replace(/v/gi, "ر");
    text = text.replace(/b/gi, "لا");
    text = text.replace(/n/gi, "ى");
    text = text.replace(/m/gi, "ة");
    text = text.replace(/,/gi, "و");
    text = text.replace(/\./gi, "ز");
    text = text.replace(/\//gi, "ظ");
    return text;
}


function replaceArChars(string) {
    string = string.replace(/أ/gi, 'H');
    string = string.replace(/د/gi, ']');
    string = string.replace(/ج/gi, '[');
    string = string.replace(/ح/gi, 'p');
    string = string.replace(/خ/gi, 'o');
    string = string.replace(/ه/gi, 'i');
    string = string.replace(/ع/gi, 'u');
    string = string.replace(/غ/gi, 'y');
    string = string.replace(/ف/gi, 't');
    string = string.replace(/ق/gi, 'r');
    string = string.replace(/ث/gi, 'e');
    string = string.replace(/ص/gi, 'w');
    string = string.replace(/ض/gi, 'q');
    string = string.replace(/ط/gi, '\'');
    string = string.replace(/ك/gi, ';');
    string = string.replace(/م/gi, 'l');
    string = string.replace(/ن/gi, 'k');
    string = string.replace(/ت/gi, 'j');
    string = string.replace(/ا/gi, 'h');
    string = string.replace(/ل/gi, 'g');
    string = string.replace(/ب/gi, 'f');
    string = string.replace(/ي/gi, 'd');
    string = string.replace(/س/gi, 's');
    string = string.replace(/ش/gi, 'a');
    string = string.replace(/ظ/gi, '/');
    string = string.replace(/ز/gi, '.');
    string = string.replace(/و/gi, ',');
    string = string.replace(/ة/gi, 'm');
    string = string.replace(/ى/gi, 'n');
    string = string.replace(/لا/gi, 'b');
    string = string.replace(/ر/gi, 'v');
    string = string.replace(/ؤ/gi, 'c');
    string = string.replace(/ء/gi, 'x');
    string = string.replace(/ئ/gi, 'z');
    return string;
}