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

Add a full screen "Open in tab" button #135

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/full.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Fullscreen access

Once and JupyterLite example has been activate by a user, and "Open in Tab" button is available that will open the same
JupyterLite instance in a separate tab.

## custom link to JupyterLite

You can access the JupyterLite deployment that `jupyterlite-sphinx` made for you, in fullscreen, following the `./lite/lab` and `./lite/retro` relative urls:

- [JupyterLab](./lite/lab/index.html)
Expand Down
15 changes: 15 additions & 0 deletions jupyterlite_sphinx/jupyterlite_sphinx.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ window.tryExamplesHideIframe = (examplesContainerId, iframeParentContainerId) =>
examplesContainer.classList.remove("hidden");
}

// this will be used by the "Open in tab" button that is present next
// # to the "go back" button after an iframe is made visible.
window.openInNewTab = (examplesContainerId, iframeParentContainerId) => {
const examplesContainer = document.getElementById(examplesContainerId);
const iframeParentContainer = document.getElementById(
iframeParentContainerId
);

window.open(
// we make some assumption that there is a single iframe and the the src is what we want to open.
// Maybe we should have tabs open JupyterLab by default.
iframeParentContainer.getElementsByTagName("iframe")[0].getAttribute("src")
);
tryExamplesHideIframe(examplesContainerId, iframeParentContainerId);
};

/* Global variable for try_examples iframe minHeight. Defaults to 0 but can be
* modified based on configuration in try_examples.json */
Expand Down
12 changes: 10 additions & 2 deletions jupyterlite_sphinx/jupyterlite_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,17 @@ def run(self):

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

full_screen_button_html = (
'<button class="try_examples_button" '
f"onclick=\"window.openInNewTab('{examples_div_id}',"
f"'{iframe_parent_div_id}')\">"
"Open In Tab</button>"
)

# Button with the onclick event to swap examples with embedded notebook.
Expand All @@ -465,7 +470,10 @@ def run(self):
# Combine everything
notebook_container_html = (
iframe_parent_container_div_start
+ '<div class="try_examples_button_container">'
+ go_back_button_html
+ full_screen_button_html
+ "</div>"
+ iframe_container_div
+ iframe_parent_container_div_end
)
Expand Down
Loading