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

Commit 08d28ca

Browse files
committed
Add captions
1 parent a503723 commit 08d28ca

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

runestone/activecode/activecode.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,11 @@ def setup(app):
5454

5555

5656
TEMPLATE = """
57-
<pre data-component="activecode" id=%(divid)s data-lang="%(language)s" %(autorun)s %(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s %(gradebutton)s>
57+
<pre data-component="activecode" id=%(divid)s data-lang="%(language)s" %(autorun)s %(hidecode)s %(include)s %(timelimit)s %(coach)s %(codelens)s data-audio='%(ctext)s' %(sourcefile)s %(datafile)s %(stdin)s %(gradebutton)s %(caption)s>
5858
%(initialcode)s
5959
</pre>
6060
"""
6161

62-
63-
CAPTION = '''
64-
<div class="clearfix"></div>
65-
<p class="ac_caption"><span class="ac_caption_text">%(caption)s (%(divid)s)</span> </p>
66-
'''
67-
68-
69-
70-
7162
class ActivcodeNode(nodes.General, nodes.Element):
7263
def __init__(self, content):
7364
"""
@@ -175,6 +166,8 @@ def run(self):
175166

176167
if 'caption' not in self.options:
177168
self.options['caption'] = ''
169+
else:
170+
self.options['caption'] = "data-caption='%s'" % self.options['caption']
178171

179172
if 'include' not in self.options:
180173
self.options['include'] = ''

runestone/activecode/js/activecode.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ ActiveCode.prototype.init = function(opts) {
6060
this.createEditor();
6161
this.createOutput();
6262
this.createControls();
63+
if ($(orig).data('caption')) {
64+
this.caption = $(orig).data('caption');
65+
} else {
66+
this.caption = ""
67+
}
68+
this.addCaption()
6369

6470
if ($(orig).data('autorun')) {
6571
$(document).ready(this.runProg.bind(this));
@@ -224,6 +230,16 @@ ActiveCode.prototype.createOutput = function () {
224230

225231
};
226232

233+
ActiveCode.prototype.addCaption = function() {
234+
//someElement.parentNode.insertBefore(newElement, someElement.nextSibling);
235+
var capDiv = document.createElement('p');
236+
$(capDiv).html(this.caption + " (" + this.divid + ")");
237+
$(capDiv).addClass("ac_caption");
238+
$(capDiv).addClass("ac_caption_text");
239+
240+
this.outerDiv.parentNode.insertBefore(capDiv, this.outerDiv.nextSibling);
241+
};
242+
227243
ActiveCode.prototype.saveEditor = function () {
228244

229245
};

0 commit comments

Comments
 (0)