MediaWiki:Common.js: Difference between revisions

From Trickster Development Wiki
mNo edit summary
mNo edit summary
 
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using(['ext.visualEditor.desktopArticleTarget.init'], function () {
mw.loader.using([
    'ext.visualEditor.core',
    'ext.visualEditor.desktopArticleTarget.init'
], function () {


     $(document).on('keydown', function (e) {
     // Wait until VE is actually ready
        // Ctrl + Alt + C (safer than Ctrl+Shift+C)
    mw.hook('ve.activationComplete').add(function () {
        if (e.ctrlKey && e.altKey && e.key.toLowerCase() === 'c') {


            const surface = ve.init.target.getSurface();
        const target = ve.init.target;
            if (!surface) return;
        const surface = target.getSurface();
        if (!surface) return;


             e.preventDefault();
        // Register a new command
        surface.commandRegistry.register(
            new ve.ui.Command(
                'customCode',
                'annotation',
                'toggle',
                { type: 'textStyle/code' }
            )
        );
 
        // Bind shortcut: Ctrl + Alt + C
        surface.getView().getDocument().on('keydown', function (e) {
             if (e.ctrlKey && e.altKey && e.key.toLowerCase() === 'c') {
                e.preventDefault();
                surface.execute('customCode');
            }
        });


            // Apply <code> formatting
            surface.getModel().getFragment().annotateContent('set', 'textStyle/code');
        }
     });
     });


});
});
/*That's to change the shitty Code command to Ctrl+Shift+q*/
/*That's to change the shitty Code command to Ctrl+alt+c*/

Latest revision as of 19:50, 18 April 2026

/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using([
    'ext.visualEditor.core',
    'ext.visualEditor.desktopArticleTarget.init'
], function () {

    // Wait until VE is actually ready
    mw.hook('ve.activationComplete').add(function () {

        const target = ve.init.target;
        const surface = target.getSurface();
        if (!surface) return;

        // Register a new command
        surface.commandRegistry.register(
            new ve.ui.Command(
                'customCode',
                'annotation',
                'toggle',
                { type: 'textStyle/code' }
            )
        );

        // Bind shortcut: Ctrl + Alt + C
        surface.getView().getDocument().on('keydown', function (e) {
            if (e.ctrlKey && e.altKey && e.key.toLowerCase() === 'c') {
                e.preventDefault();
                surface.execute('customCode');
            }
        });

    });

});
/*That's to change the shitty Code command to Ctrl+alt+c*/