Skip to content

Commit a744e0d

Browse files
authored
Attempt add adding a full screen in tab button. (#135)
1 parent 96f789e commit a744e0d

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

docs/full.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Fullscreen access
22

3+
Once and JupyterLite example has been activate by a user, and "Open in Tab" button is available that will open the same
4+
JupyterLite instance in a separate tab.
5+
6+
## custom link to JupyterLite
7+
38
You can access the JupyterLite deployment that `jupyterlite-sphinx` made for you, in fullscreen, following the `./lite/lab` and `./lite/retro` relative urls:
49

510
- [JupyterLab](./lite/lab/index.html)

jupyterlite_sphinx/jupyterlite_sphinx.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ window.tryExamplesHideIframe = (examplesContainerId, iframeParentContainerId) =>
115115
examplesContainer.classList.remove("hidden");
116116
}
117117

118+
// this will be used by the "Open in tab" button that is present next
119+
// # to the "go back" button after an iframe is made visible.
120+
window.openInNewTab = (examplesContainerId, iframeParentContainerId) => {
121+
const examplesContainer = document.getElementById(examplesContainerId);
122+
const iframeParentContainer = document.getElementById(
123+
iframeParentContainerId
124+
);
125+
126+
window.open(
127+
// we make some assumption that there is a single iframe and the the src is what we want to open.
128+
// Maybe we should have tabs open JupyterLab by default.
129+
iframeParentContainer.getElementsByTagName("iframe")[0].getAttribute("src")
130+
);
131+
tryExamplesHideIframe(examplesContainerId, iframeParentContainerId);
132+
};
118133

119134
/* Global variable for try_examples iframe minHeight. Defaults to 0 but can be
120135
* modified based on configuration in try_examples.json */

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,17 @@ def run(self):
442442

443443
# Button with the onclick event to swap embedded notebook back to examples.
444444
go_back_button_html = (
445-
'<div class="try_examples_button_container">'
446445
'<button class="try_examples_button" '
447446
f"onclick=\"window.tryExamplesHideIframe('{examples_div_id}',"
448447
f"'{iframe_parent_div_id}')\">"
449448
"Go Back</button>"
450-
"</div>"
449+
)
450+
451+
full_screen_button_html = (
452+
'<button class="try_examples_button" '
453+
f"onclick=\"window.openInNewTab('{examples_div_id}',"
454+
f"'{iframe_parent_div_id}')\">"
455+
"Open In Tab</button>"
451456
)
452457

453458
# Button with the onclick event to swap examples with embedded notebook.
@@ -465,7 +470,10 @@ def run(self):
465470
# Combine everything
466471
notebook_container_html = (
467472
iframe_parent_container_div_start
473+
+ '<div class="try_examples_button_container">'
468474
+ go_back_button_html
475+
+ full_screen_button_html
476+
+ "</div>"
469477
+ iframe_container_div
470478
+ iframe_parent_container_div_end
471479
)

0 commit comments

Comments
 (0)