@@ -32,12 +32,12 @@ function playground_text(playground) {
3232 method : 'POST' ,
3333 mode : 'cors' ,
3434 } )
35- . then ( response => response . json ( ) )
36- . then ( response => {
37- // get list of crates available in the rust playground
38- let playground_crates = response . crates . map ( item => item [ "id" ] ) ;
39- playgrounds . forEach ( block => handle_crate_list_update ( block , playground_crates ) ) ;
40- } ) ;
35+ . then ( response => response . json ( ) )
36+ . then ( response => {
37+ // get list of crates available in the rust playground
38+ let playground_crates = response . crates . map ( item => item [ "id" ] ) ;
39+ playgrounds . forEach ( block => handle_crate_list_update ( block , playground_crates ) ) ;
40+ } ) ;
4141 }
4242
4343 function handle_crate_list_update ( playground_block , playground_crates ) {
@@ -124,17 +124,46 @@ function playground_text(playground) {
124124
125125 result_block . innerText = "Running..." ;
126126
127- fetch_with_timeout ( "https://play.rust-lang.org/evaluate.json" , {
128- headers : {
129- 'Content-Type' : "application/json" ,
130- } ,
131- method : 'POST' ,
132- mode : 'cors' ,
133- body : JSON . stringify ( params )
127+ // fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
128+ // headers: {
129+ // 'Content-Type': "application/json",
130+ // },
131+ // method: 'POST',
132+ // mode: 'cors',
133+ // body: JSON.stringify(params)
134+ // })
135+ new Promise ( ( resolve , reject ) => {
136+ setTimeout ( ( ) => {
137+ resolve ( "foo" ) ;
138+ } , 200 )
134139 } )
135- . then ( response => response . json ( ) )
136- . then ( response => result_block . innerText = response . result )
137- . catch ( error => result_block . innerText = "Playground Communication: " + error . message ) ;
140+ // .then(response => response.json())
141+ // .then(response => result_block.innerText = response.result)
142+ // .then(response => result_block.innerHTML = "<div style=\"height: 300px;background-color: red;\"></div>")
143+ // .then(response => result_block.innerHTML = " <div id=\"button_click\"></div><script type=\"module\" src=\"wasm-test.js\"></script>")
144+ . then ( response => {
145+ result_block . innerText = "" ;
146+ var iframe = result_block . appendChild ( document . createElement ( 'iframe' ) ) ,
147+ doc = iframe . contentWindow . document ,
148+ options = {
149+ objid : 152 ,
150+ key : 316541321
151+ } ,
152+ //src = "host/widget.js",
153+ uri = encodeURIComponent ( JSON . stringify ( options ) ) ;
154+ doc . someVar = "Hello World!" ;
155+ iframe . id = "iframewidget" ;
156+ iframe . width = result_block . width ;
157+ iframe . height = result_block . height ;
158+
159+ var html = '<body onload="var d=document;' +
160+ 'var script=d.createElement(\'script\');script.type=\'module\';script.src=\'wasm-test.js\';' +
161+ 'd.getElementsByTagName(\'head\')[0].appendChild(script);"><div id="button_click"></div></body>' ;
162+ doc . open ( ) . write ( html ) ;
163+ doc . close ( ) ;
164+ } )
165+ . catch ( error => result_block . innerText = "Playground Communication: " + error . message ) ;
166+
138167 }
139168
140169 // Syntax highlighting Configuration
@@ -146,7 +175,7 @@ function playground_text(playground) {
146175 let code_nodes = Array
147176 . from ( document . querySelectorAll ( 'code' ) )
148177 // Don't highlight `inline code` blocks in headers.
149- . filter ( function ( node ) { return ! node . parentElement . classList . contains ( "header" ) ; } ) ;
178+ . filter ( function ( node ) { return ! node . parentElement . classList . contains ( "header" ) ; } ) ;
150179
151180 if ( window . ace ) {
152181 // language-rust class needs to be removed for editable
@@ -363,15 +392,15 @@ function playground_text(playground) {
363392 set_theme ( theme ) ;
364393 } ) ;
365394
366- themePopup . addEventListener ( 'focusout' , function ( e ) {
395+ themePopup . addEventListener ( 'focusout' , function ( e ) {
367396 // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
368397 if ( ! ! e . relatedTarget && ! themeToggleButton . contains ( e . relatedTarget ) && ! themePopup . contains ( e . relatedTarget ) ) {
369398 hideThemes ( ) ;
370399 }
371400 } ) ;
372401
373402 // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628
374- document . addEventListener ( 'click' , function ( e ) {
403+ document . addEventListener ( 'click' , function ( e ) {
375404 if ( themePopup . style . display === 'block' && ! themeToggleButton . contains ( e . target ) && ! themePopup . contains ( e . target ) ) {
376405 hideThemes ( ) ;
377406 }
@@ -593,7 +622,7 @@ function playground_text(playground) {
593622 } ) ;
594623} ) ( ) ;
595624
596- ( function scrollToTop ( ) {
625+ ( function scrollToTop ( ) {
597626 var menuTitle = document . querySelector ( '.menu-title' ) ;
598627
599628 menuTitle . addEventListener ( 'click' , function ( ) {
0 commit comments