Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide buttons from TryExamples directive by default #173

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ docs/build
build
dist
.jupyterlite.doit.db
/.vscode/
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 7 additions & 4 deletions jupyterlite_sphinx/jupyterlite_sphinx.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,18 @@ window.loadTryExamplesConfig = async (configFilePath) => {
tryExamplesGlobalMinHeight = parseInt(data.global_min_height);
}

// Disable interactive examples if file matches one of the ignore patterns
// by hiding try_examples_buttons.
// Selectively enable interactive examples if file matches one of the ignore patterns
// by un-hiding try_examples_buttons.
Patterns = data.ignore_patterns;
for (let pattern of Patterns) {
let regex = new RegExp(pattern);
if (regex.test(currentPageUrl)) {
agriyakhetarpal marked this conversation as resolved.
Show resolved Hide resolved
var buttons = document.getElementsByClassName("try_examples_button");
var buttons = document.getElementsByClassName(
"try_examples_button hidden",
);
for (var i = 0; i < buttons.length; i++) {
buttons[i].classList.add("hidden");
console.log(buttons[i]);
buttons[i].classList.remove("hidden");
}
break;
}
Expand Down
6 changes: 3 additions & 3 deletions jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,14 @@ def run(self):

# Button with the onclick event to swap embedded notebook back to examples.
go_back_button_html = (
'<button class="try_examples_button" '
'<button class="try_examples_button hidden" '
f"onclick=\"window.tryExamplesHideIframe('{examples_div_id}',"
f"'{iframe_parent_div_id}')\">"
"Go Back</button>"
)

full_screen_button_html = (
'<button class="try_examples_button" '
'<button class="try_examples_button hidden" '
f"onclick=\"window.openInNewTab('{examples_div_id}',"
f"'{iframe_parent_div_id}')\">"
"Open In Tab</button>"
Expand All @@ -484,7 +484,7 @@ def run(self):
# Button with the onclick event to swap examples with embedded notebook.
try_it_button_html = (
'<div class="try_examples_button_container">'
'<button class="try_examples_button" '
'<button class="try_examples_button hidden" '
f"onclick=\"window.tryExamplesShowIframe('{examples_div_id}',"
f"'{iframe_div_id}','{iframe_parent_div_id}','{iframe_src}',"
f"'{height}')\">"
Expand Down