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 1: | Zeile 1: | ||
| mw.hook('ve.loadModules').add(function (addPlugin) { | mw.hook('ve.loadModules').add(function (addPlugin) { | ||
|      addPlugin(function () { |      addPlugin(function () { | ||
|          //  |          // Define and register the command | ||
|          ve.ui.HighlightCommand = function VeUiHighlightCommand() { |          ve.ui.HighlightCommand = function VeUiHighlightCommand() { | ||
|              ve.ui.HighlightCommand.super.call(this, 'insertHighlight'); |              ve.ui.HighlightCommand.super.call(this, 'insertHighlight'); | ||
|          }; |          }; | ||
|          OO.inheritClass(ve.ui.HighlightCommand, ve.ui.Command); |          OO.inheritClass(ve.ui.HighlightCommand, ve.ui.Command); | ||
|          ve.ui.HighlightCommand.prototype.execute = function (surface) { |          ve.ui.HighlightCommand.prototype.execute = function (surface) { | ||
|              var fragment = surface.getModel().getFragment(); |              var fragment = surface.getModel().getFragment(); | ||
|              var selectedText = fragment.getText(); |              var selectedText = fragment.getText(); | ||
|              if (!selectedText) { |              if (!selectedText) { | ||
|                  surface.getView().flash(); |                  surface.getView().flash(); | ||
|                  return false;  |                  return false; | ||
|              } |              } | ||
|              var templateData = [ |              var templateData = [ | ||
|                  { |                  { | ||
| Zeile 30: | Zeile 25: | ||
|                                      }, |                                      }, | ||
|                                      params: { |                                      params: { | ||
|                                          1: { wt: selectedText },  |                                          1: { wt: selectedText }, | ||
|                                          2: { wt: 'yellow' }  |                                          2: { wt: 'yellow' } | ||
|                                      } |                                      } | ||
|                                  } |                                  } | ||
| Zeile 40: | Zeile 35: | ||
|                  { type: '/mwTransclusionInline' } |                  { type: '/mwTransclusionInline' } | ||
|              ]; |              ]; | ||
|              fragment.insertContent(templateData); |              fragment.insertContent(templateData); | ||
|              return true;  |              return true; | ||
|          }; |          }; | ||
|          ve.ui.commandRegistry.register(new ve.ui.HighlightCommand()); |          ve.ui.commandRegistry.register(new ve.ui.HighlightCommand()); | ||
|          //  |          // Define and register the tool | ||
|          ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) { |          ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) { | ||
|              ve.ui.HighlightTool.super.call(this, toolGroup, config); |              ve.ui.HighlightTool.super.call(this, toolGroup, config); | ||
|          }; |          }; | ||
|          OO.inheritClass(ve.ui.HighlightTool, ve.ui.Tool); |          OO.inheritClass(ve.ui.HighlightTool, ve.ui.Tool); | ||
|          ve.ui.HighlightTool.static.name = 'highlight'; |          ve.ui.HighlightTool.static.name = 'highlight'; | ||
|          ve.ui.HighlightTool.static.group = 'style'; //  |          ve.ui.HighlightTool.static.group = 'style'; // Correct group for formatting | ||
|          ve.ui.HighlightTool.static.icon = ' |          ve.ui.HighlightTool.static.icon = 'marker'; // Use a standard icon | ||
|          ve.ui.HighlightTool.static.title = 'Highlight text'; |          ve.ui.HighlightTool.static.title = 'Highlight text'; | ||
|          ve.ui.HighlightTool.static.commandName = 'insertHighlight'; |          ve.ui.HighlightTool.static.commandName = 'insertHighlight'; | ||
|          ve.ui.toolFactory.register(ve.ui.HighlightTool); |          ve.ui.toolFactory.register(ve.ui.HighlightTool); | ||
|          console.log('Highlight tool registered in the "style" group.'); |          console.log('Highlight tool registered in the "style" group.'); | ||
|         // Debug: Log after a delay to check registration | |||
|         setTimeout(function() { | |||
|             if (ve.init.target && ve.init.target.toolbar) { | |||
|                 var styleGroup = ve.init.target.toolbar.groups.find(g => g.name === 'style'); | |||
|                 if (styleGroup) { | |||
|                     console.log('Tools in style group:', styleGroup.items.map(item => item.constructor.static.name)); | |||
|                 } | |||
|             } | |||
|         }, 5000); | |||
|      }); |      }); | ||
| }); | }); | ||
Version vom 3. September 2025, 22:03 Uhr
mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // Define and register the command
        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());
        // Define and register the 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 = 'style'; // Correct group for formatting
        ve.ui.HighlightTool.static.icon = 'marker'; // Use a standard icon
        ve.ui.HighlightTool.static.title = 'Highlight text';
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);
        console.log('Highlight tool registered in the "style" group.');
        // Debug: Log after a delay to check registration
        setTimeout(function() {
            if (ve.init.target && ve.init.target.toolbar) {
                var styleGroup = ve.init.target.toolbar.groups.find(g => g.name === 'style');
                if (styleGroup) {
                    console.log('Tools in style group:', styleGroup.items.map(item => item.constructor.static.name));
                }
            }
        }, 5000);
    });
});