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

مستخدم:Кензой/en-ar.js

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

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

var english = /[\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 (!(english.test(searchKey)) & cs>4){
	$("#didyoumeanr").html("هل تقصد: <u><a style = 'color:red;' id = 'suggestr'>"+replaeChars (searchKey)+"</a>        </u>");
       	$('#suggestr').on('click', function () {
			var input = $( ".oo-ui-textInputWidget [type='search']" );
			input.val(replaeChars (searchKey));
                        $("#didyoumeanr").hide ();
		});
	}
}


function updateCount() {
    var cs = $(this).val().length;
    var searchKey= $(this).val();
    if (!(english.test(searchKey)) & cs>4){
       $("#didyoumean").html("هل تقصد: <u><a style = 'color:red;' id = 'suggest'>"+replaeChars (searchKey)+"</a>        </u>");
       	$('#suggest').on('click', function () {
			var input = $( "#searchInput" );
			input.val(replaeChars (searchKey));
                        $("#didyoumean").hide ();
		});
	}
}

function replaeChars (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(mw, $, undefined) {
    var customizeBetaToolbar = function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            'group': 'insert',
            'tools': {
                'uncyclopedic': {
                    label: 'en-ar',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/2/2d/Toolbaricon_insert_%C3%86.png',
                    action: {
                        type: 'callback',
						/*عند الضغط على الزر سيقوم باساتبدال المحدد بالنص العربي*/
                        execute: function(context) {
                        	/*عملية الاستبدال*/
                            $('#wpTextbox1').val(
                                $('#wpTextbox1').val().replace(getInputSelection($("#wpTextbox1")),
                                    replaeChars(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 english = /[\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 (!(english.test(searchKey)) & cs > 4) {
        $("#didyoumeanr").html("هل تقصد: <u><a style = 'color:red;' id = 'suggestr'>" + replaeChars(searchKey) + "</a>        </u>");
        $('#suggestr').on('click', function() {
            var input = $(".oo-ui-textInputWidget [type='search']");
            input.val(replaeChars(searchKey));
            $("#didyoumeanr").hide();
        });
    }
}

/*جلب النص المحدد*/
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 (!(english.test(searchKey)) & cs > 4) {
        $("#didyoumean").html("هل تقصد: <u><a style = 'color:red;' id = 'suggest'>" + replaeChars(searchKey) + "</a>        </u>");
        $('#suggest').on('click', function() {
            var input = $("#searchInput");
            input.val(replaeChars(searchKey));
            $("#didyoumean").hide();
        });
    }
}



/*هنا يتم الاستبدال*/
function replaeChars(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;
}