@@ -32,12 +32,12 @@ function playground_text(playground) {
32
32
method : 'POST' ,
33
33
mode : 'cors' ,
34
34
} )
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
+ } ) ;
41
41
}
42
42
43
43
function handle_crate_list_update ( playground_block , playground_crates ) {
@@ -124,17 +124,46 @@ function playground_text(playground) {
124
124
125
125
result_block . innerText = "Running..." ;
126
126
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 )
134
139
} )
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
+
138
167
}
139
168
140
169
// Syntax highlighting Configuration
@@ -146,7 +175,7 @@ function playground_text(playground) {
146
175
let code_nodes = Array
147
176
. from ( document . querySelectorAll ( 'code' ) )
148
177
// 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" ) ; } ) ;
150
179
151
180
if ( window . ace ) {
152
181
// language-rust class needs to be removed for editable
@@ -363,15 +392,15 @@ function playground_text(playground) {
363
392
set_theme ( theme ) ;
364
393
} ) ;
365
394
366
- themePopup . addEventListener ( 'focusout' , function ( e ) {
395
+ themePopup . addEventListener ( 'focusout' , function ( e ) {
367
396
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
368
397
if ( ! ! e . relatedTarget && ! themeToggleButton . contains ( e . relatedTarget ) && ! themePopup . contains ( e . relatedTarget ) ) {
369
398
hideThemes ( ) ;
370
399
}
371
400
} ) ;
372
401
373
402
// 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 ) {
375
404
if ( themePopup . style . display === 'block' && ! themeToggleButton . contains ( e . target ) && ! themePopup . contains ( e . target ) ) {
376
405
hideThemes ( ) ;
377
406
}
@@ -593,7 +622,7 @@ function playground_text(playground) {
593
622
} ) ;
594
623
} ) ( ) ;
595
624
596
- ( function scrollToTop ( ) {
625
+ ( function scrollToTop ( ) {
597
626
var menuTitle = document . querySelector ( '.menu-title' ) ;
598
627
599
628
menuTitle . addEventListener ( 'click' , function ( ) {
0 commit comments