var H5P = H5P || {}; /** * Constructor. * * @param {Object} params Options for this library. * @param {Number} id Content identifier * @returns {undefined} */ (function ($) { H5P.Image = function (params, id, extras) { H5P.EventDispatcher.call(this); this.extras = extras; if (params.file === undefined || !(params.file instanceof Object)) { this.placeholder = true; } else { this.source = H5P.getPath(params.file.path, id); this.width = params.file.width; this.height = params.file.height; } this.alt = (!params.decorative && params.alt !== undefined) ? params.alt : ''; if (params.title !== undefined) { this.title = params.title; } }; H5P.Image.prototype = Object.create(H5P.EventDispatcher.prototype); H5P.Image.prototype.constructor = H5P.Image; /** * Wipe out the content of the wrapper and put our HTML in it. * * @param {jQuery} $wrapper * @returns {undefined} */ H5P.Image.prototype.attach = function ($wrapper) { var self = this; var source = this.source; if (self.$img === undefined) { if(self.placeholder) { self.$img = $('
', { width: '100%', height: '100%', class: 'h5p-placeholder', title: this.title === undefined ? '' : this.title, on: { load: function () { self.trigger('loaded'); } } }); } else { self.$img = $('', { width: '100%', height: '100%', src: source, alt: this.alt, title: this.title === undefined ? '' : this.title, on: { load: function () { self.trigger('loaded'); } } }); } } $wrapper.addClass('h5p-image').html(self.$img); }; return H5P.Image; }(H5P.jQuery)); ; 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 = $('