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.hook('ve.loadModules').add(function (addPlugin) {
     mw.hook('ve.activationComplete').add(function () {
     addPlugin(function () {
         console.log('ve.activationComplete fired, registering tool...');
         // Register command
       
        ve.ui.commandRegistry.register(
        function doHighlight(surface) {
            new ve.ui.Command('insertHighlight', 'content', 'insert', {
            var fragment = surface.getModel().getFragment();
                args: [
            var selectedText = fragment.getText();
                    [
            if (!selectedText) {
                        {
                return;
                            type: 'mwTransclusionInline',
            }
                            attributes: {
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
                                mw: {
                                    parts: [{
                                        template: {
                                            target: {
                                                href: 'Template:Highlight',
                                                wt: 'Highlight'
                                            },
                                            params: {
                                                1: { wt: 'selected text' }, // Placeholder, replaced dynamically
                                                2: { wt: 'yellow' }
                                            }
                                        }
                                    }]
                                }
                            }
                        },
                        { type: '/mwTransclusionInline' }
                    ],
                    false, // Annotate
                    true // Collapse selection
                ],
                supportedSelections: ['linear']
            })
        );
 
        // Register tool
        function HighlightTool() {
            HighlightTool.super.apply(this, arguments);
         }
         }
       
        var commandName = 'insertHighlight';
       
        if (!ve.ui.commandRegistry.lookup(commandName)) {
            ve.ui.commandRegistry.register(
                new ve.ui.Command(
                    commandName,
                    'content',
                    'exec',
                    { args: [doHighlight] }
                )
            );
        }
       
        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 = 'insert'; // Try insert first
         HighlightTool.static.group = 'insert';
         HighlightTool.static.icon = 'highlight';
         HighlightTool.static.icon = 'highlight';
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.commandName = commandName;
         HighlightTool.static.commandName = 'insertHighlight';
        HighlightTool.static.autoAddToCatchall = true;
         ve.ui.toolFactory.register(HighlightTool);
        HighlightTool.static.autoAddToGroup = true;
 
          
        console.log('Highlight tool and command registered.');
        if (!ve.ui.toolFactory.lookup('highlight')) {
            ve.ui.toolFactory.register(HighlightTool);
            console.log('Highlight tool registered with insert group');
        }
       
        setTimeout(function() {
            if (ve.init.target && ve.init.target.toolbar) {
                var insertGroup = ve.init.target.toolbar.groups.find(g => g.name === 'insert');
                console.log('Insert group:', insertGroup);
               
                if (insertGroup && insertGroup.items) {
                    console.log('Insert group tools:', insertGroup.items.map(item => item.constructor.static.name));
                   
                    // Check if highlight is in there
                    var highlightTool = insertGroup.items.find(item => item.constructor.static.name === 'highlight');
                    if (highlightTool) {
                        console.log('Found highlight tool in insert group!');
                    } else {
                        console.log('Highlight tool NOT found in insert group');
                    }
                }
            }
        }, 3000);
     });
     });
});
});

Version vom 3. September 2025, 21:52 Uhr

mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // Register command
        ve.ui.commandRegistry.register(
            new ve.ui.Command('insertHighlight', 'content', 'insert', {
                args: [
                    [
                        {
                            type: 'mwTransclusionInline',
                            attributes: {
                                mw: {
                                    parts: [{
                                        template: {
                                            target: {
                                                href: 'Template:Highlight',
                                                wt: 'Highlight'
                                            },
                                            params: {
                                                1: { wt: 'selected text' }, // Placeholder, replaced dynamically
                                                2: { wt: 'yellow' }
                                            }
                                        }
                                    }]
                                }
                            }
                        },
                        { type: '/mwTransclusionInline' }
                    ],
                    false, // Annotate
                    true // Collapse selection
                ],
                supportedSelections: ['linear']
            })
        );

        // Register tool
        function HighlightTool() {
            HighlightTool.super.apply(this, arguments);
        }
        OO.inheritClass(HighlightTool, ve.ui.Tool);
        HighlightTool.static.name = 'highlight';
        HighlightTool.static.group = 'insert';
        HighlightTool.static.icon = 'highlight';
        HighlightTool.static.title = 'Highlight text';
        HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(HighlightTool);

        console.log('Highlight tool and command registered.');
    });
});