diff --git a/runestone/activecode/activecode.py b/runestone/activecode/activecode.py index 987bbbf77..42b38c10d 100644 --- a/runestone/activecode/activecode.py +++ b/runestone/activecode/activecode.py @@ -47,6 +47,7 @@ def setup(app): app.add_javascript('skulpt.min.js') app.add_javascript('skulpt-stdlib.js') app.add_javascript('clike.js') + app.add_javascript('timed_activecode.js') app.add_node(ActivcodeNode, html=(visit_ac_node, depart_ac_node)) diff --git a/runestone/activecode/css/activecode.css b/runestone/activecode/css/activecode.css index 7fbb6a54e..84b419e38 100644 --- a/runestone/activecode/css/activecode.css +++ b/runestone/activecode/css/activecode.css @@ -94,4 +94,8 @@ .full_width ol { max-width: 100% !important; -} \ No newline at end of file +} + +.ac-disabled { + pointer-events: none; +} diff --git a/runestone/activecode/js/activecode.js b/runestone/activecode/js/activecode.js index 8bf4d0b72..8458e650f 100755 --- a/runestone/activecode/js/activecode.js +++ b/runestone/activecode/js/activecode.js @@ -64,24 +64,24 @@ ActiveCode.prototype.init = function(opts) { }; ActiveCode.prototype.createEditor = function (index) { - var newdiv = document.createElement('div'); + this.containerDiv = document.createElement('div'); var linkdiv = document.createElement('div') linkdiv.id = this.divid.replace(/_/g,'-').toLowerCase(); // :ref: changes _ to - so add this as a target - $(newdiv).addClass("ac_section alert alert-warning"); + $(this.containerDiv).addClass("ac_section alert alert-warning"); var codeDiv = document.createElement("div"); $(codeDiv).addClass("ac_code_div col-md-12"); this.codeDiv = codeDiv; - newdiv.id = this.divid; - newdiv.lang = this.language; - this.outerDiv = newdiv; + this.containerDiv.id = this.divid; + this.containerDiv.lang = this.language; + this.outerDiv = this.containerDiv; - $(this.origElem).replaceWith(newdiv); + $(this.origElem).replaceWith(this.containerDiv); if (linkdiv.id !== this.divid) { // Don't want the 'extra' target if they match. - newdiv.appendChild(linkdiv); + this.containerDiv.appendChild(linkdiv); } - newdiv.appendChild(codeDiv); + this.containerDiv.appendChild(codeDiv); var editor = CodeMirror(codeDiv, {value: this.code, lineNumbers: true, - mode: newdiv.lang, indentUnit: 4, + mode: this.containerDiv.lang, indentUnit: 4, matchBrackets: true, autoMatchParens: true, extraKeys: {"Tab": "indentMore", "Shift-Tab": "indentLess"} }); @@ -203,6 +203,7 @@ ActiveCode.prototype.createControls = function () { $(butt).click((function() {new AudioTour(this.divid, this.editor.getValue(), 1, $(this.origElem).data("audio"))}).bind(this)); } + $(this.outerDiv).prepend(ctrlDiv); }; @@ -326,11 +327,9 @@ ActiveCode.prototype.saveEditor = function () { }; ActiveCode.prototype.loadEditor = function () { - var loadEditor = (function (data, status, whatever) { // function called when contents of database are returned successfully var res = eval(data)[0]; - if (res.source) { this.editor.setValue(res.source); setTimeout(function() { @@ -356,8 +355,12 @@ ActiveCode.prototype.loadEditor = function () { if (this.sid !== undefined) { data['sid'] = this.sid; } + // This function needs to be chainable for when we want to do things like run the activecode + // immediately after loading the previous input (such as in a timed exam) + var dfd = jQuery.Deferred(); this.logBookEvent({'event': 'activecode', 'act': 'load', 'div_id': this.divid}); // Log the run event - jQuery.get(eBookConfig.ajaxURL + 'getprog', data, loadEditor); + jQuery.get(eBookConfig.ajaxURL + 'getprog', data, loadEditor).done(function () {dfd.resolve();}); + return dfd; }; @@ -731,7 +734,7 @@ JSActiveCode.prototype.runProg = function() { if (!str) str=""; _this.output.innerHTML += _this.outputfun(str)+"
"; }; - + $(this.eContainer).remove(); $(this.output).text(''); $(this.codeDiv).switchClass("col-md-12","col-md-6",{duration:500,queue:false}); @@ -1001,8 +1004,8 @@ AudioTour.prototype.tour = function (divid, audio_type, bcount) { // str+=""; - - var dir = "http://media.interactivepython.org/" + eBookConfig.basecourse + "/audio/" + + var dir = "http://media.interactivepython.org/" + eBookConfig.basecourse + "/audio/" //var dir = "../_static/audio/" str += "