MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
     mw.hook('ve.activationComplete').add(function () {
     mw.hook('ve.activationComplete').add(function (_, target) {
 
         console.log('VisualEditor activated, adding Highlight tool...');
         console.log('VisualEditor activated, adding Highlight tool...');
       
 
         // --- Define the command ---
         // --- Command ---
         function doHighlight(surface) {
         function doHighlight(surface) {
             var fragment = surface.getModel().getFragment();
             var fragment = surface.getModel().getFragment();
             var selectedText = fragment.getText();
             var selectedText = fragment.getText();
             if (!selectedText) {
             if (!selectedText) return;
                return;
            }
             fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
             fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
         }
         }
       
 
         var commandName = 'insertHighlight';
         var commandName = 'insertHighlight';
       
        // Register command
         if (!ve.ui.commandRegistry.lookup(commandName)) {
         if (!ve.ui.commandRegistry.lookup(commandName)) {
             ve.ui.commandRegistry.register(
             ve.ui.commandRegistry.register(
Zeile 26: Zeile 23:
             );
             );
         }
         }
       
 
         // --- Define the tool ---
         // --- Tool ---
         function HighlightTool(toolGroup, config) {
         function HighlightTool(toolGroup, config) {
             ve.ui.Tool.call(this, 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'; // Start with textStyle
         HighlightTool.static.icon = 'highlight'; // built-in OOUI icon
        HighlightTool.static.icon = 'highlight';
         HighlightTool.static.title = 'Text hervorheben'; // German label for toolbar
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.commandName = commandName;
         HighlightTool.static.commandName = commandName;
          
         HighlightTool.static.group = 'highlightGroup';  // top-level toolbar group
 
         if (!ve.ui.toolFactory.lookup('highlight')) {
         if (!ve.ui.toolFactory.lookup('highlight')) {
             ve.ui.toolFactory.register(HighlightTool);
             ve.ui.toolFactory.register(HighlightTool);
Zeile 44: Zeile 41:
         }
         }


         // Safe debugging - check if target exists
         // --- Force-add top-level toolbar group ---
         setTimeout(function() {
         var toolbar = target.getToolbar();
            if (typeof ve !== 'undefined' && ve.init && ve.init.target) {
        if (toolbar) {
                console.log('Target found:', ve.init.target.constructor.name);
            console.log('Adding Highlight button to top-level toolbar...');
                if (ve.init.target.toolbar) {
            if (!toolbar.getGroup('highlightGroup')) {
                    console.log('Toolbar found');
                 toolbar.addToolbarGroup('highlightGroup', { type: 'bar' });
                    // You can add more debugging here
                }
            } else {
                 console.log('Target not found yet');
             }
             }
        }, 1000);
            toolbar.addTool('highlightGroup', 'highlight');
            toolbar.emit('updateState'); // refresh toolbar
        }
     });
     });
});
});

Version vom 3. September 2025, 20:41 Uhr

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

        console.log('VisualEditor activated, adding Highlight tool...');

        // --- Command ---
        function doHighlight(surface) {
            var fragment = surface.getModel().getFragment();
            var selectedText = fragment.getText();
            if (!selectedText) return;
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
        }

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

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

        HighlightTool.static.name = 'highlight';
        HighlightTool.static.icon = 'highlight';  // built-in OOUI icon
        HighlightTool.static.title = 'Text hervorheben';  // German label for toolbar
        HighlightTool.static.commandName = commandName;
        HighlightTool.static.group = 'highlightGroup';  // top-level toolbar group

        if (!ve.ui.toolFactory.lookup('highlight')) {
            ve.ui.toolFactory.register(HighlightTool);
            console.log('Highlight tool registered');
        }

        // --- Force-add top-level toolbar group ---
        var toolbar = target.getToolbar();
        if (toolbar) {
            console.log('Adding Highlight button to top-level toolbar...');
            if (!toolbar.getGroup('highlightGroup')) {
                toolbar.addToolbarGroup('highlightGroup', { type: 'bar' });
            }
            toolbar.addTool('highlightGroup', 'highlight');
            toolbar.emit('updateState');  // refresh toolbar
        }
    });
});