MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(18 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) {
     console.log('VE modules loaded');
     addPlugin(function () {
   
        // 1. Define a custom annotation for highlighting
    // --- Define the command and tool first ---
        ve.dm.HighlightAnnotation = function VeDmHighlightAnnotation() {
    function doHighlight(surface) {
            ve.dm.HighlightAnnotation.super.apply(this, arguments);
        var fragment = surface.getModel().getFragment();
         };
         var selectedText = fragment.getText();
         OO.inheritClass(ve.dm.HighlightAnnotation, ve.dm.TextStyleAnnotation);
         if (!selectedText) {
         ve.dm.HighlightAnnotation.static.name = 'textStyle/highlight';
            return;
         ve.dm.HighlightAnnotation.static.matchTagNames = ['mark'];
         }
         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() {
    var commandName = 'insertHighlight';
             ve.ce.HighlightAnnotation.super.apply(this, arguments);
   
         };
    function registerHighlightTool() {
         OO.inheritClass(ve.ce.HighlightAnnotation, ve.ce.TextStyleAnnotation);
         console.log('Attempting to register highlight tool...');
         ve.ce.HighlightAnnotation.static.name = 'textStyle/highlight';
          
         ve.ce.HighlightAnnotation.static.tagName = 'mark';
        // Register command
         ve.ce.annotationFactory.register(ve.ce.HighlightAnnotation);
        if (!ve.ui.commandRegistry.lookup(commandName)) {
 
            ve.ui.commandRegistry.register(
         // 3. Register the command to toggle the highlight
                new ve.ui.Command(
        ve.ui.commandRegistry.register(
                    commandName,
            new ve.ui.Command(
                    'content',
                'insertHighlight',
                    'exec',
                'annotation',
                    { args: [doHighlight] }
                 'toggle',
                )
                 {  
            );
                     args: ['textStyle/highlight'],
            console.log('Command registered');
                     supportedSelections: ['linear', 'table']
        }
       
         // --- 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 = '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');
            return true;
        }
         return false;
    }
   
    // Try multiple hooks
    mw.hook('ve.activationComplete').add(function () {
        console.log('ve.activationComplete fired');
        registerHighlightTool();
       
        // Wait a bit then check toolbar
        setTimeout(function() {
            console.log('Checking toolbar after delay...');
            if (typeof ve !== 'undefined' && ve.init && ve.init.target) {
                 console.log('Target exists:', ve.init.target.constructor.name);
                 if (ve.init.target.toolbar) {
                     console.log('Toolbar exists');
                     console.log('Toolbar setup:', ve.init.target.toolbar.setup);
                } else {
                    console.log('No toolbar found');
                 }
                 }
             } else {
             )
                console.log('No target found');
        );
            }
 
         }, 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.');
     });
     });
   
    // Try other possible hooks
    mw.hook('ve.toolbarSaveButton.stateChanged').add(function() {
        console.log('Toolbar save button state changed - toolbar should be ready');
    });
   
    mw.hook('ve.deactivationComplete').add(function() {
        console.log('VE deactivated');
    });
   
    // List all available ve hooks
    setTimeout(function() {
        if (typeof mw.hook._hooks !== 'undefined') {
            var veHooks = Object.keys(mw.hook._hooks).filter(hook => hook.startsWith('ve.'));
            console.log('Available VE hooks:', veHooks);
        }
    }, 1000);
});
});

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.');
    });
});