1
1
window . jupyterliteShowIframe = ( tryItButtonId , iframeSrc ) => {
2
2
const tryItButton = document . getElementById ( tryItButtonId ) ;
3
3
const iframe = document . createElement ( 'iframe' ) ;
4
+ const buttonRect = tryItButton . getBoundingClientRect ( ) ;
5
+
6
+ const spinner = document . createElement ( 'div' ) ;
7
+ // hardcoded spinner height and width needs to match what is in css.
8
+ const spinnerHeight = 50 ; // px
9
+ const spinnerWidth = 50 ; // px
10
+ spinner . classList . add ( 'jupyterlite_sphinx_spinner' ) ;
11
+ spinner . style . display = 'none' ;
12
+ // Add negative margins to center the spinner
13
+ spinner . style . marginTop = `-${ spinnerHeight / 2 } px` ;
14
+ spinner . style . marginLeft = `-${ spinnerWidth / 2 } px` ;
4
15
5
16
iframe . src = iframeSrc ;
6
17
iframe . width = iframe . height = '100%' ;
7
18
iframe . classList . add ( 'jupyterlite_sphinx_iframe' ) ;
8
19
20
+ tryItButton . style . display = 'none' ;
21
+ spinner . style . display = 'block' ;
22
+
23
+ tryItButton . parentNode . appendChild ( spinner ) ;
9
24
tryItButton . parentNode . appendChild ( iframe ) ;
10
- tryItButton . innerText = 'Loading ...' ;
11
- tryItButton . classList . remove ( 'jupyterlite_sphinx_try_it_button_unclicked' ) ;
12
- tryItButton . classList . add ( 'jupyterlite_sphinx_try_it_button_clicked' ) ;
13
25
}
14
26
15
27
window . jupyterliteConcatSearchParams = ( iframeSrc , params ) => {
@@ -50,9 +62,17 @@ window.tryExamplesShowIframe = (
50
62
const iframeContainer = document . getElementById ( iframeContainerId ) ;
51
63
var height ;
52
64
53
- let iframe = iframeContainer . querySelector ( 'iframe.jupyterlite_sphinx_raw_iframe ' ) ;
65
+ let iframe = iframeContainer . querySelector ( 'iframe.jupyterlite_sphinx_iframe ' ) ;
54
66
55
67
if ( ! iframe ) {
68
+ // Add spinner
69
+ const spinner = document . createElement ( 'div' ) ;
70
+ // hardcoded spinner width needs to match what is in css.
71
+ const spinnerHeight = 50 ; // px
72
+ const spinnerWidth = 50 ; // px
73
+ spinner . classList . add ( 'jupyterlite_sphinx_spinner' ) ;
74
+ iframeContainer . appendChild ( spinner ) ;
75
+
56
76
const examples = examplesContainer . querySelector ( '.try_examples_content' ) ;
57
77
iframe = document . createElement ( 'iframe' ) ;
58
78
iframe . src = iframeSrc ;
@@ -62,9 +82,23 @@ window.tryExamplesShowIframe = (
62
82
} else {
63
83
height = Math . max ( tryExamplesGlobalMinHeight , examples . offsetHeight ) ;
64
84
}
85
+
86
+ /* Get spinner position. It will be centered in the iframe, unless the
87
+ * iframe extends beyond the viewport, in which case it will be centered
88
+ * between the top of the iframe and the bottom of the viewport.
89
+ */
90
+ const examplesTop = examples . getBoundingClientRect ( ) . top ;
91
+ const viewportBottom = window . innerHeight ;
92
+ const spinnerTop = 0.5 * Math . min ( ( viewportBottom - examplesTop ) , height ) ;
93
+ spinner . style . top = `${ spinnerTop } px` ;
94
+ // Add negative margins to center the spinner
95
+ spinner . style . marginTop = `-${ spinnerHeight / 2 } px` ;
96
+ spinner . style . marginLeft = `-${ spinnerWidth / 2 } px` ;
97
+
65
98
iframe . style . height = `${ height } px` ;
66
- iframe . classList . add ( 'jupyterlite_sphinx_raw_iframe ' ) ;
99
+ iframe . classList . add ( 'jupyterlite_sphinx_iframe ' ) ;
67
100
examplesContainer . classList . add ( "hidden" ) ;
101
+
68
102
iframeContainer . appendChild ( iframe ) ;
69
103
} else {
70
104
examplesContainer . classList . add ( "hidden" ) ;
0 commit comments