var H5P = H5P || {}; /** * Constructor. * * @param {object} params Options for this library. */ H5P.Text = function (params) { this.text = params.text === undefined ? 'New text' : params.text; }; /** * Wipe out the content of the wrapper and put our HTML in it. * * @param {jQuery} $wrapper */ H5P.Text.prototype.attach = function ($wrapper) { $wrapper.addClass('h5p-text').html(this.text); }; ; var H5P = H5P || {}; /** * Text Input Field module * @external {jQuery} $ H5P.jQuery */ H5P.TextInputField = (function ($) { // CSS Classes: var MAIN_CONTAINER = 'h5p-text-input-field'; var INPUT_LABEL = 'h5p-text-input-field-label'; var INPUT_FIELD = 'h5p-text-input-field-textfield'; var WRAPPER_MESSAGE = 'h5p-text-input-field-message-wrapper'; var CHAR_MESSAGE = 'h5p-text-input-field-message-char'; var ariaId = 0; /** * Initialize module. * @param {Object} params Behavior settings * @param {Number} id Content identification * @returns {Object} TextInputField TextInputField instance */ function TextInputField(params, id, contentData) { this.$ = $(this); this.id = id; this.contentData = contentData; // Set default behavior. this.params = $.extend({}, { taskDescription: 'Input field', placeholderText: '', inputFieldSize: '1', requiredField: false }, params); // Sanitize the task description as it comes in HTML this.XAPIGenerator = new H5P.TextInputField.XAPIGenerator(this.params.taskDescription.replace(/^\s+|\s+$/g, '').replace(/(

|<\/p>)/img, "")); // Set the maximum length for the textarea this.maxTextLength = (typeof this.params.maximumLength === 'undefined') ? '' : parseInt(this.params.maximumLength, 10); // Get previous state if (this.contentData !== undefined && this.contentData.previousState !== undefined) { this.previousState = this.contentData.previousState; } ariaId++; } /** * Attach function called by H5P framework to insert H5P content into page. * * @param {jQuery} $container The container which will be appended to. */ TextInputField.prototype.attach = function ($container) { var self = this; this.$inner = $container.addClass(MAIN_CONTAINER); this.$taskDescription = $('

', { id: ariaId, 'class': INPUT_LABEL + (this.params.requiredField ? ' required' : ''), 'html': self.params.taskDescription }).appendTo(self.$inner); this.$inputField = $('