File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,23 @@ the editor that it's running for:
92
92
console.log(someVar);
93
93
</textarea>
94
94
95
+ # Cleanup scripts: #
96
+
97
+ Sometimes you just have to clean up the mess you made, or have something execute
98
+ after your code that the reader doesn't need to see. No problem! Add a cleanup script
99
+ as follows:
100
+
101
+ <script type="codemirror/cleanup" data-selector="#code4">
102
+ someVar = 20;
103
+
104
+ // This will output 20!
105
+ console.log(someVar);
106
+ </script>
107
+
108
+ <textarea id="code4" name="code" class="code" mode="javascript" style="display: none;" runnable="true">
109
+ var someVar = 10;
110
+ </textarea>
111
+
95
112
# Globals! #
96
113
97
114
Sometimes you just need to access a global of some kind. The code in the codemirror editors is executed
Original file line number Diff line number Diff line change 53
53
var $container = $ [ deck ] ( 'getContainer' ) ,
54
54
opts = $ [ deck ] ( 'getOptions' ) ,
55
55
codeblocks = $ ( slide ) . find ( opts . selectors . codemirroritem ) ,
56
- hiddenScripts = [ ] ;
56
+ hiddenScripts = [ ] ,
57
+ cleanupScripts = [ ] ;
57
58
58
59
// Seek out and cache all hidden scripts
59
60
$ ( "script[type=codemirror]" ) . each ( function ( ) {
62
63
src : this . innerHTML
63
64
} ) ;
64
65
} ) ;
66
+
67
+ // Seek out and cache all cleanup scripts
68
+ $ ( "script[type=\"codemirror/cleanup\"]" ) . each ( function ( ) {
69
+ cleanupScripts . push ( {
70
+ selector : $ ( this ) . data ( "selector" ) ,
71
+ src : this . innerHTML
72
+ } ) ;
73
+ } ) ;
65
74
66
75
// go through all code blocks
67
76
$ . each ( codeblocks , function ( i , codeblock ) {
170
179
171
180
var combinedSource = "" ;
172
181
182
+ // Prepend all setup scripts
173
183
$ . each ( hiddenScripts , function ( ) {
174
184
if ( $ ( codeblock ) . is ( this . selector ) ) {
175
185
combinedSource += this . src + "\n" ;
176
186
}
177
187
} ) ;
188
+
189
+ // Append all cleanup scripts
190
+ $ . each ( cleanupScripts , function ( ) {
191
+ if ( $ ( codeblock ) . is ( this . selector ) ) {
192
+ combinedSource = combinedSource + this . src + "\n" ;
193
+ }
194
+ } ) ;
178
195
179
196
combinedSource += editor . getValue ( ) ;
180
197
Original file line number Diff line number Diff line change @@ -147,6 +147,29 @@ <h3> Then your code </h3>
147
147
< div > < textarea id ="code4 " name ="code " class ="code " mode ="javascript " style ="display: none; " runnable ="true "> // output my log
148
148
console.log(someVar);</ textarea > </ div >
149
149
</ section >
150
+
151
+ < section class ="slide " id ="cleanup-script-tags ">
152
+ < h2 > Need to run some cleanup for your codes? </ h2 >
153
+ < h3 > Embed a secret hidden cleanup script tag like so in your slide: </ h3 >
154
+
155
+ < script type ="codemirror/cleanup " data-selector ="#code4 ">
156
+ someVar = 12 ;
157
+ console . log ( someVar ) ;
158
+ </ script >
159
+
160
+ < code >
161
+ <script type="codemirror/cleanup" data-selector="#code3">< br />
162
+ someVar = 12;
163
+ console.log(someVar);< br />
164
+ </script>< br />
165
+ </ code >
166
+
167
+ < h3 > Then your code </ h3 >
168
+ < div > < textarea id ="code4 " name ="code " class ="code " mode ="javascript " style ="display: none; " runnable ="true ">
169
+ // set some initial value
170
+ var someVar = 15;
171
+ </ textarea > </ div >
172
+ </ section >
150
173
151
174
< section class ="slide " id ="globals ">
152
175
< h2 > Sometimes you need some globals </ h2 >
You can’t perform that action at this time.
0 commit comments