Interface H5PEditorObject

Param: TWidgetMachineName

Typically PascalCased - MyWidget

Param: TWidgetName

Typically camelCased - myWidget

Param: TWidget

The widget class

See

https://h5p.org/node/2468

interface H5PEditorObject {
    $: JQueryStatic;
    ContentType: H5PEditorContentType;
    constants: {
        otherLibraries: string;
    };
    contentId: H5PContentId;
    isIE: boolean;
    libraryCache: Record<string, unknown>;
    libraryLoaded: Record<string, unknown>;
    loadedCallbacks: (() => void)[];
    renderableCommonFields: Record<string, unknown>;
    storage: {
        get: ((key, next) => void);
        set: ((key, value) => void);
    };
    supportedLanguages: Record<string, string>;
    widgets: Record<string, unknown>;
    addCommonField<TField>(field, parent, params, ancestor, skipAppendTo?): void;
    bindImportantDescriptionEvents(widget, fieldName, parent): void;
    canPaste(clipboard, libs): boolean;
    canPastePlus(clipboard, libs): {
        canPaste: true;
    } | {
        canPaste: false;
        description: string;
        reason: string;
    };
    checkErrors<TValue>($errors, $input, value): false | TValue;
    confirmReplace(library, top, next): void;
    createBooleanFieldMarkup(field, content, inputId?): string;
    createButton(id, title, handler, displayTitle?): JQuery<HTMLDivElement>;
    createCopyPasteButtons(): string;
    createDescription(description, inputId?): string;
    createError(message): string;
    createFieldMarkup(field, content, inputId?): string;
    createImportance<TImportance>(importance): TImportance extends H5PImportance
        ? `importance-${TImportance<TImportance>}`
        : "";
    createImportantDescription(importantDescription): string;
    createItem(type, label, description, content): string;
    createLabel(field, content?): string;
    createOption(value, text, selected?): string;
    createText(value?, maxLength?, placeholder?, id?, describedby?): string;
    enableMetadata(library): boolean;
    findAncestor(parent): undefined | H5PForm;
    findField<TField, TParent>(path, parent): false | TField;
    findLibraryAncestor(parent): undefined | H5PForm;
    findSemanticsField(fieldName, semanticsStructure): null | H5PField | H5PField[];
    followField<TField>(parent, path, callback): void;
    getDescriptionId(id): string;
    getNextFieldId(field): string;
    getParentLibrary(parent): null | H5PForm;
    getParentZebra(parent): "odd" | "even";
    getWidgetName(field): string;
    htmlspecialchars(escapedHtml): string;
    joinNonEmptyStrings(strings, separator?): string;
    libraryFromString<TLibraryName, TMajorVersion, TMinorVersion>(library): false | {
        machineName: TLibraryName;
        majorVersion: TMajorVersion;
        minorVersion: TMinorVersion;
    };
    libraryRequested<TSemantics>(libraryName, callback): void;
    libraryToString<TLib>(library): `${TLib["machineName"]} ${TLib["majorVersion"]}.${TLib["minorVersion"]}`;
    loadJs(src, doneCallback): void;
    loadLibrary<TSemantics>(libraryName, callback): void;
    processSemanticsChunk<TFields>(semanticsChunk, params, $wrapper, parent, machineName?): void;
    removeChildren(children): void;
    renderCommonField(machineName, libraries?): void;
    resetLoadedLibraries(): void;
    setCommonFieldsWrapper(parent, wrapper): void;
    t(library, key, vars?): string;
    updateCommonFieldsDefault(semantics, translation, parentIsCommon?): void;
    wrapFieldMarkup(field, markup): string;
}

Hierarchy-Diagram

UML class diagram of H5PEditorObject
Legend
icon for an interface in the UML class diagram interface
icon for a public property in the UML class diagram public property
icon for a public method in the UML class diagram public method

Hierarchy

  • Record<string, unknown>
    • H5PEditorObject

Properties

$: JQueryStatic
constants: {
    otherLibraries: string;
}

Type declaration

  • otherLibraries: string
contentId: H5PContentId
isIE: boolean
libraryCache: Record<string, unknown>
libraryLoaded: Record<string, unknown>
loadedCallbacks: (() => void)[]

Type declaration

    • (): void
    • Returns void

renderableCommonFields: Record<string, unknown>
storage: {
    get: ((key, next) => void);
    set: ((key, value) => void);
}

Type declaration

  • get: ((key, next) => void)
      • (key, next): void
      • Parameters

        • key: string
        • next: ((value) => void)
            • (value): void
            • Parameters

              • value: unknown

              Returns void

        Returns void

  • set: ((key, value) => void)
      • (key, value): void
      • Parameters

        • key: string
        • value: unknown

        Returns void

supportedLanguages: Record<string, string>
widgets: Record<string, unknown>

Methods

  • Adds a field to the Common Fields container. Used internally by H5PEditor.processSemanticsChunk.

    Type Parameters

    Parameters

    Returns void

  • Bind events to important description

    Parameters

    Returns void

  • Check if clipboard can be pasted

    Parameters

    • clipboard: {
          generic?: unknown;
      } & Record<string, unknown>
    • libs: Record<string, unknown>

    Returns boolean

  • Check if clipboard can be pasted and give reason if not.

    Parameters

    • clipboard: {
          generic?: unknown;
      } & Record<string, unknown>

      Clipboard data.

    • libs: Record<string, unknown>

      Libraries to compare against.

    Returns {
        canPaste: true;
    } | {
        canPaste: false;
        description: string;
        reason: string;
    }

    Results. {canPaste: boolean, reason: string, description: string}.

  • Check if any errors have been set. Blocks tab-key on $input if $errors is not empty.

    Type Parameters

    • TValue extends string | number | boolean | Record<string, unknown>

    Parameters

    Returns false | TValue

  • Confirm replace if there is content selected

    Parameters

    • library: string
    • top: number
    • next: (() => void)
        • (): void
        • Returns void

    Returns void

  • Create HTML wrapper for a boolean field item.

    Parameters

    • field: H5PField
    • content: string
    • Optional inputId: string

    Returns string

  • Makes it easier to add consistent buttons across the editor widget

    Parameters

    • id: string

      Typical CSS class format

    • title: string

      Human readable format

    • handler: (() => void)

      Action handler when triggered

        • (): void
        • Returns void

    • Optional displayTitle: boolean

      Show button with text. Default: false

    Returns JQuery<HTMLDivElement>

  • Generate markup for the copy and paste buttons

    Returns string

  • Create a description

    Parameters

    • description: string
    • Optional inputId: string

    Returns string

  • Create an error paragraph with the given message

    Parameters

    • message: string

      Error message to display

    Returns string

    Message wrapped in

    -tags

  • Create HTML wrapper for a field item. Replacement for createItem()

    Parameters

    • field: H5PField
    • content: string
    • Optional inputId: string

    Returns string

    Since

    1.12

  • Create an important description

    Parameters

    • importantDescription: undefined | {
          description?: string;
          example?: string;
      }

    Returns string

  • Create the HTML wrapper for field items.

    Parameters

    • type: "number" | "boolean" | "library" | "audio" | "file" | "group" | "image" | "list" | "select" | "text" | "video" | Number | Boolean | Audio | File | Group | Image | Library | List | Select | Text | Video

      Field type as string (ie. "text", "image", "number")

    • label: undefined | string

      Label text. Can be HTML

    • description: undefined | string

      Optional description text for the field. If set, it will be included beneath the field edit form

    • content: string

      HTML content for the field as a string. Inserted in the wrapper

    Returns string

    Deprecated

    since version 1.12 (Jan. 2017, will be removed Jan. 2018). Use createFieldMarkup instead.

  • Create a label to wrap content in.

    Parameters

    • field: H5PField

      Semantics object for the field

    • Optional content: string

      HTML string for content field

    Returns string

    Label as string of HTML

  • Create HTML for select options.

    Parameters

    • value: string

      The value of the option

    • text: string

      The text for the option

    • Optional selected: boolean

      If set, the option is set as selected

    Returns string

    Option as string of HTML

  • Parameters

    • Optional value: string

      Initial value for the text input

    • Optional maxLength: number

      Maximum number of characters

    • Optional placeholder: string

      Placeholder string shown if no value is entered

    • Optional id: string

      The input field's id

    • Optional describedby: string

      aria-describedby id

    Returns string

    Input field as string of HTML

  • Check if the current library is entitled for the metadata button. True by default.

    Parameters

    • library: string

      Current library.

    Returns boolean

    True, if form should have the metadata button.

  • Find the nearest ancestor which handles commonFields.

    Parameters

    Returns undefined | H5PForm

  • Find the nearest library ancestor. Used when adding common fields.

    Parameters

    Returns undefined | H5PForm

  • Search for a field or a set of fields. Returns null if the field isn't found.

    Parameters

    Returns null | H5PField | H5PField[]

  • 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.

    Type Parameters

    Parameters

    • parent: H5PForm

      The parent object of the field

    • path: string

      Relative to the parent object

    • callback: ((params) => void)

      Gets called for params changes

    Returns void

    Example

    H5PEditor.followField(parent, 'settings/background', function (params) {
    setBackground(params);
    });
  • Helps generating a consistent description ID across fields

    Parameters

    • id: string

    Returns string

  • Generates a consistent and unique field ID for the given field

    Parameters

    Returns string

  • Recursively traverse parents to find the library our field belongs to

    Parameters

    Returns null | H5PForm

  • Alternate the background color of fields

    Parameters

    Returns "odd" | "even"

    odd or even to determine background color of callee

  • Helper function for detecting field widget

    Parameters

    Returns string

  • Mimics a simple version of PHP htmlspecialchars. Basically replaces brackets and quotes with corresponding HTML entities.

    Parameters

    • escapedHtml: string

      String to replace special chars

    Returns string

    Example

    const unescapedHtml = "<h1>"Hello world"</h1>";
    const escapedHtml = H5PEditor.htmlspecialchars(unescapedHtml);
    // &lt;h1&gt;&quot;Hello world&quot;&lt;/h1&gt;
  • Joins an array of strings if they are defined and non empty

    Parameters

    • strings: (undefined | string)[]
    • Optional separator: string

      Default: " "

    Returns string

  • Private

    Helper function invoked when a library is requested. Will add CSS and eval JS if not already done.

    Type Parameters

    • TSemantics = unknown

    Parameters

    • libraryName: `${string} ${number}.${number}`

      On the form "machineName majorVersion.minorVersion"

    • callback: ((semantics) => void)
        • (semantics): void
        • Parameters

          Returns void

    Returns void

  • Translates a library object to a library string.

    Type Parameters

    • TLib extends Pick<H5PLibrary, "machineName" | "majorVersion" | "minorVersion">

    Parameters

    • library: TLib

      Library object with machineName, majorVersion and minorVersion set

    Returns `${TLib["machineName"]} ${TLib["majorVersion"]}.${TLib["minorVersion"]}`

  • Help load JavaScripts, prevents double loading

    Parameters

    • src: string
    • doneCallback: (() => void)
        • (): void
        • Returns void

    Returns void

  • 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.

    Type Parameters

    • TSemantics = unknown

    Parameters

    • libraryName: `${string} ${number}.${number}`
    • callback: ((semantics) => void)

      Callback that will be called with the library's semantics when loaded

        • (semantics): void
        • Parameters

          Returns void

    Returns void

  • Recursive processing of the semantics chunks.

    Type Parameters

    Parameters

    Returns void

  • Call remove on the given children

    Parameters

    Returns void

  • Render common fields of content type with given machine name.

    Parameters

    • machineName: string

      Machine name of content type with common fields

    • Optional libraries: H5PLibrary[]

      Library data for machine name

    Returns void

  • Reset loaded libraries - i.e removes CSS added previously

    Returns void

  • Attach ancestor of parent's common fields to a new wrapper

    Parameters

    • parent: H5PForm

      Parent content type instance that common fields should be attached to

    • wrapper: HTMLElement

      New wrapper of common fields

    Returns void

  • Translate text strings

    Parameters

    • library: string

      The library name(machineName), or "core"

    • key: string

      Translation string identifier

    • Optional vars: Record<`:${string}`, string>

      Placeholders and values to replace in the text

    Returns string

    Translated string, or a default text if the translation is missing

  • Update common fields default values for the given semantics. Works by reference.

    Parameters

    • semantics: H5PField[]
    • translation: H5PField[]
    • Optional parentIsCommon: boolean

      Used to indicated that one of the ancestors is a common field

    Returns void

  • Wraps a field with some metadata classes, and adds error field.

    Parameters

    Returns string