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 () {
     console.log('VE modules loaded');
        console.log('VisualEditor activated, adding Highlight tool...');
   
       
    // --- Define the command and tool first ---
        // --- Define the 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';
   
    function registerHighlightTool() {
        console.log('Attempting to register highlight tool...');
          
          
         // Register command
         // Register command
Zeile 25: Zeile 27:
                 )
                 )
             );
             );
            console.log('Command registered');
         }
         }
          
          
Zeile 42: Zeile 45:
             ve.ui.toolFactory.register(HighlightTool);
             ve.ui.toolFactory.register(HighlightTool);
             console.log('Highlight tool registered');
             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);
     });
     });
        ve.init.target.toolbar.groups.forEach(function(group, index) {
   
         console.log('Group', index, ':', group.name, group.type);
    // Try other possible hooks
        if (group.tools) {
    mw.hook('ve.toolbarSaveButton.stateChanged').add(function() {
            console.log(' Tools:', group.tools.map(tool => tool.constructor.static.name));
         console.log('Toolbar save button state changed - toolbar should be ready');
        }
    });
   
    mw.hook('ve.deactivationComplete').add(function() {
        console.log('VE deactivated');
     });
     });
 
   
     // Also listen for when the surface is ready
     // List all available ve hooks
     mw.hook('ve.surfaceReady').add(function () {
     setTimeout(function() {
         console.log('Surface ready - toolbar should be available now');
         if (typeof mw.hook._hooks !== 'undefined') {
       
            var veHooks = Object.keys(mw.hook._hooks).filter(hook => hook.startsWith('ve.'));
        // Now it's safe to access the toolbar
             console.log('Available VE hooks:', veHooks);
        if (ve.init.target && ve.init.target.toolbar) {
            console.log('Toolbar is available');
             console.log('Toolbar tools:', Object.keys(ve.init.target.toolbar.tools));
         }
         }
     });
     }, 1000);
});
});

Version vom 3. September 2025, 20:56 Uhr

mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
    console.log('VE modules loaded');
    
    // --- Define the command and tool first ---
    function doHighlight(surface) {
        var fragment = surface.getModel().getFragment();
        var selectedText = fragment.getText();
        if (!selectedText) {
            return;
        }
        fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
    }
    
    var commandName = 'insertHighlight';
    
    function registerHighlightTool() {
        console.log('Attempting to register highlight tool...');
        
        // Register command
        if (!ve.ui.commandRegistry.lookup(commandName)) {
            ve.ui.commandRegistry.register(
                new ve.ui.Command(
                    commandName,
                    'content',
                    'exec',
                    { args: [doHighlight] }
                )
            );
            console.log('Command registered');
        }
        
        // --- 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);
    });
    
    // 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);
});