Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Display a right-click activated Context Menu which provides a dropdown menu of options. A ContextMenu is constructed by designating a parent HTML container and a target selector. An Array of menuItems defines the entries of the menu which is displayed.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • container: any

        The HTML element that contains the context menu targets.

      • selector: string

        A CSS selector which activates the context menu.

      • menuItems: ContextMenuEntry[]

        An Array of entries to display in the menu

      • Optionaloptions: ContextMenuOptions = {}

        Additional options to configure the context menu.

      Returns ContextMenu

    Properties

    menuItems: (ContextMenuEntry & { element: HTMLElement })[]

    The array of menu items to render.

    A function to call when the context menu is closed.

    A function to call when the context menu is opened.

    Accessors

    • get element(): HTMLElement

      The menu element.

      Returns HTMLElement

    • get eventName(): string

      The event name to listen for.

      Returns string

    • get expandUp(): boolean

      Check which direction the menu is expanded in.

      Returns boolean

    • get fixed(): boolean

      Whether to position the context menu as a fixed element, or inject it into the target.

      Returns boolean

    • get relative(): "target" | "cursor"

      For fixed context menus, control whether the menu is positioned relative to the target or to the mouse cursor. Non-fixed context menus are always positioned relative to the target.

      Returns "target" | "cursor"

    • get selector(): string

      A CSS selector to identify context menu targets.

      Returns string

    • get target(): HTMLElement

      The parent HTML element to which the context menu is attached

      Returns HTMLElement

    • get implementation(): typeof ContextMenu

      Retrieve the configured ContextMenu implementation.

      Returns typeof ContextMenu

    Methods

    • Local listeners which apply to each ContextMenu instance which is created.

      Parameters

      Returns void

    • Closes the menu and removes it from the DOM.

      Parameters

      • Optionaloptions: { animate?: boolean; target?: HTMLElement } = {}

        Options to configure the closing behavior.

        • Optionalanimate?: boolean

          Animate the context menu closing.

        • Optionaltarget?: HTMLElement

          The target element to close on.

      Returns Promise<void>

    • Render the Context Menu by iterating over the menuItems it contains. Check the visibility of each menu item, and only render ones which are allowed by the item's logical condition. Attach a click handler to each item which is rendered.

      Parameters

      • target: HTMLElement

        The target element to which the context menu is attached.

      • Optionaloptions: ContextMenuRenderOptions = {}

      Returns Promise<void>

      A Promise that resolves when the open animation has completed.

    • Protected

      Animate the context menu's height when opening or closing.

      Parameters

      • open: boolean = false

        Whether the menu is opening or closing.

      Returns Promise<void>

      A Promise that resolves when the animation completes.

    • Protected

      Close the menu and remove it from the DOM.

      Parameters

      • Optionaloptions: { target?: HTMLElement } = {}
        • Optionaltarget?: HTMLElement

          The target element to close on.

      Returns void

    • Protected

      Inject the menu inside the target.

      Parameters

      • menu: HTMLElement

        The menu element.

      • target: HTMLElement

        The context target.

      Returns void

    • Protected

      Handle context menu activation.

      Parameters

      • event: Event

        The triggering event.

      Returns Promise<void> | undefined

    • Protected

      Called after the context menu has finished rendering its entries.

      Parameters

      Returns Promise<void>

    • Protected

      Called before the context menu begins rendering.

      Parameters

      Returns Promise<void>

    • Protected

      Set the context menu at a fixed position in the viewport.

      Parameters

      • menu: HTMLElement

        The menu element.

      • target: HTMLElement

        The context target.

      • Optionaloptions: { event?: Event } = {}
        • Optionalevent?: Event

          The event that triggered the context menu opening.

      Returns void

    • Protected

      Set the position of the context menu, taking into consideration whether the menu should expand upward or downward

      Parameters

      • menu: HTMLElement

        The context menu element.

      • target: HTMLElement

        The element that the context menu was spawned on.

      • Optionaloptions: { event?: Event } = {}
        • Optionalevent?: Event

          The event that triggered the context menu opening.

      Returns void

    • Bind global context menu listeners to a given document.

      Parameters

      • document: Document

        The document.

      • __namedParameters: { _deprecated?: boolean } = {}

      Returns void

    • Create a ContextMenu for this Application and dispatch hooks.

      Parameters

      • app: Application

        The Application this ContextMenu belongs to.

      • html: any

        The Application's rendered HTML.

      • selector: string

        The target CSS selector which activates the menu.

      • menuItems: ContextMenuEntry[]

        The array of menu items being rendered.

      • Optionaloptions: { hookName?: string } = {}

        Additional options to configure context menu initialization.

        • OptionalhookName?: string

          The name of the hook to call.

      Returns ContextMenu

      since v13