Fandom Developers Wiki
Advertisement

Modal library is a library for easier and faster creation and display of Fandom's built-in modals.

Usage

Importing

To import the Modal library inside your script, use:

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

The script's object won't be immediately available, but it will call a hook through mw.hook. To ensure it exists, you can use:

mw.hook('dev.modal').add(function(modal) {
    // `modal` object is the library's
    // exported object, same as window.dev.modal.
});

Exported object

The library exposes an object with several properties:

Modal
The main class of the library. Instantiating it registers the modal in the library.
AltLink
Class for the alternative link in the modal. Will be instantiated by the library but can also be instantiated manually with appropriate parameters and passed to setAltLink.
ModalButton
Class for modal's buttons.
modals
Object with all registered modals.
_init
Function called before the hook is fired as a callback for when Fandom's modal component loads.
_modal
Fandom's modal component internally used by the library.

Models

Modal

Class representing the modal object.

Parameters

id
Unique ID of the modal. This parameter is required.
context
Object that modal events should be bound to.
size
{{{models-Modal-size|Size of the modal. Accepted values are small, medium, large and content-size.
content
Content of the modal.
If set to a string, it represents the HTML the modal contains.
If set to an object while UI-js is imported, it runs the object through the dev.ui function and sets the generated HTML as the modal's content.
Note: DOM events set on the nodes through UI-js will get unregistered, as the library calls .outerHTML on the node.
title
Title of the modal. By default set to "Modal". This is safe by default unless isHTML is set, in that case it must be escaped properly.
isHTML
Whether the title of the modal is passed as HTML.
buttons
Array of objects representing parameters to the ModalButton model.
events
Events registered in the modal. These events can be called by modal buttons.
By default, Fandom's modal component registers a close event called when the close button is clicked.
class or classes
close
closeEscape
closeTitle
altLink

Properties

Methods

AltLink

Parameters

Properties

Methods

ModalButton

Parameters

Properties

Methods

Examples

Text above can be found here (edit)
Advertisement