diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/codeq/hint.js | 13 | ||||
-rw-r--r-- | js/codeq/prolog.js | 15 | ||||
-rw-r--r-- | js/codeq/python.js | 13 |
3 files changed, 37 insertions, 4 deletions
diff --git a/js/codeq/hint.js b/js/codeq/hint.js index 06eceb0..c06aef7 100644 --- a/js/codeq/hint.js +++ b/js/codeq/hint.js @@ -7,9 +7,10 @@ var firstCharacterPos = {'line': 0, 'ch': 0}, sel_no_scroll = {'scroll': false}; - codeq.makeHinter = function (jqHints, jqEditor, editor, hintDefs) { + codeq.makeHinter = function (jqHints, jqEditor, editor, hintDefs, planDef) { var hintCounter = 0, // for generating unique class-names hintCleaners = [], + planIdx = 0, clearHints = function () { var i; @@ -124,6 +125,16 @@ }; return { + /** Display the next "planning" hint and return whether there are + * any more available. + */ + 'planNext': function () { + if (planIdx < planDef.length) { + jqHints.append('<div class="plan">' + planDef[planIdx++] + '</div>'); + } + return planIdx < planDef.length; + }, + /** * Processes and display appropriately the server hints. * TODO: sort hints so static and popup hints come first, and a (single) drop-down hint last diff --git a/js/codeq/prolog.js b/js/codeq/prolog.js index 96c3077..4eed354 100644 --- a/js/codeq/prolog.js +++ b/js/codeq/prolog.js @@ -95,9 +95,11 @@ * add the above function to the buttons */ addClickListenerTranstions = function(){ + $('#btn_code_plan').on('click',clickListenerTransitionFun); $('#btn_code_hint').on('click',clickListenerTransitionFun); $('#btn_code_test').on('click',clickListenerTransitionFun); + $('#btn_code_plan').on(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_hint').on(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_test').on(transitionEventName,mouseDownEventIgnoreFun); }, @@ -105,9 +107,11 @@ * and a function to remove it */ removeClickListenerTransition = function(){ + $('#btn_code_plan').off('click',clickListenerTransitionFun); $('#btn_code_hint').off('click',clickListenerTransitionFun); $('#btn_code_test').off('click',clickListenerTransitionFun); + $('#btn_code_plan').off(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_hint').off(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_test').off(transitionEventName,mouseDownEventIgnoreFun); }, @@ -362,11 +366,12 @@ editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true }), activityHandler = makeActivityHandler(editor, problem.id), terminal = makePrologTerminalHandler(jqConsole, editor, problem.id, activityHandler), - hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint); + hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan); editor.setValue(info.solution); $('#title').text(problem.slug); jqDescription.html(problem.description); + $('#btn_code_plan').prop('disabled', problem.plan.length == 0); editor.on('change', function (instance, changeObj) { var doc = editor.getDoc(), @@ -381,6 +386,12 @@ } }); + $('#btn_code_plan').on('click', function () { + if (!hinter.planNext()) { + $('#btn_code_plan').prop('disabled', true); + $('#btn_code_plan').blur(); + } + }); $('#btn_code_hint').on('click', function () { terminal.append('hint.\n', 'input'); terminal.inputDisable(); @@ -451,4 +462,4 @@ } }; }; -})();
\ No newline at end of file +})(); diff --git a/js/codeq/python.js b/js/codeq/python.js index e856c08..1d4ee17 100644 --- a/js/codeq/python.js +++ b/js/codeq/python.js @@ -97,9 +97,11 @@ * add the above function to the buttons */ addClickListenerTranstions = function(){ + $('#btn_code_plan').on('click',clickListenerTransitionFun); $('#btn_code_hint').on('click',clickListenerTransitionFun); $('#btn_code_test').on('click',clickListenerTransitionFun); + $('#btn_code_plan').on(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_hint').on(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_test').on(transitionEventName,mouseDownEventIgnoreFun); }, @@ -107,9 +109,11 @@ * and a function to remove it */ removeClickListenerTransition = function(){ + $('#btn_code_plan').off('click',clickListenerTransitionFun); $('#btn_code_hint').off('click',clickListenerTransitionFun); $('#btn_code_test').off('click',clickListenerTransitionFun); + $('#btn_code_plan').off(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_hint').off(transitionEventName,mouseDownEventIgnoreFun); $('#btn_code_test').off(transitionEventName,mouseDownEventIgnoreFun); }, @@ -312,11 +316,12 @@ editor = CodeMirror(jqEditor[0], { cursorHeight: 0.85, lineNumbers: true, matchBrackets: true, mode: 'python' }), activityHandler = makeActivityHandler(editor, problem.id), terminal = makePythonTerminalHandler(jqConsole, editor, problem.id, activityHandler), - hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint); + hinter = codeq.makeHinter(jqHints, jqEditor, editor, problem.hint, problem.plan); editor.setValue(info.solution); $('#title').text(problem.slug); jqDescription.html(problem.description); + $('#btn_code_plan').prop('disabled', problem.plan.length == 0); editor.on('change', function (instance, changeObj) { var doc = editor.getDoc(), @@ -331,6 +336,12 @@ } }); + $('#btn_code_plan').on('click', function () { + if (!hinter.planNext()) { + $('#btn_code_plan').prop('disabled', true); + $('#btn_code_plan').blur(); + } + }); $('#btn_code_hint').on('click', function () { var doc = editor.getDoc(); codeq.comms.sendHint({ |