Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Show/ hide all buttons at top of page; but all pages except index hav…
…e it.
  • Loading branch information
ehmatthes committed Nov 3, 2013
1 parent 6eb256a commit 8c43c49
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
4 changes: 4 additions & 0 deletions notebooks/css/site_styles.css
Expand Up @@ -11,6 +11,10 @@ button.hide_output, button.show_output {
width: 100px;
}

button.show_output_all {
margin-right: 10px;
}

/* Start out with output hidden. */
div.output {
display: none;
Expand Down
26 changes: 16 additions & 10 deletions notebooks/js/show_hide_output.js
@@ -1,17 +1,23 @@
// Show all output
$(document).ready(function(){
$("button.hide_output_all").click(function(){
$("div.output").hide();
$("button.show_output_all").show();
$("button.hide_output_all").hide();
});
$("button.show_output_all").click(function(){
// Make all output visible
$("div.output").show();
// Make sure all buttons toggled to 'hide output'
$("button.show_output").hide();
$("button.hide_output").show();
});
});

// Hide all output
$(document).ready(function(){
$("button.show_output_all").click(function(){
$("div.output").show();
$("button.show_output_all").hide();
$("button.hide_output_all").show();
});
$("button.hide_output_all").click(function(){
// Hide all output
$("div.output").hide();
// Make sure all buttons toggled to 'show output'
$("button.show_output").show();
$("button.hide_output").hide();
});
});

// Show single output
Expand Down
2 changes: 0 additions & 2 deletions scripts/add_css_js_links.sh
Expand Up @@ -25,8 +25,6 @@ css_js_link_string="$css_js_link_string<script type='text\/javascript' src='js\/

# js file to show/ hide output
css_js_link_string="$css_js_link_string<script type='text\/javascript' src='js\/show_hide_output.js'><\/script>\n"
printf "HERE HERE HERE\n"
printf "css_js $css_js_link_string\n"

# Not using this at this point, just leads to unfound resource.
#css_js_link_string="$css_js_link_string<!-- Custom stylesheet, it must be in the same directory as the html file -->\n"
Expand Down
22 changes: 20 additions & 2 deletions scripts/show_hide_output.py
Expand Up @@ -25,10 +25,21 @@ def generate_button(id_number):
button_string += "</div>\n"
return button_string

def generate_show_hide_all_buttons():
# Generate the buttons that show or hide all output.
button_string = "<div class='text-right'>\n"
button_string += " <button id='show_output_all' class='btn btn-success btn-xs show_output_all'>Show all output</button>\n"
button_string += " <button id='hide_output_all' class='btn btn-success btn-xs hide_output_all'>Hide all output</button>\n"
button_string += "</div>\n"
return button_string


# Find all div.output, and add an id to each.
# Add show/ hide buttons to each output
# For each file, add show_all, hide_all buttons just under navbar
# This is after second div.container element
for filename in filenames:

container_number = 0
f = open(path_to_notebooks + filename, 'r')
lines = f.readlines()
f.close()
Expand All @@ -37,7 +48,14 @@ def generate_button(id_number):
f = open(path_to_notebooks + filename, 'wb')
replacement_num = 0
for line in lines:
if target_string in line:

if "<div class='container'>" in line or '<div class="container">' in line:
# Add show_all hide_all buttons in second container.
container_number += 1
f.write(line)
if container_number == 2:
f.write(generate_show_hide_all_buttons())
elif target_string in line:
# If this line has a div.output, add an id
replacement_string = '<div id="output_%d" class="output ' % replacement_num

Expand Down

0 comments on commit 8c43c49

Please sign in to comment.