Replace the default WikiEditor signature button with a custom signature button: Difference between revisions

From ProWiki - Demo and Test Wiki

(add formatting)
(add Q&A)
Line 1: Line 1:
<div style="float: right">__TOC__</div>  
<div style="float: right">__TOC__</div>  
=== JavaScript ===
=== JavaScript ===
; Add the following code to the "MediaWiki:Common.js page
Add the following code to the "MediaWiki:Common.js page
<syntaxhighlight lang=javascript>
<syntaxhighlight lang=javascript>
// <nowiki>
// <nowiki>
Line 46: Line 46:
=== CSS ===
=== CSS ===
=== JavaScript ===
=== JavaScript ===
; Add the following code to the "MediaWiki:Common.js page
Add the following code to the "MediaWiki:Common.js page
<syntaxhighlight lang=javascript>
<syntaxhighlight lang=javascript>
/** WikiEditor
/** WikiEditor
Line 55: Line 55:
}
}
</syntaxhighlight>
</syntaxhighlight>
=== Q&A ===
Q: What is the difference to the default signature button?
A: This custom signature button prepends a space to the signature code in contrast to the code added by the default button, i.e. <code> --[[User:Karsten|Karsten]] ([[User talk:Karsten|talk]]) 18:04, 29 February 2024 (UTC)</code> instead of <code>--[[User:Karsten|Karsten]] ([[User talk:Karsten|talk]]) 18:04, 29 February 2024 (UTC)</code>
__NOEDITSECTION__
__NOEDITSECTION__

Revision as of 18:04, 29 February 2024

JavaScript

Add the following code to the "MediaWiki:Common.js page

// <nowiki>
var customizeToolbar = function () {
    /**
     * Add the custom signature button to the existing "main" group
     */
    $('#wpTextbox1').wikiEditor('addToToolbar', {
        section: 'main',
        group: 'insert',
        tools: {
            "customSignature": {
                label: 'Signatur einfügen',
                type: 'button',
                icon: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c0/OOjs_UI_icon_signature-ltr.svg/20px-OOjs_UI_icon_signature-ltr.svg.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: ' --~~~~',
                        post: '',
                        ownline: false
                    }
                }
            }
        }
    });
};

/**
 * Check if the view is in edit mode and the required modules are available. Then, customize the toolbar …
 */
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
    mw.loader.using('user.options').then(function () {
        if (mw.user.options.get('usebetatoolbar') == 1) {
            $.when(
                mw.loader.using('ext.wikiEditor'), $.ready
            ).then(customizeToolbar);
        }
    });
}
// </nowiki>

CSS

JavaScript

Add the following code to the "MediaWiki:Common.js page

/** WikiEditor
 * Hide the custom signature button from the existing "main" group
 */
div#wikiEditor-ui-toolbar span[rel="signature"] {
    display: none;
}

Q&A

Q: What is the difference to the default signature button? A: This custom signature button prepends a space to the signature code in contrast to the code added by the default button, i.e. --Karsten (talk) 18:04, 29 February 2024 (UTC) instead of --Karsten (talk) 18:04, 29 February 2024 (UTC)