MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 6: Zeile 6:
             var fragment = surface.getModel().getFragment();
             var fragment = surface.getModel().getFragment();
             var selectedText = fragment.getText();
             var selectedText = fragment.getText();
             if (!selectedText) return;
             if (!selectedText) {
                return;
            }


             // Replace selected text with the template call
             // Replace selected text with the template call
Zeile 14: Zeile 16:
         var commandName = 'insertHighlight';
         var commandName = 'insertHighlight';


         ve.ui.commandRegistry.register(
         // Register command
            new ve.ui.Command(
        if (!ve.ui.commandRegistry.lookup(commandName)) {
                commandName,
            ve.ui.commandRegistry.register(
                'content',
                new ve.ui.Command(
                'exec',
                    commandName,
                { args: [doHighlight] }
                    'content',
             )
                    'exec',
         );
                    { args: [doHighlight] }
                )
             );
         }


         // --- Define the tool ---
         // --- Define the tool ---
Zeile 30: Zeile 35:


         HighlightTool.static.name = 'highlight';
         HighlightTool.static.name = 'highlight';
         HighlightTool.static.group = 'insert';
         HighlightTool.static.group = 'insert';   // Puts it into the Insert group
         HighlightTool.static.icon = 'highlight'; // Built-in OOUI icon
         HighlightTool.static.icon = 'highlight'; // Uses built-in OOUI icon
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.commandName = commandName;
         HighlightTool.static.commandName = commandName;


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

Version vom 3. September 2025, 20:09 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';

        // Register command
        if (!ve.ui.commandRegistry.lookup(commandName)) {
            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';   // Puts it into the Insert group
        HighlightTool.static.icon = 'highlight'; // Uses built-in OOUI icon
        HighlightTool.static.title = 'Highlight text';
        HighlightTool.static.commandName = commandName;

        if (!ve.ui.toolFactory.lookup('highlight')) {
            ve.ui.toolFactory.register(HighlightTool);
        }
    });
});