Skip to content

Commit 2dfa072

Browse files
committed
[collapsible_headings] add optional collapse/uncollapse-all button
1 parent e41b62b commit 2dfa072

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/collapsible_headings.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Parameters:
1010
description: Add a toolbar button to collapse the closest header cell
1111
input_type: checkbox
1212
default: false
13+
- name: collapsible_headings.add_all_cells_button
14+
description: Add a toolbar button to collapse/uncollapse all header cells
15+
input_type: checkbox
16+
default: false
1317
- name: collapsible_headings.add_insert_header_buttons
1418
description: Add toolbar buttons to insert heading cells above/below the selected cell
1519
input_type: checkbox

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/main.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define(['jquery', 'require'], function ($, require) {
1515
// define default values for config parameters
1616
var params = {
1717
add_button : false,
18+
add_all_cells_button: false,
1819
add_insert_header_buttons: false,
1920
use_toggle_controls : true,
2021
make_toggle_controls_buttons : false,
@@ -844,6 +845,25 @@ define(['jquery', 'require'], function ($, require) {
844845
}
845846
}]);
846847
}
848+
if (params.add_all_cells_button) {
849+
Jupyter.toolbar.add_buttons_group([{
850+
label: 'toggle all headings',
851+
icon: 'fa-angle-double-up',
852+
callback: function () {
853+
/**
854+
* Collapse/uncollapse all heading cells based on status of first
855+
*/
856+
var cells = Jupyter.notebook.get_cells();
857+
for (var ii = 0; ii < cells.length; ii++) {
858+
if (is_heading(cells[ii])) {
859+
Jupyter.keyboard_manager.actions.call(action_names[
860+
is_collapsed_heading(cells[ii]) ? 'uncollapse_all' : 'collapse_all']);
861+
return;
862+
}
863+
}
864+
}
865+
}]);
866+
}
847867
if (params.add_insert_header_buttons) {
848868
Jupyter.toolbar.add_buttons_group([
849869
action_names.insert_above, action_names.insert_below

src/jupyter_contrib_nbextensions/nbextensions/collapsible_headings/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ the nbextensions config page:
4040
indicating hidden content (disabled by default)
4141
* A toolbar button to collapse the nearest heading to the curently selected
4242
cell (disabled by default)
43+
* A toolbar button to collapse/uncollapse all headings (disabled by default)
4344

4445

4546
css

0 commit comments

Comments
 (0)