MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus RI Wiki
				
				
				Zur Navigation springenZur Suche springen
				
				
| Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt | Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt | ||
| Zeile 59: | Zeile 59: | ||
|      }); |      }); | ||
| }); | }); | ||
| // Run this in the browser console after opening VisualEditor | |||
| setTimeout(function() { | |||
|     if (ve.init && ve.init.target && ve.init.target.toolbar) { | |||
|         // Find the highlight tool in any group | |||
|         var allTools = []; | |||
|         ve.init.target.toolbar.tools.forEach(function(toolGroup) { | |||
|             if (toolGroup && toolGroup.tools) { | |||
|                 toolGroup.tools.forEach(function(tool) { | |||
|                     if (tool && tool.constructor && tool.constructor.static) { | |||
|                         allTools.push({ | |||
|                             name: tool.constructor.static.name, | |||
|                             group: tool.constructor.static.group, | |||
|                             icon: tool.constructor.static.icon | |||
|                         }); | |||
|                     } | |||
|                 }); | |||
|             } | |||
|         }); | |||
|         console.log('All registered tools:', allTools); | |||
|         // Check if our tool is there | |||
|         var highlightTool = allTools.find(function(t) { | |||
|             return t.name === 'highlight'; | |||
|         }); | |||
|         console.log('Highlight tool found:', highlightTool); | |||
|     } | |||
| }, 3000); | |||
Version vom 3. September 2025, 22:15 Uhr
mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // Custom command for highlighting
        ve.ui.HighlightCommand = function VeUiHighlightCommand() {
            ve.ui.HighlightCommand.super.call(this, 'insertHighlight');
        };
        OO.inheritClass(ve.ui.HighlightCommand, ve.ui.Command);
        ve.ui.HighlightCommand.prototype.execute = function (surface) {
            var fragment = surface.getModel().getFragment();
            var selectedText = fragment.getText();
            
            if (!selectedText) {
                surface.getView().flash();
                return false;
            }
            var templateData = [
                {
                    type: 'mwTransclusionInline',
                    attributes: {
                        mw: {
                            parts: [{
                                template: {
                                    target: {
                                        href: 'Template:Highlight',
                                        wt: 'Highlight'
                                    },
                                    params: {
                                        1: { wt: selectedText },
                                        2: { wt: 'yellow' }
                                    }
                                }
                            }]
                        }
                    }
                },
                { type: '/mwTransclusionInline' }
            ];
            fragment.insertContent(templateData);
            return true;
        };
        ve.ui.commandRegistry.register(new ve.ui.HighlightCommand());
        // Register tool
        ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
            ve.ui.HighlightTool.super.call(this, toolGroup, config);
        };
        OO.inheritClass(ve.ui.HighlightTool, ve.ui.Tool);
        ve.ui.HighlightTool.static.name = 'highlight';
        ve.ui.HighlightTool.static.group = 'insert';
        ve.ui.HighlightTool.static.icon = 'marker';
        ve.ui.HighlightTool.static.title = 'Highlight text';
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);
        console.log('Highlight tool and command registered.');
    });
});
// Run this in the browser console after opening VisualEditor
setTimeout(function() {
    if (ve.init && ve.init.target && ve.init.target.toolbar) {
        // Find the highlight tool in any group
        var allTools = [];
        ve.init.target.toolbar.tools.forEach(function(toolGroup) {
            if (toolGroup && toolGroup.tools) {
                toolGroup.tools.forEach(function(tool) {
                    if (tool && tool.constructor && tool.constructor.static) {
                        allTools.push({
                            name: tool.constructor.static.name,
                            group: tool.constructor.static.group,
                            icon: tool.constructor.static.icon
                        });
                    }
                });
            }
        });
        console.log('All registered tools:', allTools);
        
        // Check if our tool is there
        var highlightTool = allTools.find(function(t) {
            return t.name === 'highlight';
        });
        console.log('Highlight tool found:', highlightTool);
    }
}, 3000);