پرش به محتوا

کاربر:محمد/insertPakVE.js

از ویکی‌هزاره

نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.

  • فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلید‌های Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-R)
  • گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-Shift-R)
  • Edge: کلید Ctrl را نگه‌دارید و روی دکمهٔ Refresh کلیک کنید، یا کلید‌های Ctrl-F5 را با هم فشار دهید
function makeInsertPakVE() {
    var pakTemplate = [{
        type: 'mwTransclusionInline',
        attributes: {
            mw: {
                parts: [{
                    template: {
                        target: {
                            href: 'الگو:پک',
                            wt: 'پک'
                        },
                        params: {
                            1: {
                                wt: ''
                            },
                            2: {
                                wt: ''
                            },
                            'ک': {
                                wt: ''
                            },
                            'ف': {
                                wt: ''
                            },
                            'ج': {
                                wt: ''
                            },
                            'ص': {
                                wt: ''
                            }
                        }
                    }
                }]
            }
        }
    }, {
        type: '/mwTransclusionInline'
    }];

    function InsertAndOpenCommand(name, options) {
        InsertAndOpenCommand.parent.call(this, name, null, null, options);
    }
    OO.inheritClass(InsertAndOpenCommand, ve.ui.Command);

    InsertAndOpenCommand.prototype.execute = function(surface, args) {
        args = args || this.args;
        surface.getModel().getFragment().collapseToEnd().insertContent(args[0], args[1]).select();
        surface.execute('window', 'open', 'transclusion');
        return true;
    };

    ve.ui.commandRegistry.register(
        new InsertAndOpenCommand('insertpak', {
            args: [pakTemplate, false],
            supportedSelections: ['linear']
        })
    );

    if (ve.ui.wikitextCommandRegistry) {
        ve.ui.wikitextCommandRegistry.register(
            new ve.ui.Command('insertpak', 'mwWikitext', 'wrapSelection', {
                args: ['<ref>{{پک|', '}}</ref>', '', '', '', '', '', ''],
                supportedSelections: ['linear']
            })
        );
    }

    function insertPakVE() {
        insertPakVE.parent.apply(this, arguments);
    }
    OO.inheritClass(insertPakVE, ve.ui.MWTransclusionDialogTool);

    insertPakVE.static.name = 'insertpakve';
    insertPakVE.static.group = 'insert';
    insertPakVE.static.title = 'پک';
    insertPakVE.static.commandName = 'insertpak';
    insertPakVE.static.icon = 'book';

    ve.ui.triggerRegistry.register(
        'insertpak', {
            mac: new ve.ui.Trigger('cmd+shift+,'),
            pc: new ve.ui.Trigger('ctrl+shift+,')
        }
    );
    ve.ui.toolFactory.register(insertPakVE);

}

mw.hook('ve.loadModules').add(function(addPlugin) {
    addPlugin(makeInsertPakVE);
});