MediaWiki:Common.js
Aus RI Wiki
Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
mw.hook('ve.loadModules').add(function (addPlugin) {
addPlugin(function () {
// 1. Define the custom command to handle the highlight action
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) {
// Optional: Provide user feedback if no text is selected
surface.getView().flash();
return false; // Indicate the command did not execute
}
// 2. Construct the template data structure for {{Highlight|selectedText|yellow}}
var templateData = [
{
type: 'mwTransclusionInline',
attributes: {
mw: {
parts: [{
template: {
target: {
href: 'Template:Highlight',
wt: 'Highlight'
},
params: {
1: { wt: selectedText }, // The selected text
2: { wt: 'yellow' } // Default highlight color
}
}
}]
}
}
},
{ type: '/mwTransclusionInline' }
];
// 3. Replace the selected text with the template
fragment.insertContent(templateData);
return true; // Indicate successful execution
};
ve.ui.commandRegistry.register(new ve.ui.HighlightCommand());
// 4. Define and register the tool itself
ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
ve.ui.HighlightTool.super.call(this, toolGroup, config);
};
OO.inheritClass(ve.ui.HighlightTool, ve.ui.Tool);
// *** KEY CHANGE: Set group to 'style' instead of 'insert' ***
ve.ui.HighlightTool.static.name = 'highlight';
ve.ui.HighlightTool.static.group = 'style'; // Now belongs to the Style group
ve.ui.HighlightTool.static.icon = 'highlight';
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.');
});
});