Skip to content

Commit 1f25121

Browse files
rfallinBenHall
authored andcommitted
PLAY-2780 | Adjusted labels for better accessibility and added more unique identifiers
1 parent 74fed67 commit 1f25121

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/marked.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,14 @@ Renderer.prototype.code = function(code, lang, escaped, attr) {
857857

858858
Renderer.prototype.quiz = function(quizTokens) {
859859
var body = "<section class='quiz'>" +" <h1>" + quizTokens.text + "</h1>";
860-
861860
body += "<form id='quiz-group-" + quizTokens.id + "'>";
862861
for (var i = 0; i < quizTokens.items.length; i++) {
863862
var e = quizTokens.items[i];
863+
var uniqueId = getRandomInt(10000);
864864
if(e.type === "text") {
865-
body += "<label for='quiz-group-" + quizTokens.id + "-" + i + "' class='incorrect'></label><input id='quiz-group-" + quizTokens.id + "-" + i + "' name='quiz-group-" + quizTokens.id + "-" + i + "' type='text' data-answer='" + (e.option || "") + "' data-value='" + e.text.toString("base64") + "' />";
865+
body += "<label for='quiz-group-" + quizTokens.id + "-" + uniqueId + "' class='incorrect'><input id='quiz-group-" + quizTokens.id + "-" + uniqueId + "' name='quiz-group-" + quizTokens.id + "-" + uniqueId + "' type='text' data-answer='" + (e.option || "") + "' data-value='" + e.text.toString("base64") + "' /></label>";
866866
} else {
867-
body += "<label for='quiz-group-" + quizTokens.id + "-" + i + "' class='incorrect'></label><input id='quiz-group-" + quizTokens.id + "-" + i + "' name='quiz-group-" + quizTokens.id + "-" + i + "' type='" + e.type + "' data-answer='" + (e.option || "") + "' />" + e.text + "</br>";
867+
body += "<label for='quiz-group-" + quizTokens.id + "-" + uniqueId + "' class='incorrect'><input id='quiz-group-" + quizTokens.id + "-" + uniqueId + "' name='quiz-group-" + quizTokens.id + "-" + uniqueId + "' type='" + e.type + "' data-answer='" + (e.option || "") + "' />" + e.text + "</label></br>";
868868
}
869869
}
870870

@@ -1382,3 +1382,7 @@ if (typeof module !== 'undefined' && typeof exports === 'object') {
13821382
}).call(function() {
13831383
return this || (typeof window !== 'undefined' ? window : global);
13841384
}());
1385+
1386+
function getRandomInt(max) {
1387+
return Math.floor(Math.random() * Math.floor(max));
1388+
}

0 commit comments

Comments
 (0)