Skip to content

Commit b73dab8

Browse files
committed
MOBILE-2103 lesson: Fix buttons in legacy lessons (1.9)
1 parent ed9c02e commit b73dab8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

www/addons/mod/lesson/services/helper.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,27 @@ angular.module('mm.addons.mod_lesson')
9393
var buttons = [],
9494
rootElement = document.createElement('div'),
9595
buttonsContainer,
96-
forms;
96+
forms,
97+
isLegacy = false;
9798

9899
// Get the container of the buttons if it exists.
99100
rootElement.innerHTML = html;
100101
buttonsContainer = rootElement.querySelector('.branchbuttoncontainer');
101102

102103
if (!buttonsContainer) {
103-
// Button container not found, no buttons.
104-
return buttons;
104+
// Button container not found, might be a legacy lesson (from 1.9).
105+
if (!rootElement.querySelector('form input[type="submit"]')) {
106+
// No buttons found.
107+
return buttons;
108+
}
109+
isLegacy = true;
110+
buttonsContainer = rootElement;
105111
}
106112

107113
forms = buttonsContainer.querySelectorAll('form');
108114
angular.forEach(forms, function(form) {
109-
var buttonEl = form.querySelector('button[type="submit"]'),
115+
var buttonSelector = isLegacy ? 'input[type="submit"]' : 'button[type="submit"]',
116+
buttonEl = form.querySelector(buttonSelector),
110117
inputs = form.querySelectorAll('input'),
111118
button;
112119

@@ -117,13 +124,15 @@ angular.module('mm.addons.mod_lesson')
117124

118125
button = {
119126
id: buttonEl.id,
120-
title: buttonEl.title,
121-
content: buttonEl.innerHTML.trim(),
127+
title: buttonEl.title || buttonEl.value,
128+
content: isLegacy ? buttonEl.value : buttonEl.innerHTML.trim(),
122129
data: {}
123130
};
124131

125132
angular.forEach(inputs, function(input) {
126-
button.data[input.name] = input.value;
133+
if (input.type != 'submit') {
134+
button.data[input.name] = input.value;
135+
}
127136
});
128137

129138
buttons.push(button);

0 commit comments

Comments
 (0)