H5P.AdvancedText = (function ($, EventDispatcher) { /** * A simple library for displaying text with advanced styling. * * @class H5P.AdvancedText * @param {Object} parameters * @param {Object} [parameters.text='New text'] * @param {number} id */ function AdvancedText(parameters, id) { var self = this; EventDispatcher.call(this); var html = (parameters.text === undefined ? 'New text' : parameters.text); /** * Wipe container and add text html. * * @alias H5P.AdvancedText#attach * @param {H5P.jQuery} $container */ self.attach = function ($container) { $container.addClass('h5p-advanced-text').html(html); }; } AdvancedText.prototype = Object.create(EventDispatcher.prototype); AdvancedText.prototype.constructor = AdvancedText; return AdvancedText; })(H5P.jQuery, H5P.EventDispatcher); ; /** * Accordion module * * @param {jQuery} $ */ H5P.Accordion = (function ($) { var nextIdPrefix = 0; var nextLooperId = 0; var allowedLoopers = []; /** * Initialize a new Accordion * * @class H5P.InteractiveVideo * @extends H5P.EventDispatcher * @param {Object} params Behavior settings * @param {Number} contentId Content identification * @param {Object} contentData Object containing task specific content data */ function Accordion(params, contentId, contentData) { this.contentId = contentId; H5P.EventDispatcher.call(this); // Set default behavior. this.params = $.extend({}, { hTag: "h2", panels: [] }, params); this.contentData = contentData; this.instances = []; for (var i = 0; i < this.params.panels.length; i++) { this.instances[i] = H5P.newRunnable(this.params.panels[i].content, contentId); } this.idPrefix = (nextIdPrefix++) + '-'; } Accordion.prototype = Object.create(H5P.EventDispatcher.prototype); Accordion.prototype.constructor = Accordion; /** * Append field to wrapper. * @param {jQuery} container the jQuery object which this module will attach itself to. */ Accordion.prototype.attach = function ($container) { var self = this; if (self.$content === undefined) { // Mark as consumed self.triggerConsumed(); // Create the content self.elements = []; for (var i = 0; i < self.params.panels.length; i++) { self.createPanel(i); } self.$content = $(self.elements); } // Insert content $container.html('').addClass('h5p-accordion').append(self.$content); }; /** * Create HTML for Panel. * @param {number} id */ Accordion.prototype.createPanel = function (id) { var self = this; var titleId = 'h5p-panel-link-' + this.idPrefix + id; var contentId = 'h5p-panel-content-' + self.idPrefix + id; var toggleCollapse = function () { if (self.$expandedTitle === undefined || !self.$expandedTitle.is($title)) { self.collapseExpandedPanels(); self.expandPanel($title, $titleButton, $content); } else { self.collapsePanel($title, $titleButton, $content); } // We're running in an iframe, so we must animate the iframe height self.animateResize(); }; // Create panel title var $title = $('<' + this.params.hTag + '/>', { 'id': titleId, 'class': 'h5p-panel-title', }); // Create panel button var $titleButton = $('