dev

WDSIcons is a library aimed at making it easier for other script authors to use Fandom Design System icons in their scripts (demo).

Note: asset output HTML is changed to be more similar to the design system upstream:

Usage

Library usage

To use WDSIcons, attach your icon logic to the dev.wds event using mw.hook.

Importing the script

Once you've set up your script logic, you can import the library after.

// register hook before import to avoid race conditions
mw.hook('dev.wds').add(function(wds) {
    // wds is a shortcut to window.dev.wds
});

importArticle({ type: 'script', article: 'u:dev:MediaWiki:WDSIcons/code.js' });

Library methods

The library has the following keys, controlling icon usage in the library:


Asset addition

Assets can be appended directly or as variables, with support for custom attributes.

mw.hook('dev.wds').add(function(wds) {
    $('foo').append(wds.icon('pencil-small', {
        'class': 'edit'
    }));
    var bar = wds.icon('trash-small', {
        'class': 'garbage'
    });
    $('.foo').append(bar);
});

Library renderer

The library can operate on an existing section of HTML, or article content.

These are substituted with the corresponding WDS asset. The library also allows attributes on placeholders.

Article usage:

<div class="bar"><!--
 --><div class="wds-icon-small" id="dev-wds-icons-gear"><!--
 --></div>
</div>
mw.hook('dev.wds').add(function(wds) {
    wds.render('.bar');
});

Script usage:

mw.hook('dev.wds').add(function(wds) {
    $('.foo').append(
        $('<div>', {
            'id': 'dev-wds-icons-gear-small'
        })
    );
    wds.render('.foo');
});


Demo

bell
external
image
link
pages

See also

Text above can be found here (edit)