Class: EventDispatcher

H5P. EventDispatcher

new EventDispatcher()

The base of the event system. Inherit this class if you want your H5P to dispatch events.

Methods

createXAPIEventTemplate(verb, extra) → {H5P.XAPIEvent}

Helper function to create event templates added to the EventDispatcher. Will in the future be used to add representations of the questions to the statements.
Parameters:
Name Type Argument Description
verb string Verb id in short form
extra Object <optional>
Extra values to be added to the statement
Returns:
Instance
Type
H5P.XAPIEvent

off(type, listener)

Remove event listener. If no listener is specified, all listeners will be removed.
Parameters:
Name Type Description
type string Event type
listener H5P.EventCallback Event listener
Throws:
listener must be a function
Type
TypeError

on(type, listener, thisArg)

Add new event listener.
Parameters:
Name Type Argument Description
type string Event type
listener H5P.EventCallback Event listener
thisArg Object <optional>
Optionally specify the this value when calling listener.
Throws:
listener must be a function
Type
TypeError

once(type, listener, thisArg)

Add new event listener that will be fired only once.
Parameters:
Name Type Description
type string Event type
listener H5P.EventCallback Event listener
thisArg Object Optionally specify the this value when calling listener.
Throws:
listener must be a function
Type
TypeError

trigger(event, eventData, extras)

Dispatch event.
Parameters:
Name Type Argument Description
event string | H5P.Event Event object or event type as string
eventData * <optional>
Custom event data(used when event type as string is used as first argument).
extras Object <optional>
Properties
Name Type Argument Description
bubbles boolean <optional>
external boolean <optional>

triggerXAPI(verb, extra)

Helper function for triggering xAPI added to the EventDispatcher.
Parameters:
Name Type Argument Description
verb string The short id of the verb we want to trigger
extra Oject <optional>
Extra properties for the xAPI statement

triggerXAPICompleted(score, maxScore, success)

Helper function to create xAPI completed events DEPRECATED - USE triggerXAPIScored instead
Parameters:
Name Type Description
score number Will be set as the 'raw' value of the score object
maxScore number will be set as the "max" value of the score object
success boolean will be set as the "success" value of the result object
Deprecated:
  • since 1.5, use triggerXAPIScored instead.

triggerXAPIScored(score, maxScore, verb, completion, success)

Helper function to create scored xAPI events
Parameters:
Name Type Description
score number Will be set as the 'raw' value of the score object
maxScore number Will be set as the "max" value of the score object
verb string Short form of adl verb
completion boolean Is this a statement from a completed activity?
success boolean Is this a statement from an activity that was done successfully?
Documentation generated by JSDoc 3.4.3 on 2017-02-07T13:45:43+01:00