module:core/modal

module:core/modal

new (require("core/modal"))(root)

Source:

Constructor for the Modal.

Parameters:
Name Type Description
root HTMLElement

The HTMLElement at the root of the Modal content

Members

(inner) A :Number

Source:

counter that gets incremented for each modal created. This can be used to generate unique values for the modals.

Type:
  • Number

(inner) Module :Promise

Source:

singleton for the backdrop to be reused by all Modal instances

Type:
  • Promise

(inner) The :string

Source:

type of modal

Type:
  • string

(inner) The :string

Source:

template to use for this modal

Type:
  • string

Methods

(protected, static) _getTemplateName(modalConfig) → {string}

Source:

A helper to get the template name for this modal.

Parameters:
Name Type Description
modalConfig ModalConfig
Returns:
Type
string

(static) registerModalType()

Source:

Register a modal with the legacy modal registry.

This is provided to allow backwards-compatibility with existing code that uses the legacy modal registry. It is not necessary to register modals for code only present in Moodle 4.3 and later.

configure(param0)

Source:

Configure the modal.

Parameters:
Name Type Description
param0 ModalConfig

The configuration options

getActionSelector(action) → {DOMString}

Source:

Get the Selector for an action.

Parameters:
Name Type Description
action String
Returns:
Type
DOMString

getAttachmentPoint() → {jQuery}

Source:

Gets the jQuery wrapped node that the Modal should be attached to.

Returns:
Type
jQuery

setBodyContent(promise) → {Promise}

Source:

Alternative to setBody() that can be used from non-Jquery modules

Parameters:
Name Type Description
promise Promise

promise that returns {html, js} object

Returns:
Type
Promise

setButtonDisabled(action, disabled)

Source:

Set the a button enabled or disabled.

Parameters:
Name Type Description
action DOMString

The action of the button

disabled Boolean

the new disabled value

setButtonText(action, value) → {Promise}

Source:

Set the title text of a button.

This method is overloaded to take either a string value for the button title or a jQuery promise that is resolved with text most commonly from a Str.get_string call.

Parameters:
Name Type Description
action DOMString

The action of the button

value String | object

The button text, or a promise which will resolve to it

Returns:
Type
Promise

setRemoveOnClose(remove)

Source:

Set the flag to remove the modal from the DOM on close.

Parameters:
Name Type Description
remove Boolean

setReturnElement(element)

Source:

Set the return element for the modal.

Parameters:
Name Type Description
element Element | jQuery

Element to focus when the modal is closed

(inner) accessibilityHide()

Source:

Restores the aria visibility on the DOM elements changed when displaying the dialogue popup and makes the dialogue aria hidden to allow screen readers to navigate the main page correctly when the dialogue is closed.

(inner) accessibilityShow()

Source:

Sets the appropriate aria attributes on this dialogue and the other elements in the DOM to ensure that screen readers are able to navigate the dialogue popup correctly.

(inner) asyncSet(value, setFunction) → {Promise}

Source:

Set or resolve and set the value using the function.

Parameters:
Name Type Description
value string | object

The string or jQuery promise.

setFunction function

The setter

Returns:
Type
Promise

(inner) attachToDOM()

Source:

Attach the modal to the correct part of the page.

If it hasn't already been added it runs any javascript that has been cached until now.

(inner) calculateZIndex() → {int}

Source:

Determine the highest z-index value currently on the page.

Returns:
Type
int

(inner) countOtherVisibleModals() → {int}

Source:

Count the number of other visible modals (not including this one).

Returns:
Type
int

(inner) destroy()

Source:

Remove this modal from the DOM.

(inner) getBackdrop() → {object}

Source:

Get the modal backdrop.

Returns:

jQuery promise

Type
object

(inner) getBody() → {object}

Source:

Get the modal body element.

Returns:

jQuery object

Type
object

(inner) getBodyPromise() → {object}

Source:

Get a promise resolving to the body region.

Returns:

jQuery object

Type
object

(inner) getFooter() → {object}

Source:

Get the modal footer element.

Returns:

jQuery object

Type
object

(inner) getFooterPromise() → {object}

Source:

Get a promise resolving to the footer region.

Returns:

jQuery object

Type
object

(inner) getModal() → {object}

Source:

Get the modal element of this modal.

Returns:

jQuery object

Type
object

(inner) getModalCount() → {int}

Source:

Get the unique modal count.

Returns:
Type
int

(inner) getRoot() → {object}

Source:

Get the root element of this modal.

Returns:

jQuery object

Type
object

(inner) getTitle() → {object}

Source:

Get the modal title element.

Returns:

jQuery object

Type
object

(inner) getTitlePromise() → {Promise}

Source:

Get a promise resolving to the title region.

Returns:
Type
Promise

(inner) hasFocus() → {bool}

Source:

Check if this modal has focus.

Returns:
Type
bool

(inner) hasFooterContent() → {bool}

Source:

Check if the footer has any content in it.

Returns:
Type
bool

(inner) hasTransitions() → {bool}

Source:

Check if this modal has CSS transitions applied.

Returns:
Type
bool

(inner) hide()

Source:

Hide this modal.

(inner) hideFooter()

Source:

Hide the footer element.

(inner) hideIfNotForm()

Source:

Hide this modal if it does not contain a form.

(inner) isLarge() → {bool}

Source:

Check if the modal is a large modal.

Returns:
Type
bool

(inner) isSmall() → {bool}

Source:

Check if the modal is a small modal.

Returns:
Type
bool

(inner) isVerticallyCentered() → {bool}

Source:

Check if the modal is vertically centered.

Returns:
Type
bool

(inner) isVisible() → {bool}

Source:

Check if this modal is visible.

Returns:
Type
bool

(inner) registerCloseOnCancel()

Source:

Register a listener to close the dialogue when the cancel button is pressed.

(inner) registerCloseOnDelete()

Source:

Register a listener to close the dialogue when the delete button is pressed.

(inner) registerCloseOnSave()

Source:

Register a listener to close the dialogue when the save button is pressed.

(inner) registerEventListeners()

Source:

Set up all of the event handling for the modal.

(inner) setBody(value)

Source:

Set the modal body element.

This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with HTML and Javascript most commonly from a Templates.render call.

Parameters:
Name Type Description
value string | object

The body string or jQuery promise which resolves to the body.

Fires:

(inner) setFooter(value)

Source:

Set the modal footer element. The footer element is made visible, if it isn't already.

This method is overloaded to take either a string value for the body or a jQuery promise that is resolved with HTML and Javascript most commonly from a Templates.render call.

Parameters:
Name Type Description
value string | object

The footer string or jQuery promise

(inner) setLarge()

Source:

Mark the modal as a large modal.

(inner) setScrollable(value)

Source:

Set this modal to be scrollable or not.

Parameters:
Name Type Description
value bool

Whether the modal is scrollable or not

(inner) setSmall()

Source:

Mark the modal as a small modal.

(inner) setTitle(value)

Source:

Set the modal title element.

This method is overloaded to take either a string value for the title or a jQuery promise that is resolved with HTML most commonly from a Str.get_string call.

Parameters:
Name Type Description
value string | object

The title string or jQuery promise which resolves to the title.

(inner) setVerticallyCentered()

Source:

Mark the modal as a centered modal.

(inner) show() → {Promise}

Source:

Display this modal. The modal will be attached to the DOM if it hasn't already been.

Returns:
Type
Promise

(inner) showFooter()

Source:

Show the footer element.

Type Definitions

ModalConfig

Source:
Properties:
Name Type Attributes Default Description
type string <optional>

The type of modal to create.

title string | Promise.<string> <optional>

The title of the modal.

body string | Promise.<string> <optional>

The body of the modal.

footer string | Promise.<string> <optional>

The footer of the modal.

show boolean <optional>
false

Whether to show the modal immediately.

scrollable boolean <optional>
true

Whether the modal should be scrollable.

removeOnClose boolean <optional>
true

Whether the modal should be removed from the DOM when it is closed.

returnElement Element | jQuery <optional>

The element to focus when closing the modal.

large boolean <optional>
false

Whether the modal should be a large modal.

isVerticallyCentered boolean <optional>
false

Whether the modal should be vertically centered.

buttons object <optional>
{}

The buttons to display in the footer as a key => title pair.

A configuration to provide to the modal.

Type:
  • Object