Commit d0dde4a935791253ea6f7e0e03b3d644ebc656e9

Authored by Miguel Barão
1 parent 0153d41a
Exists in master and in 1 other branch dev

- changed animations and improved submit button dynamics

Showing 1 changed file with 34 additions and 20 deletions   Show diff stats
aprendizations/static/js/topic.js
1 $.fn.extend({ 1 $.fn.extend({
2 - animateCSS: function (animation) { 2 + animateCSS: function (animation, run_on_end) {
3 var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend'; 3 var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
4 this.addClass('animated ' + animation).one(animationEnd, function() { 4 this.addClass('animated ' + animation).one(animationEnd, function() {
5 $(this).removeClass('animated ' + animation); 5 $(this).removeClass('animated ' + animation);
6 - $("#submit").removeClass("disabled"); 6 + if (run_on_end !== undefined) {
  7 + run_on_end();
  8 + }
7 }); 9 });
8 } 10 }
9 }); 11 });
@@ -13,7 +15,7 @@ function showTriesLeft(tries) { @@ -13,7 +15,7 @@ function showTriesLeft(tries) {
13 if (tries > 1) 15 if (tries > 1)
14 msg = "(" + tries + " tentativas)"; 16 msg = "(" + tries + " tentativas)";
15 else if (tries == 1) 17 else if (tries == 1)
16 - msg = "(última tentativa)"; 18 + msg = "(1 tentativa)";
17 else 19 else
18 msg = ""; 20 msg = "";
19 $("#tries").html(msg); 21 $("#tries").html(msg);
@@ -21,7 +23,9 @@ function showTriesLeft(tries) { @@ -21,7 +23,9 @@ function showTriesLeft(tries) {
21 23
22 // Get current question 24 // Get current question
23 function getQuestion() { 25 function getQuestion() {
  26 + $("#comments").html("").hide();
24 $("#submit").addClass("disabled"); 27 $("#submit").addClass("disabled");
  28 +
25 $.ajax({ 29 $.ajax({
26 type: "GET", 30 type: "GET",
27 url: "/question", 31 url: "/question",
@@ -37,6 +41,7 @@ function updateQuestion(response) { @@ -37,6 +41,7 @@ function updateQuestion(response) {
37 var params = response["params"]; 41 var params = response["params"];
38 42
39 $("#right, #wrong").hide(); 43 $("#right, #wrong").hide();
  44 +
40 switch (method) { 45 switch (method) {
41 case "new_question": 46 case "new_question":
42 new_question(params["type"], params["question"], params["tries"], params["progress"]); 47 new_question(params["type"], params["question"], params["tries"], params["progress"]);
@@ -52,13 +57,18 @@ function updateQuestion(response) { @@ -52,13 +57,18 @@ function updateQuestion(response) {
52 57
53 function new_question(type, question, tries, progress) { 58 function new_question(type, question, tries, progress) {
54 window.scrollTo(0, 0); 59 window.scrollTo(0, 0);
55 - $("#question_div").html(question).animateCSS('bounceInDown');  
56 - showTriesLeft(tries);  
57 - $("#comments").html("").hide(); 60 + $("#submit").hide();
  61 + $("#question_div").animateCSS('bounceOutUp', function() {
  62 + $("#question_div").html(question);
  63 + MathJax.typeset();
  64 + $("#question_div").animateCSS('bounceInDown', function() {
  65 + showTriesLeft(tries);
  66 + $("#submit").removeClass("disabled").show();
  67 + });
  68 + });
58 var btntext = (type == "information") ? "Continuar" : "Responder"; 69 var btntext = (type == "information") ? "Continuar" : "Responder";
59 $("#submit").html(btntext).off().click(postAnswer); 70 $("#submit").html(btntext).off().click(postAnswer);
60 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress); 71 $('#topic_progress').css('width', (100*progress)+'%').attr('aria-valuenow', 100*progress);
61 - MathJax.typeset();  
62 72
63 if (type == "radio") { 73 if (type == "radio") {
64 $(".list-group-item").click(function (e) { 74 $(".list-group-item").click(function (e) {
@@ -108,35 +118,39 @@ function getFeedback(response) { @@ -108,35 +118,39 @@ function getFeedback(response) {
108 118
109 switch (method) { 119 switch (method) {
110 case "right": 120 case "right":
  121 + $('#wrong').hide();
111 $('#comments').html(params['comments']).show(); 122 $('#comments').html(params['comments']).show();
112 $('#solution_right').html(params['solution']); 123 $('#solution_right').html(params['solution']);
113 MathJax.typeset(); 124 MathJax.typeset();
114 - $('#wrong').hide();  
115 - $('#right').show().animateCSS('zoomIn');  
116 - $("#submit").html("Continuar").off().click(getQuestion); 125 + $('#right').show().animateCSS('zoomIn', function(){
  126 + $("#submit").html("Continuar").removeClass("disabled").off().click(getQuestion);
  127 + });
117 break; 128 break;
118 129
119 case "try_again": 130 case "try_again":
120 $('#comments').html(params['comments']).show(); 131 $('#comments').html(params['comments']).show();
121 MathJax.typeset(); 132 MathJax.typeset();
122 - $('#question_div').animateCSS('shake');  
123 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); 133 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]);
124 - showTriesLeft(params["tries"]);  
125 - $("fieldset").prop("disabled", false);  
126 - $("#submit").html("Responder"); 134 + $('#question_div').animateCSS('shake', function() {
  135 + showTriesLeft(params["tries"]);
  136 + $("fieldset").prop("disabled", false);
  137 + $("#submit").html("Responder").removeClass("disabled");
  138 + });
127 break; 139 break;
128 140
129 case "wrong": 141 case "wrong":
  142 + $("fieldset").prop("disabled", true);
  143 + $('#right').hide();
130 $('#comments').html(params['comments']).show(); 144 $('#comments').html(params['comments']).show();
131 $('#solution_wrong').html(params['solution']); 145 $('#solution_wrong').html(params['solution']);
132 MathJax.typeset(); 146 MathJax.typeset();
133 - $('#right').hide();  
134 - $('#wrong').show(); //.animateCSS('zoomIn'); 147 + $('#question_div').animateCSS('shake', function() {
  148 + showTriesLeft(params["tries"]);
  149 + $('#wrong').show().animateCSS('zoomIn', function() {
  150 + $("#submit").html("Continuar").removeClass("disabled").off().click(getQuestion);
  151 + });
  152 + });
135 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]); 153 $('#topic_progress').css('width', (100*params["progress"])+'%').attr('aria-valuenow', 100*params["progress"]);
136 - showTriesLeft(params["tries"]);  
137 - $("fieldset").prop("disabled", true);  
138 - $('#question_div').animateCSS('shake');  
139 - $("#submit").html("Continuar").off().click(getQuestion);  
140 break; 154 break;
141 155
142 case "invalid": 156 case "invalid":