Options
All
  • Public
  • Public/Protected
  • All
Menu

A modal needs to be created only once per instance of wed. After creation it must be installed into the DOM tree of the page on which it is going to be used. The method Modal.getTopLevel must be used to get the top level DOM element of the modal which will be inserted into the page. Once inserted, the modal is ready to be used once, twice, or more times. It need not be removed, re-created, etc. The method Modal.modal just needs to be called each time the modal must be displayed.

A typical usage scenario would be:

  // Modal setup.
  mymodal = new Modal();
  mymodal.setTitle("My modal");
  mymodal.setBody(...);
  mymodal.addYesNo();
  // This is a generic example of how to add the modal to a page.
  $("body").append(mymodal.getTopLevel());

  ...

  // Modal use
  mymodal.modal(function () {...});
  switch(mymodal.getClickedAsText()) {...}

  ...

  // A second use of the same modal
  mymodal.modal(function () {...});
  switch(mymodal.getClickedAsText()) {...}

If the same modal must be displayed on two different pages, then two Modal objects should be created, one per page.

Hierarchy

  • Modal

Index

Constructors

constructor

Properties

Private _$body

_$body: JQuery

Private _$clicked

_$clicked: JQuery | undefined

Private _$dom

_$dom: JQuery

Private _$footer

_$footer: JQuery

Private _$header

_$header: JQuery

Methods

Private _handleShown

  • _handleShown(): void

addButton

  • addButton(name: string, isPrimary?: boolean): JQuery
  • Parameters

    • name: string

      The name of the button.

    • Default value isPrimary: boolean = false

      True if the button is primary. A modal takes only one primary button but no check is made by this method to prevent it. The primary button is the one clicked if the user hits enter.

    Returns JQuery

    The jQuery object for the button.

addOkCancel

  • addOkCancel(): JQuery[]
  • Adds one Ok and one Cancel button.

    Returns JQuery[]

    The two buttons added.

addYesNo

  • addYesNo(): JQuery[]
  • Adds one Yes and one No button.

    Returns JQuery[]

    The two buttons added.

getClicked

  • getClicked(): JQuery | undefined
  • Returns JQuery | undefined

    The button that was clicked. Could be undefined if the modal disappeared without being normally dismissed or if the modal has not been used yet.

getClickedAsText

  • getClickedAsText(): string | undefined
  • Returns string | undefined

    The text of the button that was clicked. Could be undefined if the modal disappeared without being normally dismissed or if the modal has not been used yet.

getPrimary

  • getPrimary(): JQuery

getTopLevel

  • getTopLevel(): JQuery
  • Returns JQuery

    The top level node of the modal, to be inserted into a page.

modal

  • modal(callback?: undefined | function): void
  • Parameters

    • Optional callback: undefined | function

      A callback to call when the modal is dismissed by the user. This modal would typically inspect the modal to determine what the user did, and potentially clean up after itself. The callback is left out if the modal is merely for informational purposes.

    Returns void

setBody

  • setBody(body: string | JQuery | Element | Text): void
  • Set the body of this modal.

    Parameters

    • body: string | JQuery | Element | Text

    Returns void

setFooter

  • setFooter(footer: string | JQuery | Element | Text): void
  • Set the footer of this modal.

    Parameters

    • footer: string | JQuery | Element | Text

    Returns void

setTitle

  • setTitle(title: string | JQuery | Element | Text): void
  • Set the title of this modal.

    Parameters

    • title: string | JQuery | Element | Text

    Returns void

Generated using TypeDoc