Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Unbind empty answer handlers after each problem
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Aug 30, 2012
1 parent b7c7fb1 commit 681c185
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions khan-exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -1834,7 +1834,7 @@ var Khan = (function() {
$(Khan).trigger("newProblem");

// If the textbox is empty disable "Check Answer" button
// Note: We don't do this for number line etc.
// Note: We don't do this for multiple choice, number line, etc.
if (answerType === "text" || answerType === "number") {
var checkAnswerButton = $("#check-answer-button");
checkAnswerButton.attr("disabled", "disabled").attr(
Expand All @@ -1843,12 +1843,12 @@ var Khan = (function() {
// in a number and hit enter quickly do not have to wait for the
// button to be enabled by the key up
$("#solutionarea")
.keypress(function(e) {
.on("keypress.emptyAnswer", function(e) {
if (e.keyCode !== 13) {
checkAnswerButton.removeAttr("disabled").removeAttr("title");
}
})
.keyup(function() {
.on("keyup.emptyAnswer", function() {
validator();
if (checkIfAnswerEmpty()) {
checkAnswerButton.attr("disabled", "disabled");
Expand Down Expand Up @@ -1878,6 +1878,10 @@ var Khan = (function() {
$("#workarea, #hintsarea").runModules(problem, "Cleanup").empty();
$("#hint").attr("disabled", false);

// Take off the event handlers for disabling check answer; we'll rebind
// if we actually want them
$("#solutionarea").off(".emptyAnswer");

Khan.scratchpad.clear();
}

Expand Down

4 comments on commit 681c185

@sophiebits
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephjang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix!

Just for future reference, the bug was that the keypress and keyup event handlers were bound from the previous problem.

@sophiebits
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being comprehensible when I wasn't. :)

@beneater
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Please sign in to comment.