MediaWiki:Common.js: Unterschied zwischen den Versionen
Aus RI Wiki
Zur Navigation springenZur Suche springen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
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. | 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 | // Register tool | ||
function | ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) { | ||
HighlightTool.super. | ve.ui.HighlightTool.super.call(this, toolGroup, config); | ||
} | }; | ||
OO.inheritClass(HighlightTool, ve.ui.Tool); | OO.inheritClass(ve.ui.HighlightTool, ve.ui.Tool); | ||
HighlightTool.static.name = 'highlight'; | ve.ui.HighlightTool.static.name = 'highlight'; | ||
HighlightTool.static.group = 'insert'; | ve.ui.HighlightTool.static.group = 'insert'; | ||
HighlightTool.static.icon = 'highlight'; | ve.ui.HighlightTool.static.icon = 'highlight'; | ||
HighlightTool.static.title = 'Highlight text'; | ve.ui.HighlightTool.static.title = 'Highlight text'; | ||
HighlightTool.static.commandName = 'insertHighlight'; | ve.ui.HighlightTool.static.commandName = 'insertHighlight'; | ||
ve.ui.toolFactory.register(HighlightTool); | ve.ui.toolFactory.register(ve.ui.HighlightTool); | ||
console.log('Highlight tool and command registered.'); | console.log('Highlight tool and command registered.'); | ||
}); | }); | ||
}); | }); |
Version vom 3. September 2025, 21:55 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 = 'insert';
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 and command registered.');
});
});