4
4
// Hide or display solutions in a notebook
5
5
6
6
/*
7
+ December 6, 2017 @jcb91: use bootstrap 'hidden' class to play nicely with collapsible_headings
7
8
December 30, 2015: update to 4.1
8
9
Update december 22, 2015:
9
10
Added the metadata solution_first to mark the beginning of an exercise. It is now possible to have several consecutive exercises.
@@ -48,7 +49,7 @@ define([
48
49
IPython . notebook . select_next ( ) ;
49
50
cell = IPython . notebook . get_selected_cell ( ) ;
50
51
while ( cell_index ++ < ncells & cell . metadata . solution != undefined & cell . metadata . solution_first != true ) {
51
- cell . element . show ( ) ;
52
+ cell . element . removeClass ( 'hidden' ) ;
52
53
cell . metadata . solution = "shown" ;
53
54
IPython . notebook . select_next ( ) ;
54
55
cell = IPython . notebook . get_selected_cell ( ) ;
@@ -60,7 +61,7 @@ define([
60
61
IPython . notebook . select_next ( ) ;
61
62
cell = IPython . notebook . get_selected_cell ( ) ;
62
63
while ( cell_index ++ < ncells & cell . metadata . solution != undefined & cell . metadata . solution_first != true ) {
63
- cell . element . hide ( ) ;
64
+ cell . element . addClass ( 'hidden' ) ;
64
65
cell . metadata . solution = "hidden"
65
66
IPython . notebook . select_next ( ) ;
66
67
cell = IPython . notebook . get_selected_cell ( ) ;
@@ -93,7 +94,7 @@ define([
93
94
delete cell . metadata . solution_first ;
94
95
while ( cell . metadata . solution != undefined & cell . metadata . solution_first != true ) {
95
96
delete cell . metadata . solution ;
96
- cell . element . show ( ) ;
97
+ cell . element . removeClass ( 'hidden' ) ;
97
98
IPython . notebook . select_next ( ) ;
98
99
cell = IPython . notebook . get_selected_cell ( )
99
100
}
@@ -123,7 +124,7 @@ define([
123
124
cell = lcells [ k ] ;
124
125
//console.log("new cell:", icells[k]);
125
126
cell . element . css ( { "background-color" : "#ffffff" } ) ;
126
- cell . element . hide ( ) ;
127
+ cell . element . addClass ( 'hidden' ) ;
127
128
cell . metadata . solution = "hidden" ;
128
129
}
129
130
}
@@ -183,12 +184,7 @@ function load_ipython_extension(){
183
184
for ( var i in cells ) {
184
185
var cell = cells [ i ] ;
185
186
if ( found_solution == true && typeof cell . metadata . solution != "undefined" && cell . metadata . solution_first != true ) {
186
- if ( cell . metadata . solution === "hidden" ) {
187
- cell . element . hide ( )
188
- }
189
- else {
190
- cell . element . show ( )
191
- }
187
+ cell . element . toggleClass ( 'hidden' , cell . metadata . solution === 'hidden' ) ;
192
188
} else {
193
189
found_solution = false
194
190
}
0 commit comments