مستخدم:حبيشان/Gadget-Extra-Edittools.js

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

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

//[[ويكيبيديا:إضافة أدوات تحرير#النص الثاني]]
/*
[[:he:Mediawiki:Edittoolbar.js]]
{{Oldid|:no:MediaWiki:Common.js|10296967}}
[[:zh:Mediawiki:Gadget-Edittools-vector.js]]
*/
// Description: Modify parts of the toolbar to better suit this projects needs
(function (mw, $, undefined) {

    // function to build complete labels, just to get rid of some pesky errors
    var label = function (msg, txt, before, after) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (after === undefined ? true : after) str += "}" + "}";
        if (txt) str += " – " + txt;
        return str;
    };

    // function to build pre-parts of the templates, just to get rid of some pesky errors
    var pre = function (msg, txt, before) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (txt) str += txt;
        return str;
    };

    // function to build peri-parts of the templates, just to get rid of some pesky errors
    var peri = function (msg, txt, before, after) {
        var str = '';
        if (before === undefined ? true : before) str += "{" + "{";
        str += msg;
        if (txt) str += txt;
        if (after === undefined ? true : after) str += "}" + "}";
        return str;
    };

    // get timestamp for templates
    var now = new Date();
    var timestamp = now.getUTCFullYear() + '-' + (now.getUTCMonth() < 9 ? '0' : '') + (now.getUTCMonth() + 1) + '-' + (now.getUTCDate() < 9 ? '0' : '') + now.getUTCDate();

    // customization for the original toolbar
    var customizeOrigToolbar = function () {};

    // customization for the beta toolbar
    var customizeBetaToolbar = function () {

        // Add button for inserting double square brackets (popular feature of old toolbar)
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            'group': 'insert',
            'tools': {
                'references': {
                    label: 'مراجع',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/7/7f/Button_poeme_transparent.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "\n== المراجع ==\n{{مراجع}}\n",
                        }
                    }
                },

                'category': {
                    label: 'تصنيف',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/c/c4/Button_titre_transparent.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "[[تصنيف:",
                            post: "]]"
                        }
                    }
                },

                'template': {
                    label: 'قالب',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "{{",
                            periMsg: 'قالب|',
                            post: "}}"
                        }
                    }
                }
            }
        });
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'advanced',
            'group': 'format',
            'tools': {
                'hidden': {
                    label: 'تعليق مخفي',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/1/11/Toolbaricon_hiddencomment.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<!-- ",
                            periMsg: 'تعليق',
                            post: " -->"
                        }
                    }
                },
                'center': {
                    label: 'كتابة في الوسط',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Gnome-format-justify-center.svg/22px-Gnome-format-justify-center.svg.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<center>",
                            periMsg: 'وسط',
                            post: "</center>"
                        }
                    }
                },
                'left': {
                    label: 'كتابة من اليسار',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/8/81/Toolbaricon_justify-left.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<div class=\"mw-content-ltr\">",
                            periMsg: 'يسار',
                            post: "</div>"
                        }
                    }
                },

                'code': {
                        label: 'نص برمجة',
                        type: 'button',
                        icon: '//upload.wikimedia.org/wikipedia/commons/6/62/Toolbar_code.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "<code>",
                                        post: "</code>",
                                }
                        }
                },
                'quoteit': {
                    label: 'تنصيص',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "«",
                            post: "»"
                        }
                    }
                },
                'pre': {
                        label: 'نص خام',
                        type: 'button',
                        icon: '//upload.wikimedia.org/wikipedia/commons/b/b9/Toolbar_pre_vector.png',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: "<pre>",
                                        post: "</pre>",
                                }
                        }
                },

                'lang': {
                    label: 'كتابة بلغة معينة',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/0/09/Toolbaricon_bold_粗.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<span lang=\"und\">",
                            periMsg: 'كتابة',
                            post: '</span>'
                        }
                    }
                },

                'source': {
                    label: 'كتابة بلغة برمجة معينة',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/6/6d/Toolbaricon_bold_P-1.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<source lang=\"text\">",
                            periMsg: 'كتابة برمجية',
                            post: '</source>'
                        }
                    }
                },

            }
        });



        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'advanced',
            'group': 'insert',
            'tools': {
 
/*                'math': {
                    label: 'صيغة رياضية لاتينية',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/1/1c/Toolbaricon_math.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<math>",
                            periMsg: 'صيغة رياضية',
                            post: "</math>"
                        }
                    }
                },
*/
                'includeonly': {
                    label: 'تضمين في قالب',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/b/bb/Toolbaricon_regular_I.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<includeonly>",
                            periMsg: 'قالب مضمن',
                            post: "</includeonly>"
                        }
                    }
                },

                'noinclude': {
                    label: 'إظهار في قالب',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/5/55/Toolbaricon_no_include.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<noinclude>",
                            periMsg: 'قالب غير مضمن',
                            post: "</noinclude>"
                        }
                    }
                },
                'seealso': {
                    label: 'انظر أيضا',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/3/3b/Toolbaricon_regular_a_to_b.png',
                    action: {
                            type: 'encapsulate',
                            options: {
                                    pre: "== انظر أيضا ==\n* [[",
                                    post: "]]\n",
                            }
                    }
            },
            'stub': {
                    label: 'بذرة',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/0/05/Toolbar_microstub.png',
                    action: {
                            type: 'encapsulate',
                            options: {
                                    pre: "{{بذرة",
                                    post: "}}",
                            }
                    }
            },
            'layoutstub': {
                    label: 'نسق بذرة',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/3/33/Toolbar_welcome.png',
                    action: {
                            type: 'encapsulate',
                            options: {
                                    pre: "'''{{",
                                    peri: 'نسخ:اسم_الصفحة_الأساسي', 
                                    post: "}}''' <ref></ref>\n\n==انظر أيضا==\n*[[]]\n\n==مراجع==\n{{مراجع}}\n\n{{بذرة}}\n\n[[تصنيف:]]",
                            }
                    }
            }
            }
        });
        // add a template menu in the advanced sectionined' ) {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'قالب',
                            type: 'select',
                            list: {
                                'short-cite': {
                                    label: label('استشهاد مختصر'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: '<ref>{{استشهاد مختصر|',
                                            post: '|ج=|ص=}}</ref>',
                                            ownline: false
                                        }
                                    }
                                },
                                'abyat': {
                                    label: label('أبيات'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('أبيات') + '|',
                                            post: '}}',
                                            ownline: true
                                        }
                                    }
                                },
                                'about': {
                                    label: label('وضح'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('وضح'),
                                            post: '}}',
                                            ownline: true
                                        }
                                    }
                                },
                                'references': {
                                    label: label('مراجع'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('مراجع'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'stub': {
                                    label: label('بذرة'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('بذرة'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                },
                                'disambiguation': {
                                    label: label('توضيح'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('توضيح'),
                                            post: '}}',
                                            ownline: false
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    };

    /* Check if we are in edit mode and the required modules are available and then customize the toolbar */
    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);
                });
            }
        });
    }

})(mediaWiki, jQuery);