11window . jupyterliteShowIframe = ( tryItButtonId , iframeSrc ) => {
22 const tryItButton = document . getElementById ( tryItButtonId ) ;
33 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` ;
415
516 iframe . src = iframeSrc ;
617 iframe . width = iframe . height = '100%' ;
718 iframe . classList . add ( 'jupyterlite_sphinx_iframe' ) ;
819
20+ tryItButton . style . display = 'none' ;
21+ spinner . style . display = 'block' ;
22+
23+ tryItButton . parentNode . appendChild ( spinner ) ;
924 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' ) ;
1325}
1426
1527window . jupyterliteConcatSearchParams = ( iframeSrc , params ) => {
@@ -50,9 +62,17 @@ window.tryExamplesShowIframe = (
5062 const iframeContainer = document . getElementById ( iframeContainerId ) ;
5163 var height ;
5264
53- let iframe = iframeContainer . querySelector ( 'iframe.jupyterlite_sphinx_raw_iframe ' ) ;
65+ let iframe = iframeContainer . querySelector ( 'iframe.jupyterlite_sphinx_iframe ' ) ;
5466
5567 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+
5676 const examples = examplesContainer . querySelector ( '.try_examples_content' ) ;
5777 iframe = document . createElement ( 'iframe' ) ;
5878 iframe . src = iframeSrc ;
@@ -62,9 +82,23 @@ window.tryExamplesShowIframe = (
6282 } else {
6383 height = Math . max ( tryExamplesGlobalMinHeight , examples . offsetHeight ) ;
6484 }
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+
6598 iframe . style . height = `${ height } px` ;
66- iframe . classList . add ( 'jupyterlite_sphinx_raw_iframe ' ) ;
99+ iframe . classList . add ( 'jupyterlite_sphinx_iframe ' ) ;
67100 examplesContainer . classList . add ( "hidden" ) ;
101+
68102 iframeContainer . appendChild ( iframe ) ;
69103 } else {
70104 examplesContainer . classList . add ( "hidden" ) ;
0 commit comments