Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit 43af307

Browse files
committed
Implement hidecode option.
1 parent 0854443 commit 43af307

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

runestone/activecode/activecode.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919
from docutils import nodes
2020
from docutils.parsers.rst import directives
2121
from docutils.parsers.rst import Directive
22-
22+
from .textfield import *
2323

2424
def setup(app):
2525
app.add_directive('activecode', ActiveCode)
2626
app.add_directive('actex', ActiveExercise)
27+
app.add_role('textfield',textfield_role)
2728
app.add_stylesheet('codemirror.css')
2829
app.add_stylesheet('activecode.css')
2930

runestone/activecode/js/activecode.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ActiveCode.prototype.init = function(opts) {
3737
this.language = $(orig).data('lang');
3838
this.timelimit = $(orig).data('timelimit');
3939
this.includes = $(orig).data('include');
40+
this.hidecode = $(orig).data('hidecode');
4041
this.runButton = null;
4142
this.saveButton = null;
4243
this.loadButton = null;
@@ -95,6 +96,9 @@ ActiveCode.prototype.createEditor = function (index) {
9596
}).bind(this)); // use bind to preserve *this* inside the on handler.
9697

9798
this.editor = editor;
99+
if (this.hidecode) {
100+
$(this.codeDiv).css("display","none");
101+
}
98102
};
99103

100104
ActiveCode.prototype.createControls = function () {
@@ -116,14 +120,33 @@ ActiveCode.prototype.createControls = function () {
116120
$(butt).css("margin-left","10px");
117121
this.saveButton = butt;
118122
ctrlDiv.appendChild(butt);
119-
123+
if (this.hidecode) {
124+
$(butt).css("display","none")
125+
}
120126
// Load
121127
butt = document.createElement("button");
122128
$(butt).addClass("ac_opt btn btn-default");
123129
$(butt).text("Load");
124130
$(butt).css("margin-left","10px");
125131
this.loadButton = butt;
126132
ctrlDiv.appendChild(butt);
133+
if (this.hidecode) {
134+
$(butt).css("display","none")
135+
}
136+
137+
// Show/Hide Code
138+
if (this.hidecode) {
139+
butt = document.createElement("button");
140+
$(butt).addClass("ac_opt btn btn-default");
141+
$(butt).text("Show/Hide Code");
142+
$(butt).css("margin-left", "10px");
143+
this.showHideButt = butt;
144+
ctrlDiv.appendChild(butt);
145+
$(butt).click( (function() { $(this.codeDiv).toggle();
146+
$(this.loadButton).toggle();
147+
$(this.saveButton).toggle();
148+
}).bind(this));
149+
}
127150

128151
// CodeLens
129152
if ($(this.origElem).data("codelens")) {

0 commit comments

Comments
 (0)