dev

Placement is a library for script placement. It makes placement customization much easier, standardizes selectors, and creates the My Tools menu if necessary.

Usage

Importing

To import and use the Placement library inside your script, use the following:

mw.hook('dev.placement').add(function (placement) {
    // your code here
});
importArticle({
    type: 'script',
    article: 'u:dev:MediaWiki:Placement.js'
});

Methods

The library exports an object (window.dev.placement.loader) with the following properties:

Examples

Prepends link to My Tools menu
mw.hook('dev.placement').add(function (placement) {
    placement.script('ToolsMenuLink');
    $(placement.element('tools'))[placement.type('prepend')](
        $('<li>').append(
            $('<a>', {
                text: 'hello'
            })
        )
    );
});
Inserts link after custom element
mw.hook('dev.placement').add(function (placement) {
    placement.script('CustomExampleLink');
    $('<li>').append(
        $('<a>', {
            text: 'hello'
        })
    )[placement.type('insertAfter')](placement.custom('.global-navigation__bottom .wds-list li:nth-child(2)'));
});
Prepends link to My Tools menu using util
mw.hook('dev.placement').add(function (placement) {
    placement.util({
        script: 'ToolsMenuLink',
        element: 'tools',
        type: 'prepend',
        content: $('<li>').append(
            $('<a>', {
                text: 'hello'
            })
        )
    });
});

Customization

To customize a script's placement, first make sure that it uses this script. Then, start by exposing the global object.

window.dev = window.dev || {};
window.dev.placement = window.dev.placement || {};

Then specify your configuration, using element to determine where the script should be placed and type to change how the script is added (e.g. appended/prepended). The element parameter supports all excepted values for placement.element(), which are listed here, as well as custom selectors.

window.dev.placement['ScriptName'] = {
    element: 'tools',
    type: 'prepend'
};

For example, to move AjaxBatchDelete to the bottom of the edit dropdown, use the following:

window.dev = window.dev || {};
window.dev.placement = window.dev.placement || {};
window.dev.placement['AjaxBatchDelete'] = {
    element: 'editdropdown',
    type: 'append'
};
Text above can be found here (edit)