Преглед изворни кода

Hints are not displayed more than one time anymore

Taddeus Kroes пре 13 година
родитељ
комит
14772ac301
1 измењених фајлова са 12 додато и 4 уклоњено
  1. 12 4
      src/frontend/js/editor.js

+ 12 - 4
src/frontend/js/editor.js

@@ -252,12 +252,14 @@
         hide_loader();
     });
 
-    function bind_request(btn, url, handler) {
+    function bind_request(btn, url, handler, condition) {
         $('#btn-' + btn).click(function() {
             var input = input_textarea.val();
 
-            if (pending_request || !$.trim(input).length)
+            if (pending_request || !$.trim(input).length
+                    || (condition && !condition())) {
                 return;
+            }
 
             show_loader();
 
@@ -276,10 +278,16 @@
         });
     }
 
+    // No need to show a hint if there is already one at the end of the
+    // calculation
+    function no_hint_displayed() {
+        return !pretty_print.children(':last').hasClass('hint');
+    }
+
     bind_request('hint', '/hint', function(response) {
         append_hint(response.hint);
         input_textarea.focus();
-    });
+    }, no_hint_displayed);
 
     bind_request('step', '/step', function(response) {
         if ('step' in response) {
@@ -287,7 +295,7 @@
             trigger_update = true;
         }
 
-        if('hint' in response)
+        if('hint' in response && no_hint_displayed())
             append_hint(response.hint);
 
         input_textarea.focus();