Skip to content

Commit

Permalink
Merge pull request #1169 from jcb91/exercise
Browse files Browse the repository at this point in the history
[exercise,exercise2] use bootstrap hidden class
  • Loading branch information
jcb91 authored Dec 19, 2017
2 parents ac92192 + 4dfacb7 commit 4a89982
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions src/jupyter_contrib_nbextensions/nbextensions/exercise/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// Hide or display solutions in a notebook

/*
December 6, 2017 @jcb91: use bootstrap 'hidden' class to play nicely with collapsible_headings
December 30, 2015: update to 4.1
Update december 22, 2015:
Added the metadata solution_first to mark the beginning of an exercise. It is now possible to have several consecutive exercises.
Expand Down Expand Up @@ -48,7 +49,7 @@ define([
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
while (cell_index++<ncells & cell.metadata.solution !=undefined & cell.metadata.solution_first !=true) {
cell.element.show();
cell.element.removeClass('hidden');
cell.metadata.solution = "shown";
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
Expand All @@ -60,7 +61,7 @@ define([
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
while (cell_index++<ncells & cell.metadata.solution !=undefined & cell.metadata.solution_first !=true) {
cell.element.hide();
cell.element.addClass('hidden');
cell.metadata.solution = "hidden"
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
Expand Down Expand Up @@ -93,7 +94,7 @@ define([
delete cell.metadata.solution_first;
while (cell.metadata.solution != undefined & cell.metadata.solution_first !=true ) {
delete cell.metadata.solution;
cell.element.show();
cell.element.removeClass('hidden');
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell()
}
Expand Down Expand Up @@ -123,7 +124,7 @@ define([
cell = lcells[k];
//console.log("new cell:", icells[k]);
cell.element.css({"background-color": "#ffffff"});
cell.element.hide();
cell.element.addClass('hidden');
cell.metadata.solution = "hidden";
}
}
Expand Down Expand Up @@ -183,12 +184,7 @@ function load_ipython_extension(){
for(var i in cells){
var cell = cells[i];
if (found_solution == true && typeof cell.metadata.solution != "undefined" && cell.metadata.solution_first !=true) {
if (cell.metadata.solution === "hidden") {
cell.element.hide()
}
else {
cell.element.show()
}
cell.element.toggleClass('hidden', cell.metadata.solution === 'hidden');
} else {
found_solution = false
}
Expand Down
16 changes: 6 additions & 10 deletions src/jupyter_contrib_nbextensions/nbextensions/exercise2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// Hide or display solutions in a notebook

// dec 6, 2017 @jcb91: use bootstrap 'hidden' class to play nicely with collapsible_headings
// december 30, 2015: update to notebook 4.1.x
// updated on december 22, 2015 to allow consecutive exercises
// exercise2: built by @jfbercher from an earlier work by @junasch october 2015) - see readme.md
Expand All @@ -16,7 +17,7 @@
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
while (cell_index++<ncells & cell.metadata.solution2 !=undefined & cell.metadata.solution2_first !=true) {
cell.element.show();
cell.element.removeClass('hidden');
cell.metadata.solution2 = "shown";
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
Expand All @@ -31,7 +32,7 @@
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
while (cell_index++<ncells & cell.metadata.solution2 !=undefined & cell.metadata.solution2_first !=true) {
cell.element.hide();
cell.element.addClass('hidden');
cell.metadata.solution2 = "hidden";
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell();
Expand Down Expand Up @@ -105,7 +106,7 @@ id=\"myCheck' + cbx + '\" >\
delete cell.metadata.solution2_first;
while (cell.metadata.solution2 != undefined & cell.metadata.solution2_first !=true) {
delete cell.metadata.solution2;
cell.element.show();
cell.element.removeClass('hidden');
IPython.notebook.select_next();
cell = IPython.notebook.get_selected_cell()
}
Expand All @@ -119,7 +120,7 @@ id=\"myCheck' + cbx + '\" >\
for (var k = 1; k < lcells.length; k++){
cell = lcells[k];
cell.element.css({"background-color": "#ffffff"});
cell.element.hide();
cell.element.addClass('hidden');
cell.metadata.solution2 = "hidden";
}
IPython.notebook.select(icells[0]); //select first cell in the list
Expand Down Expand Up @@ -167,12 +168,7 @@ function load_ipython_extension(){
for(var i in cells){
var cell = cells[i];
if (found_solution == true && typeof cell.metadata.solution2 != "undefined" && cell.metadata.solution2_first !=true) {
if (cell.metadata.solution2 === "hidden") {
cell.element.hide();
}
else {
cell.element.show();
}
cell.element.toggleClass('hidden', cell.metadata.solution2 === 'hidden');
} else {
found_solution = false
}
Expand Down

0 comments on commit 4a89982

Please # to comment.