MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus RI Wiki
Zur Navigation springenZur Suche springen
Die Seite wurde neu angelegt: „Das folgende JavaScript wird für alle Benutzer geladen.: mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () { mw.hook('ve.ui.toolFactory').add(function () { // Define a new tool function HighlightTool() { ve.ui.Tool.call(this); } OO.inheritClass(HighlightTool, ve.ui.Tool); HighlightTool.static.name = 'highlight'; HighlightTool.static.group = 'textStyle';…“
 
Keine Bearbeitungszusammenfassung
Markierung: Manuelle Zurücksetzung
 
(32 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
mw.hook('ve.loadModules').add(function (addPlugin) {
mw.loader.using('ext.visualEditor.desktopArticleTarget.init').then(function () {
     addPlugin(function () {
     mw.hook('ve.ui.toolFactory').add(function () {
         // 1. Define a custom annotation for highlighting
         // Define a new tool
         ve.dm.HighlightAnnotation = function VeDmHighlightAnnotation() {
         function HighlightTool() {
             ve.dm.HighlightAnnotation.super.apply(this, arguments);
             ve.ui.Tool.call(this);
         };
         }
         OO.inheritClass(ve.dm.HighlightAnnotation, ve.dm.TextStyleAnnotation);
         OO.inheritClass(HighlightTool, ve.ui.Tool);
        ve.dm.HighlightAnnotation.static.name = 'textStyle/highlight';
        ve.dm.HighlightAnnotation.static.matchTagNames = ['mark'];
        ve.dm.annotationFactory.register(ve.dm.HighlightAnnotation);


         HighlightTool.static.name = 'highlight';
         // 2. Define the contentEditable view for the annotation
         HighlightTool.static.group = 'textStyle';
        ve.ce.HighlightAnnotation = function VeCeHighlightAnnotation() {
         HighlightTool.static.icon = 'highlight'; // you can use 'highlight' or custom svg
            ve.ce.HighlightAnnotation.super.apply(this, arguments);
         HighlightTool.static.title = 'Highlight text';
        };
         HighlightTool.static.commandName = 'highlightCommand';
         OO.inheritClass(ve.ce.HighlightAnnotation, ve.ce.TextStyleAnnotation);
         ve.ce.HighlightAnnotation.static.name = 'textStyle/highlight';
         ve.ce.HighlightAnnotation.static.tagName = 'mark';
         ve.ce.annotationFactory.register(ve.ce.HighlightAnnotation);


        ve.ui.toolFactory.register(HighlightTool);
         // 3. Register the command to toggle the highlight
 
         // Define the command
         ve.ui.commandRegistry.register(
         ve.ui.commandRegistry.register(
             new ve.ui.Command(
             new ve.ui.Command(
                 'highlightCommand',
                 'insertHighlight',  
                 'content',
                 'annotation',  
                 'wrapAnnotation',
                 'toggle',
                 {
                 {  
                     args: [{
                     args: ['textStyle/highlight'],  
                        name: 'template',
                    supportedSelections: ['linear', 'table']  
                        data: {
                            target: {
                                href: 'Template:Highlight'
                            },
                            params: {
                                '1': '', // text will be filled in
                                '2': 'yellow' // default color
                            }
                        }
                    }]
                 }
                 }
             )
             )
         );
         );
        // 4. Register the tool (now inherits from AnnotationTool)
        ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
            ve.ui.HighlightTool.super.call(this, toolGroup, config);
        };
        OO.inheritClass(ve.ui.HighlightTool, ve.ui.AnnotationTool);
        ve.ui.HighlightTool.static.name = 'highlight';
        ve.ui.HighlightTool.static.group = 'style'; // Can now go in style group!
        ve.ui.HighlightTool.static.icon = 'highlight';
        ve.ui.HighlightTool.static.title = 'Highlight text';
        ve.ui.HighlightTool.static.annotation = { name: 'textStyle/highlight' };
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);
        console.log('Highlight tool registered with custom annotation.');
     });
     });
});
});

Aktuelle Version vom 5. September 2025, 13:03 Uhr

mw.hook('ve.loadModules').add(function (addPlugin) {
    addPlugin(function () {
        // 1. Define a custom annotation for highlighting
        ve.dm.HighlightAnnotation = function VeDmHighlightAnnotation() {
            ve.dm.HighlightAnnotation.super.apply(this, arguments);
        };
        OO.inheritClass(ve.dm.HighlightAnnotation, ve.dm.TextStyleAnnotation);
        ve.dm.HighlightAnnotation.static.name = 'textStyle/highlight';
        ve.dm.HighlightAnnotation.static.matchTagNames = ['mark'];
        ve.dm.annotationFactory.register(ve.dm.HighlightAnnotation);

        // 2. Define the contentEditable view for the annotation
        ve.ce.HighlightAnnotation = function VeCeHighlightAnnotation() {
            ve.ce.HighlightAnnotation.super.apply(this, arguments);
        };
        OO.inheritClass(ve.ce.HighlightAnnotation, ve.ce.TextStyleAnnotation);
        ve.ce.HighlightAnnotation.static.name = 'textStyle/highlight';
        ve.ce.HighlightAnnotation.static.tagName = 'mark';
        ve.ce.annotationFactory.register(ve.ce.HighlightAnnotation);

        // 3. Register the command to toggle the highlight
        ve.ui.commandRegistry.register(
            new ve.ui.Command(
                'insertHighlight', 
                'annotation', 
                'toggle',
                { 
                    args: ['textStyle/highlight'], 
                    supportedSelections: ['linear', 'table'] 
                }
            )
        );

        // 4. Register the tool (now inherits from AnnotationTool)
        ve.ui.HighlightTool = function VeUiHighlightTool(toolGroup, config) {
            ve.ui.HighlightTool.super.call(this, toolGroup, config);
        };
        OO.inheritClass(ve.ui.HighlightTool, ve.ui.AnnotationTool);
        ve.ui.HighlightTool.static.name = 'highlight';
        ve.ui.HighlightTool.static.group = 'style'; // Can now go in style group!
        ve.ui.HighlightTool.static.icon = 'highlight';
        ve.ui.HighlightTool.static.title = 'Highlight text';
        ve.ui.HighlightTool.static.annotation = { name: 'textStyle/highlight' };
        ve.ui.HighlightTool.static.commandName = 'insertHighlight';
        ve.ui.toolFactory.register(ve.ui.HighlightTool);

        console.log('Highlight tool registered with custom annotation.');
    });
});