H5P Editor API
The H5P editor provides its own namespace as H5PEditor.
H5PEditor.t (library, key, vars)
Translate text strings.
Example usage from H5PEditor.Duration editor extension library.
H5PEditor.t('core', 'requiredProperty', {':property': field.name})
Parameters
library - Library machine name, or "core" for internal strings.
key - String to look up
vars - Object. Placeholder variables. Keys in this objects will be attempted replaced in the translated string with the corresponding values.
Return value
Translated string, with variable values replaced.
H5PEditor.loadLibrary (libraryName, callback)
Loads a complete library, with semantics, scripts and CSS from the server. Injects the javascript and stylesheets then returns the semantics object in the callback.
Parameters
libraryName - String. Library machine name and version on the format "macineName majorVersion.minorVersion"
callback - Function. Callback that will be called with the function semantics when loaded.
Return value
No return value
H5PEditor.processSemanticsChunk (semanticsChunk, params, $wrapper, parent)
Recursive processing of the semantics chunks.
Parameters
semanticsChunk - Array of semantics.
params - object
$wrapper - jQuery object
parent - Object.
Return value
No return value
Throws
Throws a missingProperty error if field name or field type is missing from the semantics definition.
H5PEditor.addCommonField (field, parent, params, ancestor)
Adds a field to the Common Fields container. Used internally by processSemanticsChunk.
Parameters
field -
parent -
params -
ancestor -
Return value
No return value
H5PEditor.findLibraryAncestor (parent)
Find the nearest library ancestor. Used when adding common fields.
Parameters
parent -
Return value
Returns nearest ancestor, or parent if not found.
H5PEditor.findAncestor (parent)
Find the nearest ancestor which handles commonFields.
Parameters
parent -
Return value
Nearest ancestor, or parent if commonFields already defined in the parent.
H5PEditor.removeChildren (children)
Call remove on the given children.
Parameters
children - Array of child objects to remove.
Return value
No return value
H5PEditor.findField (path, parent)
Find field from a path.
Parameters
path -
parent -
Return value
Returns the field found, or false if not found.
H5PEditor.followField (parent, path, callback)
Observe a field to get changes to its params. This is used to track changes within an object during editing in case the change needs to be reflected visually.
An example from H5PEditor.DragQuestion. This observes the "settings/background" property and changes the background of the editor if changed.
H5PEditor.followField(parent, 'settings/background', function (params) { that.setBackground(params); });
Parameters
parent - The parent object of the field.
path - Relative to the parent object.
callback - Gets called for params changes.
Return value
No return value
H5PEditor.createError (message)
Create an error paragraph with the given message.
Parameters
message - Error message to display.
Return value
Message wrapped in <p>-tags.
H5PEditor.createItem (type, content, description)
Create the HTML wrapper for field items.
Parameters
type - field type as string (ie. "text", "image", "number")
content - HTML content for the field as a string. Inserted in the wrapper.
description - Optional description text for the field. If set, it will be included beneath the field edit form.
Return value
Returns the generated HTML string.
H5PEditor.createOption (value, text, selected)
Create HTML for select options.
Parameters
value - The value of the option
text - The text for the option
selected - Boolean value. If set, the option is set as selected.
Return value
Generated HTML string for a select option.
H5PEditor.createText (value, maxLength, placeholder)
Create HTML for text input.
Parameters
value - Initial value for the text input
maxLength - Maximum number of characters
placeholder - Placeholder string shown if no value is entered.
Return value
Generated HTML for a text input field.
H5PEditor.createLabel (field, content)
Create a label to wrap content in.
Parameters
field - Semantics object for the field.
content - HTML string for content field.
Return value
Generated HTML string for the labelled field.
H5PEditor.checkErrors ($errors, $input, value)
Check if any errors have been set. Blocks tab-key on $input if $errors is not empty.
Parameters
$errors -
$input -
value -
Return value
Returns "value" if $errors is empty. Else returns false.
H5PEditor.libraryToString (library)
Translates a library object to a library string.
Parameters
library - Library object with machineName, majorVersion and minorVersion set.
Return value
String on the form "machineName majorVersion.minorVersion"
H5PEditor.htmlspecialchars (string)
Mimics a simple version of PHP htmlspecialchars. Basically replaces brackets and quotes with corresponding HTML entities.
Parameters
string - String to replace special chars.
Return value
String with special characters replaced.