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 () { | ||
|          //  |          // Custom command for highlighting | ||
|          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 35: | Zeile 38: | ||
|                  { type: '/mwTransclusionInline' } |                  { type: '/mwTransclusionInline' } | ||
|              ]; |              ]; | ||
|              fragment.insertContent(templateData); |              fragment.insertContent(templateData); | ||
|              return true; |              return true; | ||
| Zeile 40: | Zeile 44: | ||
|          ve.ui.commandRegistry.register(new ve.ui.HighlightCommand()); |          ve.ui.commandRegistry.register(new ve.ui.HighlightCommand()); | ||
|          //  |          // Register 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); | ||
| Zeile 46: | Zeile 50: | ||
|          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'; | ||
|          ve.ui.HighlightTool.static.icon = 'marker'; //  |          ve.ui.HighlightTool.static.icon = 'marker'; // Using 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'; | ||
| Zeile 54: | Zeile 58: | ||
|          console.log('Highlight tool registered in the "style" group.'); |          console.log('Highlight tool registered in the "style" group.'); | ||
|          //  |          // Safe debugging code | ||
|          setTimeout(function() { |          setTimeout(function() { | ||
|              if (ve.init.target && ve.init.target.toolbar) { |              if (ve.init.target && ve.init.target.toolbar) { | ||
|                  var styleGroup = ve.init.target.toolbar.groups.find(g  |                  var styleGroup = ve.init.target.toolbar.groups.find(function(g) { | ||
|                  if (styleGroup) { |                     return g && g.name === 'style'; | ||
|                      console.log('Tools in style group:',  |                 }); | ||
|                  if (styleGroup && styleGroup.items) { | |||
|                     var toolNames = []; | |||
|                     for (var i = 0; i < styleGroup.items.length; i++) { | |||
|                         if (styleGroup.items[i] && styleGroup.items[i].constructor && styleGroup.items[i].constructor.static) { | |||
|                             toolNames.push(styleGroup.items[i].constructor.static.name); | |||
|                         } | |||
|                     } | |||
|                      console.log('Tools in style group:', toolNames); | |||
|                     var hasHighlightTool = toolNames.includes('highlight'); | |||
|                     console.log('Highlight tool found:', hasHighlightTool); | |||
|                     if (!hasHighlightTool) { | |||
|                         console.log('Possible reasons: tool not added to group, icon missing, or timing issue'); | |||
|                     } | |||
|                  } |                  } | ||
|              } |              } | ||
Version vom 3. September 2025, 22:05 Uhr
mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // Custom command for highlighting
        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());
        // Register 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';
        ve.ui.HighlightTool.static.icon = 'marker'; // Using 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.');
        // Safe debugging code
        setTimeout(function() {
            if (ve.init.target && ve.init.target.toolbar) {
                var styleGroup = ve.init.target.toolbar.groups.find(function(g) {
                    return g && g.name === 'style';
                });
                
                if (styleGroup && styleGroup.items) {
                    var toolNames = [];
                    for (var i = 0; i < styleGroup.items.length; i++) {
                        if (styleGroup.items[i] && styleGroup.items[i].constructor && styleGroup.items[i].constructor.static) {
                            toolNames.push(styleGroup.items[i].constructor.static.name);
                        }
                    }
                    console.log('Tools in style group:', toolNames);
                    
                    var hasHighlightTool = toolNames.includes('highlight');
                    console.log('Highlight tool found:', hasHighlightTool);
                    
                    if (!hasHighlightTool) {
                        console.log('Possible reasons: tool not added to group, icon missing, or timing issue');
                    }
                }
            }
        }, 5000);
    });
});