Skip to content

Commit

Permalink
Attempt add adding a full screen in tab button. (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Feb 13, 2024
1 parent 96f789e commit a744e0d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
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

0 comments on commit a744e0d

Please sign in to comment.