Create a dialog window displaying a title, a message, and a set of buttons which trigger callback functions.

let d = new Dialog({
title: "Test Dialog",
content: "<p>You must choose either Option 1, or Option 2</p>",
buttons: {
one: {
icon: '<i class="fa-solid fa-check"></i>',
label: "Option One",
callback: () => console.log("Chose One")
},
two: {
icon: '<i class="fa-solid fa-xmark"></i>',
label: "Option Two",
callback: () => console.log("Chose Two")
}
},
default: "two",
render: html => console.log("Register interactivity in the rendered dialog"),
close: html => console.log("This always is logged no matter which option is chosen")
});
d.render(true);

since v13

Hierarchy (View Summary)

Constructors

Properties

_dragDrop: DragDrop[]

DragDrop workflow handlers which are active for this Application

_element: jQuery

An internal reference to the HTML element this application renders

_minimized: null | boolean

Track whether the Application is currently minimized

_scrollPositions: null | object

Track the most recent scroll positions for any vertically scrolling containers

_searchFilters: SearchFilter[]

SearchFilter handlers which are active for this Application

_tabs: Tabs[]

Tab navigation handlers which are active for this Application

appId: number

The application ID is a unique incrementing integer which is used to identify every application window drawn by the VTT

options: object

The options provided to this application upon initialization

position: object

Track the current position and dimensions of the Application UI

_priorState: number

The prior render state of this Application. This allows for rendering logic to understand if the application is being rendered for the first time.

_state: number

The current render state of the Application

RENDER_STATES: Readonly<
    {
        CLOSED: -1;
        CLOSING: -2;
        ERROR: -3;
        NONE: 0;
        RENDERED: 2;
        RENDERING: 1;
    },
> = ...

The sequence of rendering states that track the Application life-cycle.

Accessors

  • get closing(): boolean

    Whether the Application is currently closing.

    Returns boolean

  • get element(): jQuery

    Return the active application element, if it currently exists in the DOM

    Returns jQuery

  • get id(): string

    Return the CSS application ID which uniquely references this UI element

    Returns string

  • get popOut(): boolean

    Control the rendering style of the application. If popOut is true, the application is rendered in its own wrapper window, otherwise only the inner app content is rendered

    Returns boolean

  • get rendered(): boolean

    Return a flag for whether the Application instance is currently rendered

    Returns boolean

  • get template(): string

    The path to the HTML template file which should be used to render the inner content of the app

    Returns string

  • get title(): string

    An Application window should define its own title definition logic which may be dynamic depending on its data

    Returns string

Methods

  • Internal

    Customize how a new HTML Application is added and first appears in the DOM

    Parameters

    • html: jQuery

      The HTML element which is ready to be added to the DOM

    Returns void

  • Internal

    Additional actions to take when the application window is resized

    Parameters

    • event: Event

    Returns void

  • Internal

    Handle application minimization behavior - collapsing content and reducing the size of the header

    Parameters

    • ev: Event

    Returns void

  • Internal

    Render the inner application content

    Parameters

    • data: object

      The data used to render the inner template

    Returns Promise<jQuery>

    A promise resolving to the constructed jQuery object

  • Render the outer application wrapper

    Returns Promise<jQuery>

    A promise resolving to the constructed jQuery object

  • Internal

    Customize how inner HTML is replaced when the application is refreshed

    Parameters

    • element: jQuery

      The original HTML processed as a jQuery object

    • html: jQuery

      New updated HTML as a jQuery object

    Returns void

  • After rendering, activate event listeners which provide interactivity for the Application. This is where user-defined Application subclasses should attach their event-handling logic.

    Parameters

    • html: any

    Returns void

  • Change the currently active tab

    Parameters

    • tabName: string

      The target tab name to switch to

    • options: { group: string; triggerCallback: boolean } = {}

      Options which configure changing the tab

      • group: string

        A specific named tab group, useful if multiple sets of tabs are present

      • triggerCallback: boolean

        Whether to trigger tab-change callback functions

    Returns void

  • Bring the application to the top of the rendering stack

    Returns void

  • Close the application and un-register references to it within UI mappings This function returns a Promise which resolves once the window closing animation concludes

    Parameters

    • options: {} = {}

      Options which affect how the Application is closed

    Returns Promise<void>

    A Promise which resolves once the application is closed

    closeApplication

  • An application should define the data object used to render its template. This function may either return an Object directly, or a Promise which resolves to an Object If undefined, the default implementation will return an empty object allowing only for rendering of static HTML

    Parameters

    • _options: any

    Returns { buttons: {}; content: string }

  • Maximize the pop-out window, expanding it to its original size Take no action for applications which are not of the pop-out variety or are already maximized

    Returns Promise<void>

    A Promise which resolves once the maximization action has completed

  • Minimize the pop-out window, collapsing it to a small tab Take no action for applications which are not of the pop-out variety or apps which are already minimized

    Returns Promise<void>

    A Promise which resolves once the minimization action has completed

  • Render the Application by evaluating its HTML template against the object of data provided by the getData method If the Application is rendered as a pop-out window, wrap the contained HTML in an outer frame with window controls

    Parameters

    • force: boolean = false

      Add the rendered application to the DOM if it is not already present. If false, the Application will only be re-rendered if it is already present.

    • options: {
          focus?: boolean;
          height?: number;
          left?: number;
          renderContext?: string;
          renderData?: object;
          scale?: number;
          top?: number;
          width?: number;
      } = {}

      Additional rendering options which are applied to customize the way that the Application is rendered in the DOM.

      • Optionalfocus?: boolean

        Apply focus to the application, maximizing it and bringing it to the top of the vertical stack.

      • Optionalheight?: number

        The rendered height

      • Optionalleft?: number

        The left positioning attribute

      • OptionalrenderContext?: string

        A context-providing string which suggests what event triggered the render

      • OptionalrenderData?: object

        The data change which motivated the render request

      • Optionalscale?: number

        The rendered transformation scale

      • Optionaltop?: number

        The top positioning attribute

      • Optionalwidth?: number

        The rendered width

    Returns Application

    The rendered Application instance

  • Set the application position and store its new location. Returns the updated position object for the application containing the new values.

    Parameters

    • position: {
          height: null | string | number;
          left: null | number;
          scale: null | number;
          top: null | number;
          width: null | number;
      } = {}

      Positional data

      • height: null | string | number

        The application height in pixels

      • left: null | number

        The left offset position in pixels

      • scale: null | number

        The application scale as a numeric factor where 1.0 is default

      • top: null | number

        The top offset position in pixels

      • width: null | number

        The application width in pixels

    Returns
        | void
        | {
            height: number;
            left: number;
            scale: number;
            top: number;
            width: number;
        }

  • Submit the Dialog by selecting one of its buttons.

    Parameters

    • button: Object

      The configuration of the chosen button

    • event: PointerEvent

      The originating click event

    Returns void

  • Protected

    Activate required listeners which must be enabled on every Application. These are internal interactions which should not be overridden by downstream subclasses.

    Parameters

    • html: jQuery

    Returns void

  • Protected

    Call all hooks for all applications in the inheritance chain.

    Parameters

    • hookName: string | (className: string) => string

      The hook being triggered, which formatted with the Application class name

    • ...hookArgs: any[]

      The arguments passed to the hook calls

    Returns void

  • Protected

    Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector

    Parameters

    • selector: string

      The candidate HTML selector for the drop target

    Returns boolean

    Can the current user drop on this selector?

  • Protected

    Define whether a user is able to begin a dragstart workflow for a given drag selector

    Parameters

    • selector: string

      The candidate HTML selector for dragging

    Returns boolean

    Can the current user drag this selector?

  • Protected

    Specify the set of config buttons which should appear in the Application header. Buttons should be returned as an Array of objects. The header buttons which are added to the application can be modified by the getApplicationV1HeaderButtons hook.

    Returns ApplicationV1HeaderButton[]

    getApplicationHeaderButtons

  • Protected

    Handle changes to the active tab in a configured Tabs controller

    Parameters

    • event: null | MouseEvent

      A left click event

    • tabs: Tabs

      The Tabs controller

    • active: string

      The new active tab name

    Returns void

  • Protected

    Callback actions which occur when a dragged element is over a drop target.

    Parameters

    • event: DragEvent

      The originating DragEvent

    Returns void

  • Protected

    Callback actions which occur at the beginning of a drag start workflow.

    Parameters

    • event: DragEvent

      The originating DragEvent

    Returns void

  • Protected

    Callback actions which occur when a dragged element is dropped on a target.

    Parameters

    • event: DragEvent

      The originating DragEvent

    Returns void

  • Protected

    Handle a keydown event while the dialog is active

    Parameters

    • event: KeyboardEvent

      The keydown event

    Returns void | Promise<void>

  • Protected

    Handle changes to search filtering controllers which are bound to the Application

    Parameters

    • event: KeyboardEvent

      The key-up event from keyboard input

    • query: string

      The raw string input to the search field

    • rgx: RegExp

      The regular expression to test against

    • html: HTMLElement

      The HTML element which should be filtered

    Returns void

  • Protected

    An asynchronous inner function which handles the rendering of the Application

    Parameters

    • force: boolean = false

      Render and display the application even if it is not currently displayed.

    • options: object = {}

      Additional options which update the current values of the Application#options object

    Returns Promise<void>

    A Promise that resolves to the Application once rendering is complete

    renderApplication

  • Protected

    Restore the scroll positions of containers within the app after re-rendering the content

    Parameters

    • html: jQuery

      The HTML object being traversed

    Returns void

  • Protected

    Persist the scroll positions of containers within the app before re-rendering the content

    Parameters

    • html: jQuery

      The HTML object being traversed

    Returns void

  • Protected

    Wait for any images present in the Application to load.

    Returns Promise<void>

    A Promise that resolves when all images have loaded.

  • Internal

    Return the inheritance chain for this Application class up to (and including) it's base Application class.

    Returns Function[]

  • A helper factory method to create simple confirmation dialog windows which consist of simple yes/no prompts. If you require more flexibility, a custom Dialog instance is preferred.

    Parameters

    Returns Promise<any>

    A promise which resolves once the user makes a choice or closes the window

    let d = Dialog.confirm({
    title: "A Yes or No Question",
    content: "<p>Choose wisely.</p>",
    yes: () => console.log("You chose ... wisely"),
    no: () => console.log("You chose ... poorly"),
    defaultYes: false
    });
  • A helper factory method to display a basic "prompt" style Dialog with a single button

    Parameters

    • Optionalconfig: any = {}

      Dialog configuration options

    Returns Promise<any>

    The returned value from the provided callback function, if any

  • Wrap the Dialog with an enclosing Promise which resolves or rejects when the client makes a choice.

    Parameters

    • Optionaldata: DialogData = {}

      Data passed to the Dialog constructor.

    • Optionaloptions: ApplicationV1Options & DialogV1Options = {}

      Options passed to the Dialog constructor.

    • OptionalrenderOptions: object = {}

      Options passed to the Dialog render call.

    Returns Promise<any>

    A Promise that resolves to the chosen result.