Any class that implements this interface can be used as a widget in H5P.
It defines the methods that are required for a widget to work: appendTo,
validate and remove.
appendTo is called when the widget is added to the DOM.
It provides the container element as a jQuery object.
It is crucial to add the widget to the container element.
validate is called in certain cases by the H5P framework to check if the
widget is valid, for instance when the user collapses the dropdown that the
widget belongs in. If the widget is not valid, the dropdown will not collapse.
remove is called when the widget is removed from the DOM.
Here you should remove any global event listeners that you have added to avoid
memory leaks.
It is recommended to use the H5PWidget class from h5p-utils as a base class
for your widget. It sets up the widget and adds the constructor parameters as
properties on the class. It also extends the H5P.EventDispatcher class, which
allows you to use the trigger and on methods to trigger and listen to events.
⚠️ If you decide not to extend the H5PWidget class, you will have to extend
H5P.EventDispatcher yourself.
Any class that implements this interface can be used as a widget in H5P. It defines the methods that are required for a widget to work:
appendTo
,validate
andremove
.appendTo
is called when the widget is added to the DOM. It provides the container element as a jQuery object. It is crucial to add the widget to the container element.validate
is called in certain cases by the H5P framework to check if the widget is valid, for instance when the user collapses the dropdown that the widget belongs in. If the widget is not valid, the dropdown will not collapse.remove
is called when the widget is removed from the DOM. Here you should remove any global event listeners that you have added to avoid memory leaks.It is recommended to use the
H5PWidget
class fromh5p-utils
as a base class for your widget. It sets up the widget and adds the constructor parameters as properties on the class. It also extends theH5P.EventDispatcher
class, which allows you to use thetrigger
andon
methods to trigger and listen to events.⚠️ If you decide not to extend the
H5PWidget
class, you will have to extendH5P.EventDispatcher
yourself.Example