Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HFP-4136 Use H5P.Column for content #41

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions h5p-accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ H5P.Accordion = (function ($) {
this.instances = [];

for (var i = 0; i < this.params.panels.length; i++) {
this.instances[i] = H5P.newRunnable(this.params.panels[i].content, contentId);
this.instances[i] = H5P.newRunnable(this.params.panels[i], contentId);

// Bubble resize events
this.bubbleUp(this.instances[i], 'resize', this);
}

this.idPrefix = (nextIdPrefix++) + '-';

// Resize children to fit inside parent
this.bubbleDown(this, 'resize', this.instances);
}

Accordion.prototype = Object.create(H5P.EventDispatcher.prototype);
Expand Down Expand Up @@ -86,6 +92,12 @@ H5P.Accordion = (function ($) {
self.animateResize();
};

// Retrieve title from Column metadata
const title = (
self.params.panels[id].metadata &&
self.params.panels[id].metadata.title
) ? self.params.panels[id].metadata.title : 'Unknown: Panel';

// Create panel title
var $title = $('<' + this.params.hTag + '/>', {
'id': titleId,
Expand All @@ -98,7 +110,7 @@ H5P.Accordion = (function ($) {
'tabindex': '0',
'aria-expanded': 'false',
'aria-controls': contentId,
'html': self.params.panels[id].title,
'html': title,
'on': {
'click': toggleCollapse,
'keydown': function (event) {
Expand Down Expand Up @@ -288,5 +300,46 @@ H5P.Accordion = (function ($) {
return allowedLoopers.indexOf(myId) !== -1;
};

/**
* Bubble events from parent to children.
*
* @private
* @param {object} origin Origin of Event.
* @param {string} eventName Name of Event.
* @param {object[]} targets Targets to trigger event on.
*/
Accordion.prototype.bubbleDown = function (origin, eventName, targets) {
origin.on(eventName, function (event) {
if (origin.bubblingUpwards) {
return; // Prevent send event back down.
}

for (var i = 0; i < targets.length; i++) {
targets[i].trigger(eventName, event);
}
});
}

/**
* Bubble events from child to parent.
*
* @private
* @param {object} origin Origin of Event.
* @param {string} eventName Name of Event.
* @param {object} target Target to trigger event on.
*/
Accordion.prototype.bubbleUp = function (origin, eventName, target) {
origin.on(eventName, function (event) {
// Prevent target from sending event back down
target.bubblingUpwards = true;

// Trigger event
target.trigger(eventName, event);

// Reset
target.bubblingUpwards = false;
});
}

return Accordion;
})(H5P.jQuery);
13 changes: 2 additions & 11 deletions language/.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "panel",
"field": {
"label": "Content",
"entity": "content",
"fields": [
{
"label": "Title"
},
{
"label": "Content type",
"entity": "content"
}
]
"entity": "content"
}
},
{
Expand All @@ -33,4 +24,4 @@
]
}
]
}
}
19 changes: 5 additions & 14 deletions language/af.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
{
"semantics": [
{
"label": "Panele",
"entity": "paneel",
"field": {
"label": "Inhoud",
"entity": "inhoud",
"fields": [
{
"label": "Titel"
},
{
"label": "Inhoud tipe",
"entity": "inhoud"
}
]
"label":"Panele",
"entity":"paneel",
"field":{
"label":"Inhoud",
"entity":"inhoud"
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions language/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "لوحه",
"field": {
"label": "المحتوي",
"entity": "المحتوي",
"fields": [
{
"label": "عنوان فصل"
},
{
"label": "نوع المحتوى",
"entity": "المحتوى"
}
]
"entity": "المحتوي"
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions language/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "panel",
"field": {
"label": "Съдържание",
"entity": "content",
"fields": [
{
"label": "Заглавие"
},
{
"label": "Тип съдържание",
"entity": "content"
}
]
"entity": "content"
}
},
{
Expand Down
13 changes: 2 additions & 11 deletions language/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity":"panel",
"field":{
"label":"Content",
"entity":"content",
"fields":[
{
"label":"Title"
},
{
"label":"Content type",
"entity":"content"
}
]
"entity":"content"
}
},
{
Expand All @@ -33,4 +24,4 @@
]
}
]
}
}
15 changes: 3 additions & 12 deletions language/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,9 @@
{
"label": "Taulers",
"entity": "tauler",
"field": {
"label": "Contingut",
"entity": "contingut",
"fields": [
{
"label": "Títol"
},
{
"label": "Tipus de contingut",
"entity": "contingut"
}
]
"field":{
"label":"Contingut",
"entity":"contingut"
}
},
{
Expand Down
19 changes: 5 additions & 14 deletions language/cs.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
{
"semantics": [
{
"label": "Panely",
"entity": "panel",
"field": {
"label": "Obsah",
"entity": "obsah",
"fields": [
{
"label": "Nadpis"
},
{
"label": "Typ obsahu",
"entity": "obsah"
}
]
"label":"Panely",
"entity":"panel",
"field":{
"label":"Obsah",
"entity":"obsah"
}
},
{
Expand Down
13 changes: 2 additions & 11 deletions language/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity":"panel",
"field":{
"label":"Content",
"entity":"content",
"fields":[
{
"label":"Title"
},
{
"label":"Content type",
"entity":"content"
}
]
"entity":"content"
}
},
{
Expand All @@ -33,4 +24,4 @@
]
}
]
}
}
11 changes: 1 addition & 10 deletions language/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "Abschnitt",
"field": {
"label": "Inhalt",
"entity": "Inhalt",
"fields": [
{
"label": "Titel"
},
{
"label": "Inhaltstyp",
"entity": "Inhalt"
}
]
"entity": "Inhalt"
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions language/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity":"πλαισιου",
"field":{
"label":"Περιεχόμενο",
"entity":"περιεχομενου",
"fields":[
{
"label":"Τίτλος"
},
{
"label":"Τύπος περιεχομένου",
"entity":"περιεχομενου"
}
]
"entity":"περιεχομενου"
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions language/es-mx.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "panel",
"field": {
"label": "Contenido",
"entity": "contenido",
"fields": [
{
"label": "Título"
},
{
"label": "Tipo de contenido",
"entity": "contenido"
}
]
"entity": "contenido"
}
},
{
Expand Down
11 changes: 1 addition & 10 deletions language/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "panel",
"field": {
"label": "Contenido",
"entity": "contenido",
"fields": [
{
"label": "Título"
},
{
"label": "Tipo de contenido",
"entity": "contenido"
}
]
"entity": "contenido"
}
},
{
Expand Down
13 changes: 2 additions & 11 deletions language/et.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity":"paneel",
"field":{
"label":"Sisu",
"entity":"sisu",
"fields":[
{
"label":"Pealkiri"
},
{
"label":"Sisu tüüp",
"entity":"sisu"
}
]
"entity":"sisu"
}
},
{
Expand All @@ -33,4 +24,4 @@
]
}
]
}
}
11 changes: 1 addition & 10 deletions language/eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,7 @@
"entity": "panela",
"field": {
"label": "Edukia",
"entity": "edukia",
"fields": [
{
"label": "Izenburua"
},
{
"label": "Eduki mota",
"entity": "edukia"
}
]
"entity": "edukia"
}
},
{
Expand Down
Loading