h5p-utils
Version:
A set of utility classes and functions to be used when creating H5P widgets and content types.
69 lines (65 loc) • 1.77 kB
JavaScript
// src/utils/H5P.utils.ts
var H5P = window.H5P ?? {};
var H5PEditor = window.H5PEditor ?? {};
var getAbsoluteUrlFromRelativePath = (path) => {
return H5P.getPath(path, H5PEditor.contentId);
};
var getImageUrl = (imagePath) => {
if (!imagePath) {
return null;
}
const imagePathIsAbsolute = imagePath.startsWith("http://") || imagePath.startsWith("https://");
const imageUrl = imagePathIsAbsolute ? imagePath : getAbsoluteUrlFromRelativePath(imagePath);
return imageUrl;
};
var registerContentType = (name, contentType) => {
H5P[name] = contentType;
};
var registerWidget = (h5pName, widgetName, widget) => {
H5PEditor[h5pName] = widget;
H5PEditor.widgets[widgetName] = widget;
};
// src/models/H5PContentType.ts
var H5PContentType = class extends H5P.EventDispatcher {
constructor(params, contentId, extras) {
super();
this.params = params;
this.contentId = contentId;
this.extras = extras;
this.wrapper = document.createElement("div");
}
wrapper;
};
// src/models/H5PWidget.ts
var H5PWidget = class extends H5P.EventDispatcher {
constructor(parent, field, params, setValue) {
super();
this.parent = parent;
this.field = field;
this.params = params;
this.setValue = setValue;
this.wrapper = document.createElement("div");
}
wrapper;
};
// src/models/H5PResumableContentType.ts
var H5PResumableContentType = class extends H5PContentType {
extras;
state;
constructor(params, contentId, extras) {
super(params, contentId, extras);
this.extras = extras;
this.state = extras?.previousState;
}
};
export {
H5P,
H5PContentType,
H5PEditor,
H5PResumableContentType,
H5PWidget,
getAbsoluteUrlFromRelativePath,
getImageUrl,
registerContentType,
registerWidget
};