Wagtail client-side components
    Preparing search index...

    Adds the ability for a controlled element to dispatch an event and also add or remove classes when ready to be interacted with.

    <div class="keep-me hide-me" data-controller="w-init" data-w-init-remove-class="hide-me" data-w-init-ready-class="loaded">
    When the DOM is ready, this div will have the class 'loaded' added and 'hide-me' removed.
    </div>
    <div class="keep-me hide-me" data-controller="w-init" data-w-init-event-value="custom:event other-custom:event">
    When the DOM is ready, two additional custom events will be dispatched; `custom:event` and `other-custom:event`.
    </div>
    <article data-controller="w-init" data-w-init-detail-value='{"status": "success", "message": "Article has entered the room"}'>
    When the DOM is ready, the detail with value of a JSON object above will be dispatched.
    </article>

    Hierarchy

    Index

    Constructors

    • Parameters

      • context: Context

      Returns InitController

    Properties

    context: Context
    delayValue: number

    The delay before applying ready classes and dispatching events.

    detailValue: Record<string, unknown>

    The detail value to be dispatched with events when the element is ready.

    eventValue: string

    The custom events to be dispatched when the element is ready.

    readyClasses: string[]

    The classes to be added when the element is ready.

    removeClasses: string[]

    The classes to be removed when the element is ready.

    blessings: (<T>(constructor: Constructor<T>) => any)[]
    classes: string[] = ...
    outlets: string[]
    targets: string[]
    values: {
        delay: { default: number; type: NumberConstructor };
        detail: { default: {}; type: ObjectConstructor };
        event: { default: string; type: StringConstructor };
    } = ...

    Accessors

    • get application(): Application

      Returns Application

    • get classes(): ClassMap

      Returns ClassMap

    • get data(): DataMap

      Returns DataMap

    • get element(): ElementType

      Returns ElementType

    • get identifier(): string

      Returns string

    • get outlets(): OutletSet

      Returns OutletSet

    • get scope(): Scope

      Returns Scope

    • get targets(): TargetSet

      Returns TargetSet

    • get shouldLoad(): boolean

      Returns boolean

    Methods

    • Returns void

    • Parameters

      • eventName: string
      • Optional__namedParameters: Partial<
            {
                bubbles: boolean;
                cancelable: boolean;
                detail: Object;
                prefix: string;
                target: Element
                | Window
                | Document;
            },
        >

      Returns CustomEvent<Object>

    • Returns void

    • Add the ready classes and remove the remove classes after a delay. By default, the action will be immediate (negative value). Even when immediate, allow for a microtask delay to allow for other controllers to connect, then do any updates do classes/dispatch events. Support the ability to also dispatch custom event names.

      Returns void

    • Allow the controller to remove itself as it's no longer needed when the init has completed. Removing the controller reference and all other specific value/classes data attributes.

      Returns void

    • Parameters

      • _identifier: string
      • _application: Application

      Returns void