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.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'; // Start with 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');
}
// Safe debugging - check if target exists
setTimeout(function() {
if (typeof ve !== 'undefined' && ve.init && ve.init.target) {
console.log('Target found:', ve.init.target.constructor.name);
if (ve.init.target.toolbar) {
console.log('Toolbar found');
// You can add more debugging here
}
} else {
console.log('Target not found yet');
}
}, 1000);
});
});