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 ( |      mw.hook('ve.activationComplete').add(function () { | ||
|          console.log('VisualEditor activated, adding Highlight tool...'); |          console.log('VisualEditor activated, adding Highlight tool...'); | ||
|          // ---  |          // --- 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) return; |              if (!selectedText) { | ||
|                 return; | |||
|             } | |||
|              fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}'); |              fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}'); | ||
|          } |          } | ||
|          var commandName = 'insertHighlight'; |          var commandName = 'insertHighlight'; | ||
|         // Register command | |||
|          if (!ve.ui.commandRegistry.lookup(commandName)) { |          if (!ve.ui.commandRegistry.lookup(commandName)) { | ||
|              ve.ui.commandRegistry.register( |              ve.ui.commandRegistry.register( | ||
| Zeile 23: | Zeile 26: | ||
|              ); |              ); | ||
|          } |          } | ||
|          // ---  |          // --- Define the tool --- | ||
|          function HighlightTool(toolGroup, config) { |          function HighlightTool(toolGroup, config) { | ||
|              ve.ui.Tool.call(this, 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.icon = 'highlight';  |         HighlightTool.static.group = 'textStyle'; | ||
|          HighlightTool.static.title = ' |          HighlightTool.static.icon = 'highlight'; | ||
|          HighlightTool.static.title = 'Highlight text'; | |||
|          HighlightTool.static.commandName = commandName; |          HighlightTool.static.commandName = commandName; | ||
|          if (!ve.ui.toolFactory.lookup('highlight')) { |          if (!ve.ui.toolFactory.lookup('highlight')) { | ||
|              ve.ui.toolFactory.register(HighlightTool); |              ve.ui.toolFactory.register(HighlightTool); | ||
|              console.log('Highlight tool registered'); |              console.log('Highlight tool registered'); | ||
|          } |          } | ||
|     }); | |||
|     // Also listen for when the surface is ready | |||
|     mw.hook('ve.surfaceReady').add(function () { | |||
|         console.log('Surface ready - toolbar should be available now'); | |||
|         // Now it's safe to access the toolbar | |||
|         if (ve.init.target && ve.init.target.toolbar) { | |||
|             console.log('Toolbar is available'); | |||
|              console.log('Toolbar tools:', Object.keys(ve.init.target.toolbar.tools)); | |||
|          } |          } | ||
|      }); |      }); | ||
| }); | }); | ||
Version vom 3. September 2025, 20:43 Uhr
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
    mw.hook('ve.activationComplete').add(function () {
        console.log('VisualEditor activated, adding Highlight tool...');
        
        // --- Define the command ---
        function doHighlight(surface) {
            var fragment = surface.getModel().getFragment();
            var selectedText = fragment.getText();
            if (!selectedText) {
                return;
            }
            fragment.insertContent('{{Highlight|' + selectedText + '|yellow}}');
        }
        
        var commandName = 'insertHighlight';
        
        // Register command
        if (!ve.ui.commandRegistry.lookup(commandName)) {
            ve.ui.commandRegistry.register(
                new ve.ui.Command(
                    commandName,
                    'content',
                    'exec',
                    { args: [doHighlight] }
                )
            );
        }
        
        // --- 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');
        }
    });
    // Also listen for when the surface is ready
    mw.hook('ve.surfaceReady').add(function () {
        console.log('Surface ready - toolbar should be available now');
        
        // Now it's safe to access the toolbar
        if (ve.init.target && ve.init.target.toolbar) {
            console.log('Toolbar is available');
            console.log('Toolbar tools:', Object.keys(ve.init.target.toolbar.tools));
        }
    });
});