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

مستخدم:Kilwaz/vector.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 () {
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/commons/4/4b/Button_nbsp.png",
            "speedTip": "Non-breaking space",
            "tagOpen": "&nbsp;",
            "tagClose": "",
            "sampleText": ""
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png",
            "speedTip": "تحويل",
            "tagOpen": "#تحويل [[",
            "tagClose": "]]",
            "sampleText": "اسم الصفحة الهدف"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
            "speedTip": "مسطر عليه",
            "tagOpen": "<s>",
            "tagClose": "</s>",
            "sampleText": "مسطر عليه"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
            "speedTip": "سطر جديد",
            "tagOpen": "<br />",
            "tagClose": "",
            "sampleText": ""
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
            "speedTip": "سفلي",
            "tagOpen": "<sup>",
            "tagClose": "</sup>",
            "sampleText": "سفلي"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
            "speedTip": "علوي",
            "tagOpen": "<sub>",
            "tagClose": "</sub>",
            "sampleText": "علوي"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
            "speedTip": "صغير",
            "tagOpen": "<small>",
            "tagClose": "</small>",
            "sampleText": "صغير"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
            "speedTip": "تعليق مخفي",
            "tagOpen": "<!-- ",
            "tagClose": " -->",
            "sampleText": "تعليق مخفي"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
            "speedTip": "معرض صور",
            "tagOpen": "\n<gallery>\n",
            "tagClose": "\n</gallery>",
            "sampleText": "Image:Example.jpg|نص الصورة 1\nImage:Example.jpg|نص الصورة 2"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png",
            "speedTip": "جدول",
            "tagOpen": '{| class="wikitable"\n|-\n',
            "tagClose": "\n|}",
            "sampleText": "! ترويسة 1\n! ترويسة 2\n! ترويسة 3\n|-\n| مثال\n| مثال\n| مثال\n|-\n| مثال\n| مثال\n| مثال"
        };
        mwCustomEditButtons[mwCustomEditButtons.length] = {
            "imageFile": "//upload.wikimedia.org/wikipedia/commons/2/2b/Button_ref_inscription.png",
            "speedTip": "ضع بين <ref></ref>",
            "tagOpen": "<ref>",
            "tagClose": "</ref>",
            "sampleText": "مرجع"
        };
    };
*/
    // 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/thumb/6/6b/Question_book_sourced.svg/30px-Question_book_sourced.svg.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "\n==مراجع==\n{{مراجع}}\n",
                        }
                    }
                },

                'category': {
                    label: 'بالإنجليزية',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/thumb/c/ce/E_Letter_LZNQBD.jpg/40px-E_Letter_LZNQBD.jpg',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "{{إنج|",
                            post: "}}"
                        }
                    }
                },
                'ddksd': {
                    label: 'انظر ايضا',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Libya-orb.png/20px-Libya-orb.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre:  "\n==انظر ايضا==\n* \n",
                            post: ""
                        }
                    }
                },
                
                'template': {
                    label: 'قالب',
                    type: 'button',
                    icon: '//upload.wikimedia.org/wikipedia/commons/4/4a/Norwegian_template_sign.png',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "''''''{{إنج|}}\n== معرض الصور ==\n<gallery mode=packed heights=150px>\nملف:|\n</gallery>\n==انظر ايضا==\n* \n==مراجع==\n{{مراجع}}\n==وصلات خارجية==",
                            
                            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/thumb/c/ce/Gnome-format-justify-left.svg/22px-Gnome-format-justify-left.svg',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<div class=\"mw-content-ltr\">",
                            periMsg: 'يسار',
                            post: "</div>"
                        }
                    }
                },

                '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>'
                        }
                    }
                },

                '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>"
                        }
                    }
                }
            }
        });

        // add a template menu in the advanced sectionined' ) {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
            'section': 'main',
            groups: {
                'heading': {
                    tools: {
                        'heading': {
                            label: 'قالب',
                            type: 'select',
                            list: {
                                'about': {
                                    label: label('وضح'),
                                    action: {
                                        type: 'encapsulate',
                                        options: {
                                            pre: pre('وضح'),
                                            //peri: peri('نص'),
                                            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);
                });
            } else {
                $(customizeOrigToolbar);
            }
        });
    }

})(mediaWiki, jQuery);