forked from C2SM/pyvis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle_vis_button.py
40 lines (26 loc) · 961 Bytes
/
toggle_vis_button.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from IPython.display import HTML, display
def add():
tag = HTML(
"""
<script>
//$( document ).ready(function() {
var add_button = function () {
Jupyter.notebook.get_cells().forEach(function(cell) {
if (cell.element.find("form.bla").length == 0) {
cell.element.find("div.output_wrapper").append('<form class="bla" action="javascript:toggle_selected_input()"><input type="submit" style="float: right;" value="T"></i></form>');
}
})
};
var toggle_selected_input = function () {
// Find the selected cell
var cell = Jupyter.notebook.get_selected_cell();
// Toggle visibility of the input div
cell.element.find("div.input").toggle('slow');
cell.metadata.hide_input = ! cell.metadata.hide_input;
};
add_button()
//} );
</script>
"""
)
return display(tag)