MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(17 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
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...');
         // 1. Define a custom annotation for highlighting
       
         ve.dm.HighlightAnnotation = function VeDmHighlightAnnotation() {
         // --- Register your tool (same as before) ---
             ve.dm.HighlightAnnotation.super.apply(this, arguments);
        function doHighlight(surface) {
         };
            var fragment = surface.getModel().getFragment();
         OO.inheritClass(ve.dm.HighlightAnnotation, ve.dm.TextStyleAnnotation);
            var selectedText = fragment.getText();
         ve.dm.HighlightAnnotation.static.name = 'textStyle/highlight';
            if (!selectedText) {
         ve.dm.HighlightAnnotation.static.matchTagNames = ['mark'];
                return;
         ve.dm.annotationFactory.register(ve.dm.HighlightAnnotation);
            }
 
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
         // 2. Define the contentEditable view for the annotation
         }
         ve.ce.HighlightAnnotation = function VeCeHighlightAnnotation() {
       
             ve.ce.HighlightAnnotation.super.apply(this, arguments);
        var commandName = 'insertHighlight';
        };
       
        OO.inheritClass(ve.ce.HighlightAnnotation, ve.ce.TextStyleAnnotation);
        if (!ve.ui.commandRegistry.lookup(commandName)) {
        ve.ce.HighlightAnnotation.static.name = 'textStyle/highlight';
             ve.ui.commandRegistry.register(
        ve.ce.HighlightAnnotation.static.tagName = 'mark';
                new ve.ui.Command(
        ve.ce.annotationFactory.register(ve.ce.HighlightAnnotation);
                    commandName,
 
                    'content',
        // 3. Register the command to toggle the highlight
                    'exec',
        ve.ui.commandRegistry.register(
                    { args: [doHighlight] }
            new ve.ui.Command(
                )
                'insertHighlight',
            );
                'annotation',
         }
                 'toggle',
       
                 {  
        function HighlightTool(toolGroup, config) {
                     args: ['textStyle/highlight'],  
            ve.ui.Tool.call(this, toolGroup, config);
                     supportedSelections: ['linear', 'table']
        }
       
         OO.inheritClass(HighlightTool, ve.ui.Tool);
         HighlightTool.static.name = 'highlight';
        HighlightTool.static.group = 'textStyle';
         HighlightTool.static.icon = 'highlight';
        HighlightTool.static.title = 'Highlight text';
         HighlightTool.static.commandName = commandName;
       
        if (!ve.ui.toolFactory.lookup('highlight')) {
            ve.ui.toolFactory.register(HighlightTool);
            console.log('Highlight tool registered');
        }
       
         // --- Now check the actual toolbar structure ---
         setTimeout(function() {
             if (ve.init.target && ve.init.target.toolbar) {
                console.log('=== TOOLBAR ANALYSIS ===');
                console.log('Toolbar groups:', ve.init.target.toolbar.groups);
               
                // Check each group
                ve.init.target.toolbar.groups.forEach(function(group, index) {
                    console.log(`Group ${index}:`, {
                        name: group.name || 'unnamed',
                        type: group.constructor.name,
                        include: group.include || 'not specified',
                        exclude: group.exclude || 'not specified'
                    });
                   
                    // Check if it's a tool group with tools
                    if (group.items) {
                        console.log(`  Items in group ${index}:`, group.items.map(item => item.constructor.static.name || 'unnamed'));
                    }
                });
               
                // Check what's in the textStyle group specifically
                var textStyleGroup = ve.init.target.toolbar.groups.find(g =>
                    g.include && g.include.includes && g.include.includes('bold')
                 );
                 if (textStyleGroup) {
                     console.log('Found textStyle group:', textStyleGroup);
                     console.log('textStyle group items:', textStyleGroup.items ? textStyleGroup.items.map(i => i.constructor.static.name) : 'no items');
                 }
                 }
             }
             )
         }, 2000);
        );
 
        // 4. Register the tool (now inherits from AnnotationTool)
        ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
            ve.ui.HighlightTool.super.call(this, toolGroup, config);
        };
        OO.inheritClass(ve.ui.HighlightTool, ve.ui.AnnotationTool);
        ve.ui.HighlightTool.static.name = 'highlight';
        ve.ui.HighlightTool.static.group = 'style'; // Can now go in style group!
        ve.ui.HighlightTool.static.icon = 'highlight';
        ve.ui.HighlightTool.static.title = 'Highlight text';
         ve.ui.HighlightTool.static.annotation = { name: 'textStyle/highlight' };
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);
 
        console.log('Highlight tool registered with custom annotation.');
     });
     });
});
});

Aktuelle Version vom 5. September 2025, 13:03 Uhr

mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // 1. Define a custom annotation for highlighting
        ve.dm.HighlightAnnotation = function VeDmHighlightAnnotation() {
            ve.dm.HighlightAnnotation.super.apply(this, arguments);
        };
        OO.inheritClass(ve.dm.HighlightAnnotation, ve.dm.TextStyleAnnotation);
        ve.dm.HighlightAnnotation.static.name = 'textStyle/highlight';
        ve.dm.HighlightAnnotation.static.matchTagNames = ['mark'];
        ve.dm.annotationFactory.register(ve.dm.HighlightAnnotation);

        // 2. Define the contentEditable view for the annotation
        ve.ce.HighlightAnnotation = function VeCeHighlightAnnotation() {
            ve.ce.HighlightAnnotation.super.apply(this, arguments);
        };
        OO.inheritClass(ve.ce.HighlightAnnotation, ve.ce.TextStyleAnnotation);
        ve.ce.HighlightAnnotation.static.name = 'textStyle/highlight';
        ve.ce.HighlightAnnotation.static.tagName = 'mark';
        ve.ce.annotationFactory.register(ve.ce.HighlightAnnotation);

        // 3. Register the command to toggle the highlight
        ve.ui.commandRegistry.register(
            new ve.ui.Command(
                'insertHighlight', 
                'annotation', 
                'toggle',
                { 
                    args: ['textStyle/highlight'], 
                    supportedSelections: ['linear', 'table'] 
                }
            )
        );

        // 4. Register the tool (now inherits from AnnotationTool)
        ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
            ve.ui.HighlightTool.super.call(this, toolGroup, config);
        };
        OO.inheritClass(ve.ui.HighlightTool, ve.ui.AnnotationTool);
        ve.ui.HighlightTool.static.name = 'highlight';
        ve.ui.HighlightTool.static.group = 'style'; // Can now go in style group!
        ve.ui.HighlightTool.static.icon = 'highlight';
        ve.ui.HighlightTool.static.title = 'Highlight text';
        ve.ui.HighlightTool.static.annotation = { name: 'textStyle/highlight' };
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);

        console.log('Highlight tool registered with custom annotation.');
    });
});