Addons
Addons are H5P libraries that can be added to the H5P Editor or to certain H5P content without changing the content itself or the content type. They are a little-known feature of the H5P core and currently the only publicly known example of an addon is the H5P.MathDisplay addon, which uses MathJax to display mathematical formulas. Addons provide a simple and reusable way of customizing behavior and looks of H5P content types. This allows site administrators to customize H5P without programming knowledge or the need to fork content types.

Using addons (for site administrators)

To use an addon on your site, you must upload the addon file through the library management site. You cannot upload addons in the normal way you would upload a H5P package with content, as the .h5p files of addons don't contain any content and won't pass validation!
Depending on the configuration of the addon and your server, the addon will now be automatically loaded in certain situations. As the only addon currently is H5P.MathDisplay, the procedure of getting addons to load will be explained with it below:
Player: The MathDisplay addon will automatically be used in the player whenever needed, as the server scans content for a search string specified by the addon. You can also force the use of addons by setting the configuration property playerAddons of your configuration:
1
{
2
// ... further configuration values ...
3
"playerAddons": {
4
"H5P.CoursePresentation": ["H5P.MathDisplay"]
5
}
6
// ... further configuration values ...
7
}
Copied!
Editor: The MathDisplay addon will not be automatically enabled in the editor. There are two ways to enable it:
    1.
    Use a custom H5P.MathDisplay addon, that uses a lumieducation extension to avoid the server-wide configuration below.
    2.
    Set the configuration property editorAddons in your implementation of IH5PConfig to something like:
    1
    {
    2
    // ... further configuration values ...
    3
    "editorAddons": {
    4
    "H5P.CoursePresentation": [ "H5P.MathDisplay" ],
    5
    "H5P.InteractiveVideo": [ "H5P.MathDisplay" ],
    6
    "H5P.DragQuestion": [ "H5P.MathDisplay" ]
    7
    }
    8
    // ... further configuration values ...
    9
    }
    Copied!
    Now the editor will load the H5P.MathDisplay library if a user opens the editor of one these three content types (these are the three content types for which the PHP implementation also loads addons).

Customizing addon behavior

Addons can be configured by setting the property libraryConfig of your configuration implementation of IH5PConfig. The property is a complex object with H5P library machine names as keys. The object is sent to the H5P client (run in the browser) as part of the H5PIntegration object and can be accessed in a H5P library by calling H5P.getLibraryConfig('H5P.MachineName').
Example (shows how to (optionally) configure the H5P.MathDisplay addon):
1
"libraryConfig": {
2
"H5P.MathDisplay": {
3
"observers": [
4
{ "name": "mutationObserver", "params": { "cooldown": 500 } },
5
{ "name": "domChangedListener" },
6
{ "name": "interval", "params": { "time": 1000 } }
7
],
8
"renderer": {
9
"mathjax": {
10
"src": "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js",
11
"config": {
12
"extensions": ["tex2jax.js"],
13
"jax": ["input/TeX", "output/HTML-CSS"],
14
"tex2jax": {
15
"ignoreClass": "ckeditor",
16
"processEscapes": true
17
},
18
"messageStyle": "none"
19
}
20
}
21
}
22
}
23
}
Copied!

Creating addons (for developers)

Addons also use the .h5p file extension but don't have the same structure as regular h5p packages: they only contain folders with libraries and no h5p.json file or content. The library folders are basically like regular H5P libraries, as they contain a library.json file, but they can't contain semantics.json. The metadata in library.json is mostly the same as the metadata of normal libraries, but it contains the property addTo, which makes a library to an addon. (Check out the comprehensive structure of library metadata in the TypeScript interface ILibraryMetadata in /src/types.ts.)
A library containing the property addTo in its metadata will be automatically added to the player (or editor) by the server in certain circumstances:
    Always when loading the editor, if set in the global configuration of the server (see above).
    When playing content, only if the content contains a regex search string. The search string is set by setting this property:
    1
    {
    2
    // ... more metadata ...
    3
    "addTo": {
    4
    "content": {
    5
    "types": [
    6
    {
    7
    "text": {
    8
    "regex": "/your regex string/" // the regex string must start and end with a slash!
    9
    }
    10
    }
    11
    ]
    12
    }
    13
    }
    14
    // ... more metadata ...
    15
    }
    Copied!
    The configuration above means that the addon is added to every player instance if the regex is matched in any string property of the content parameters.
    Always when loading the editor if requested in the metadata like this:
    1
    {
    2
    // ... more metadata ...
    3
    "addTo": {
    4
    "editor": [ "H5P.CoursePresentation", "H5P.InteractiveVideo" ]
    5
    }
    6
    // ... more metadata ...
    7
    }
    Copied!
    Note that this way of enabling addons in the editor is a custom lumieducation extension of the library metadata structure and is not supported by the PHP implementation and might change in the future if this feature is implemented by Joubel's PHP implementation in another way.
    Always when loading the play if requested in the metadata like this:
    1
    {
    2
    // ... more metadata ...
    3
    "addTo": {
    4
    "player": [ "H5P.CoursePresentation", "H5P.InteractiveVideo" ]
    5
    }
    6
    // ... more metadata ...
    7
    }
    Copied!
    Note that this way of enabling addons in the player is a custom lumieducation extension of the library metadata structure and is not supported by the PHP implementation and might change in the future if this feature is implemented by Joubel's PHP implementation in another way.
When an addon is loaded in the editor or the player, the JavaScript and CSS files listed at preloadedJs and preloadedCss are loaded in the HTML file after the actual library is loaded.
Last modified 7mo ago