Skip to content

Commit 2fb176b

Browse files
committed
Update height configuration
1 parent 3db7762 commit 2fb176b

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

jupyterlite_sphinx/jupyterlite_sphinx.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ window.jupyterliteConcatSearchParams = (iframeSrc, params) => {
4343

4444
window.tryExamplesShowIframe = (
4545
examplesContainerId, iframeContainerId, iframeParentContainerId, iframeSrc,
46-
iframeMinHeight
46+
iframeHeight
4747
) => {
4848
const examplesContainer = document.getElementById(examplesContainerId);
4949
const iframeParentContainer = document.getElementById(iframeParentContainerId);
5050
const iframeContainer = document.getElementById(iframeContainerId);
51+
var height;
5152

5253
let iframe = iframeContainer.querySelector('iframe.jupyterlite_sphinx_raw_iframe');
5354

@@ -56,8 +57,11 @@ window.tryExamplesShowIframe = (
5657
iframe = document.createElement('iframe');
5758
iframe.src = iframeSrc;
5859
iframe.style.width = '100%';
59-
minHeight = parseInt(iframeMinHeight);
60-
height = Math.max(minHeight, examples.offsetHeight);
60+
if (iframeHeight !== 'None') {
61+
height = parseInt(iframeHeight);
62+
} else {
63+
height = Math.max(tryExamplesGlobalMinHeight, examples.offsetHeight);
64+
}
6165
iframe.style.height = `${height}px`;
6266
iframe.classList.add('jupyterlite_sphinx_raw_iframe');
6367
examplesContainer.classList.add("hidden");
@@ -78,6 +82,10 @@ window.tryExamplesHideIframe = (examplesContainerId, iframeParentContainerId) =>
7882
}
7983

8084

85+
/* Global variable for try_examples iframe minHeight. Defaults to 0 but can be
86+
* modified based on configuration in try_examples.json */
87+
var tryExamplesGlobalMinHeight = 0;
88+
8189
window.loadTryExamplesConfig = async (configFilePath) => {
8290
try {
8391
// Add a timestamp as query parameter to ensure a cached version of the
@@ -90,7 +98,7 @@ window.loadTryExamplesConfig = async (configFilePath) => {
9098
if (!response.ok) {
9199
if (response.status === 404) {
92100
// Try examples ignore file is not present.
93-
console.log('try_examples config file not found.');
101+
console.log('Optional try_examples config file not found.');
94102
return;
95103
}
96104
throw new Error(`Error fetching ${configFilePath}`);
@@ -101,6 +109,11 @@ window.loadTryExamplesConfig = async (configFilePath) => {
101109
return;
102110
}
103111

112+
// Set minimum iframe height based on value in config file
113+
if (data.global_min_height) {
114+
tryExamplesGlobalMinHeight = parseInt(data.global_min_height);
115+
}
116+
104117
// Disable interactive examples if file matches one of the ignore patterns
105118
// by hiding try_examples_buttons.
106119
Patterns = data.ignore_patterns;

jupyterlite_sphinx/jupyterlite_sphinx.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ class TryExamplesDirective(SphinxDirective):
364364
has_content = True
365365
required_arguments = 0
366366
option_spec = {
367+
"height": directives.unchanged,
367368
"theme": directives.unchanged,
368369
"button_text": directives.unchanged,
369370
"example_class": directives.unchanged,
370-
"min_height": directives.unchanged,
371371
}
372372

373373
def run(self):
@@ -380,8 +380,8 @@ def run(self):
380380
)
381381

382382
button_text = self.options.pop("button_text", "Try it with Jupyterlite!")
383+
height = self.options.pop("height", None)
383384
example_class = self.options.pop("example_class", "")
384-
min_height = self.options.pop("min_height", "200px")
385385

386386
# We need to get the relative path back to the documentation root from
387387
# whichever file the docstring content is in.
@@ -456,7 +456,7 @@ def run(self):
456456
'<button class="try_examples_button" '
457457
f"onclick=\"window.tryExamplesShowIframe('{examples_div_id}',"
458458
f"'{iframe_div_id}','{iframe_parent_div_id}','{iframe_src}',"
459-
f"'{min_height}')\">"
459+
f"'{height}')\">"
460460
f"{button_text}</button>"
461461
"</div>"
462462
)
@@ -499,7 +499,6 @@ def _process_autodoc_docstrings(app, what, name, obj, options, lines):
499499
"theme": app.config.try_examples_global_theme,
500500
"button_text": app.config.try_examples_global_button_text,
501501
"example_class": app.config.try_examples_global_example_class,
502-
"min_height": app.config.try_examples_global_min_height,
503502
}
504503
try_examples_options = {
505504
key: value for key, value in try_examples_options.items() if value is not None
@@ -608,10 +607,6 @@ def setup(app):
608607

609608
app.add_config_value("global_enable_try_examples", default=False, rebuild=True)
610609
app.add_config_value("try_examples_global_theme", default=None, rebuild=True)
611-
app.add_config_value(
612-
"try_examples_global_example_class", default=None, rebuild="html"
613-
)
614-
app.add_config_value("try_examples_global_min_height", default=None, rebuild="html")
615610
app.add_config_value(
616611
"try_examples_global_button_text",
617612
default=None,

0 commit comments

Comments
 (0)