H5PEditor.SemanticStructure = (function ($) { /** * The base of the semantic structure system. * All semantic structure class types will inherit this class. * * @class * @param {Object} field * @param {Object} defaultWidget */ function SemanticStructure(field, defaultWidget) { var self = this; // Initialize event inheritance H5P.EventDispatcher.call(self); /** * Determine this fields label. Used in error messages. * @public */ self.label = (field.label === undefined ? field.name : field.label); // Support old editor libraries self.field = {}; const id = H5PEditor.getNextFieldId(field); const descriptionId = (field.description !== undefined ? H5PEditor.getDescriptionId(id) : undefined) /** * Global instance variables. * @private */ var $widgetSelect, $wrapper, $inner, $errors, $helpText, widgets; /** * Initialize. Wrapped to avoid leaking variables * @private */ var init = function () { // Create field wrapper $wrapper = $('
', { 'class': 'field ' + field.type + ' ' + H5PEditor.createImportance(field.importance) }); /* We want to be in control of the label, description and errors containers to give the editor some structure. Also we do not provide direct access to the field object to avoid cluttering semantics.json with non-semantic properties and options. Getters and setters will be created for what is needed. */ // Create field label if (field.label !== 0) { // Add label createLabel(self.label, field.optional, id).appendTo($wrapper); } // Create description var $description; if (field.description !== undefined) { $description = $('
', { 'id': descriptionId, 'class': 'h5peditor-field-description', text: field.description, appendTo: $wrapper }); $description.html($description.html().replace('\n', '
')); } widgets = getValidWidgets(); if (widgets.length > 1) { // Create widget select box $widgetSelect = $('