jj
    Preparing search index...

    Class JJET<T>

    Wraps a DOM EventTarget.

    This is the base class for all JJ wrappers that wrap an EventTarget.

    Type Parameters

    • T extends EventTarget = EventTarget

    Hierarchy (View Summary)

    Index

    Constructors

    • Creates a JJET instance.

      Type Parameters

      • T extends EventTarget = EventTarget

      Parameters

      • ref: T

        The EventTarget to wrap.

      Returns JJET<T>

      If ref is not an EventTarget.

      JJET.from for the factory form.

    Accessors

    • get ref(): T

      Gets the underlying DOM object.

      Returns T

      run for fluent callbacks that can also access this same wrapped target.

    Methods

    • Removes an event listener.

      Parameters

      • eventName: string

        The name of the event.

      • handler: EventListenerOrEventListenerObject | null

        The event handler.

      • Optionaloptions: boolean | EventListenerOptions

        Optional event listener options or boolean.

      Returns this

      This instance for chaining.

      Pass the same handler reference that was used in on() to properly remove the listener.

      const onResize = () => {
      console.log('resized')
      }

      const win = JJET.from(window)
      win.on('resize', onResize)
      win.off('resize', onResize)
    • Adds an event listener.

      Parameters

      • eventName: string
      • handler: EventListenerOrEventListenerObject | null

        The event handler.

      • Optionaloptions: AddEventListenerOptions

        Optional event listener options.

      Returns this

      This instance for chaining.

      const onResize = () => {
      console.log('resized')
      }

      JJET.from(window).on('resize', onResize)
      const target = {
      dispatching a plain Event object.
      increment() {
      this.count++
      },
      }

      @param options Optional event initialization dictionary.
    • Runs a function in the context of this JJET instance.

      Parameters

      • fn: (this: this, jjContext: this) => void

        The synchronous function to run. this inside the function will refer to this JJET instance, and the wrapped instance is also passed as the first argument.

      Returns this

      This instance for chaining.

      node
      .run(function (jjContext) {
      console.log(this.ref)
      console.log(jjContext.ref)
      })
      .trigger(new Event('ready'))

      Use this to make synchronous adjustments while staying in a fluent chain. The callback return value is ignored. If you want to access the current JJ* instance using this, use a function rather than an arrow function.

      • ref for direct access to the wrapped native target.
      • on for event listener chaining.
      • trigger for dispatching events in-chain.
    • Dispatches an Event at the specified EventTarget.

      Parameters

      • event: Event

        The Event object to dispatch. Since CustomEvent extends Event, you can also dispatch CustomEvent instances here.

      Returns this

      This instance for chaining.

    • Creates a new CustomEvent and dispatches on the wrapped target.

      Type Parameters

      • T = unknown

      Parameters

      • type: string

        The event type name.

      • Optionaldetail: T

        Optional payload exposed as event.detail.

      • Optionaloptions: Omit<CustomEventInit<T>, "detail">

        Additional CustomEvent options excluding detail.

      Returns this

      This instance for chaining.

      This is a convenience wrapper around trigger for the common case of dispatching a payload-bearing custom event.

      The created event defaults to bubbles: true and composed: true. Pass options to override those defaults.

      JJET.from(window).triggerCustomEvent('panel-ready', { id: '123' })
      
      JJET.from(this).triggerCustomEvent('todo-toggle', {
      id: '123',
      done: true,
      })
    • Creates a new Event and dispatches on the wrapped target.

      Parameters

      • type: string

        The name identifying the type of the event for example 'click'

      • Optionaloptions: EventInit

        Optional event initialization dictionary.

      Returns this

      This instance for chaining.

      This is a convenience wrapper around trigger for the common case of dispatching a plain Event object.

      The created event defaults to bubbles: true and composed: true. Pass options to override those defaults.

      Event() for details on event options.

    • Creates a JJET instance from an EventTarget reference.

      Parameters

      • ref: EventTarget

        The EventTarget instance.

      Returns JJET<EventTarget>

      A new JJET instance.

      constructor for input validation behavior.