forked from Khan/khan-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubhints.js
More file actions
30 lines (27 loc) · 1.03 KB
/
subhints.js
File metadata and controls
30 lines (27 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(function() {
var getSubHints = function(id, title, subHints) {
var str = "[<a href='#' class='show-subhint' data-subhint='" + id + "'>" + title + "</a>]</p>";
str += "<div class='subhint' id='" + id + "'>";
for (var iHint = 0; iHint < subHints.length; iHint++) {
str += "<p>" + subHints[iHint] + "</p>";
}
str += "</div>";
return str;
};
$("a.show-subhint").live("click", function(event) {
var subhint = $("#" + $(this).data("subhint"));
var visibleText = $(this).data("visible-text") || $(this).text();
var hiddenText = $(this).data("hidden-text") || "Hide explanation";
$(this).data({ "visible-text": visibleText, "hidden-text": hiddenText });
if (subhint.is(":visible")) {
$(this).text(visibleText);
} else {
$(this).text(hiddenText);
}
$("#" + $(this).data("subhint")).toggle(200);
return false;
});
$.extend(KhanUtil, {
getSubHints: getSubHints
});
})();