Skip to content

Commit

Permalink
Added cleanup hidden script support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Irene Ros committed Nov 8, 2011
1 parent 5a3574f commit 604a9f8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ the editor that it's running for:
console.log(someVar);
</textarea>

# Cleanup scripts: #

Sometimes you just have to clean up the mess you made, or have something execute
after your code that the reader doesn't need to see. No problem! Add a cleanup script
as follows:

<script type="codemirror/cleanup" data-selector="#code4">
someVar = 20;
// This will output 20!
console.log(someVar);
</script>

<textarea id="code4" name="code" class="code" mode="javascript" style="display: none;" runnable="true">
var someVar = 10;
</textarea>

# Globals! #

Sometimes you just need to access a global of some kind. The code in the codemirror editors is executed
Expand Down
19 changes: 18 additions & 1 deletion deck.codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
var $container = $[deck]('getContainer'),
opts = $[deck]('getOptions'),
codeblocks = $(slide).find(opts.selectors.codemirroritem),
hiddenScripts = [];
hiddenScripts = [],
cleanupScripts = [];

// Seek out and cache all hidden scripts
$("script[type=codemirror]").each(function() {
Expand All @@ -62,6 +63,14 @@
src: this.innerHTML
});
});

// Seek out and cache all cleanup scripts
$("script[type=\"codemirror/cleanup\"]").each(function() {
cleanupScripts.push({
selector: $(this).data("selector"),
src: this.innerHTML
});
});

// go through all code blocks
$.each(codeblocks, function(i, codeblock) {
Expand Down Expand Up @@ -170,11 +179,19 @@

var combinedSource = "";

// Prepend all setup scripts
$.each(hiddenScripts, function() {
if ($(codeblock).is(this.selector)) {
combinedSource += this.src + "\n";
}
});

// Append all cleanup scripts
$.each(cleanupScripts, function() {
if ($(codeblock).is(this.selector)) {
combinedSource = combinedSource + this.src + "\n";
}
});

combinedSource += editor.getValue();

Expand Down
23 changes: 23 additions & 0 deletions introduction/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ <h3> Then your code </h3>
<div><textarea id="code4" name="code" class="code" mode="javascript" style="display: none;" runnable="true">// output my log
console.log(someVar);</textarea></div>
</section>

<section class="slide" id="cleanup-script-tags">
<h2> Need to run some cleanup for your codes? </h2>
<h3> Embed a secret hidden cleanup script tag like so in your slide: </h3>

<script type="codemirror/cleanup" data-selector="#code4">
someVar = 12;
console.log(someVar);
</script>

<code>
&lt;script type=&quot;codemirror/cleanup&quot; data-selector=&quot;#code3&quot;&gt;<br/>
someVar = 12;
console.log(someVar);<br/>
&lt;/script&gt;<br/>
</code>

<h3> Then your code </h3>
<div><textarea id="code4" name="code" class="code" mode="javascript" style="display: none;" runnable="true">
// set some initial value
var someVar = 15;
</textarea></div>
</section>

<section class="slide" id="globals">
<h2> Sometimes you need some globals </h2>
Expand Down

0 comments on commit 604a9f8

Please sign in to comment.