MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Die Seite wurde neu angelegt: „Das folgende JavaScript wird für alle Benutzer geladen.: mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () { mw.hook('ve.ui.toolFactory').add(function () { // Define a new tool function HighlightTool() { ve.ui.Tool.call(this); } OO.inheritClass(HighlightTool, ve.ui.Tool); HighlightTool.static.name = 'highlight'; HighlightTool.static.group = 'textStyle';…“
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
     mw.hook('ve.ui.toolFactory').add(function () {
     mw.hook('ve.activationComplete').add(function () {
         // Define a new tool
 
         function HighlightTool() {
         // --- Define the command ---
             ve.ui.Tool.call(this);
        function doHighlight(surface) {
            var fragment = surface.getModel().getFragment();
            var selectedText = fragment.getText();
            if (!selectedText) return;
 
            // Replace selected text with the template call
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
        }
 
        var commandName = 'insertHighlight';
 
        ve.ui.commandRegistry.register(
            new ve.ui.Command(
                commandName,
                'content',
                'exec',
                { args: [doHighlight] }
            )
        );
 
        // --- Define the tool ---
         function HighlightTool(toolGroup, config) {
             ve.ui.Tool.call(this, toolGroup, config);
         }
         }
         OO.inheritClass(HighlightTool, ve.ui.Tool);
         OO.inheritClass(HighlightTool, ve.ui.Tool);


         HighlightTool.static.name = 'highlight';
         HighlightTool.static.name = 'highlight';
         HighlightTool.static.group = 'textStyle';
         HighlightTool.static.group = 'insert';
         HighlightTool.static.icon = 'highlight'; // you can use 'highlight' or custom svg
         HighlightTool.static.icon = 'highlight'; // Built-in OOUI icon
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.commandName = 'highlightCommand';
         HighlightTool.static.commandName = commandName;


         ve.ui.toolFactory.register(HighlightTool);
         ve.ui.toolFactory.register(HighlightTool);


         // Define the command
         // --- Add to toolbar ---
         ve.ui.commandRegistry.register(
         ve.ui.targetToolbarGroups.content.push({
            new ve.ui.Command(
            name: 'highlightGroup',
                'highlightCommand',
            type: 'bar',
                'content',
            include: [ 'highlight' ]
                'wrapAnnotation',
        });
                {
                    args: [{
                        name: 'template',
                        data: {
                            target: {
                                href: 'Template:Highlight'
                            },
                            params: {
                                '1': '', // text will be filled in
                                '2': 'yellow' // default color
                            }
                        }
                    }]
                }
            )
        );
     });
     });
});
});

Version vom 3. September 2025, 20:06 Uhr

mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
    mw.hook('ve.activationComplete').add(function () {

        // --- Define the command ---
        function doHighlight(surface) {
            var fragment = surface.getModel().getFragment();
            var selectedText = fragment.getText();
            if (!selectedText) return;

            // Replace selected text with the template call
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
        }

        var commandName = 'insertHighlight';

        ve.ui.commandRegistry.register(
            new ve.ui.Command(
                commandName,
                'content',
                'exec',
                { args: [doHighlight] }
            )
        );

        // --- Define the tool ---
        function HighlightTool(toolGroup, config) {
            ve.ui.Tool.call(this, toolGroup, config);
        }
        OO.inheritClass(HighlightTool, ve.ui.Tool);

        HighlightTool.static.name = 'highlight';
        HighlightTool.static.group = 'insert';
        HighlightTool.static.icon = 'highlight'; // Built-in OOUI icon
        HighlightTool.static.title = 'Highlight text';
        HighlightTool.static.commandName = commandName;

        ve.ui.toolFactory.register(HighlightTool);

        // --- Add to toolbar ---
        ve.ui.targetToolbarGroups.content.push({
            name: 'highlightGroup',
            type: 'bar',
            include: [ 'highlight' ]
        });
    });
});