@@ -587,10 +587,30 @@ <h3>New to C++ Mode?</h3>
587587
588588const heroEditor = CodeMirror . fromTextArea ( document . getElementById ( 'hero-editor' ) , {
589589 mode : 'cppmode' , theme : 'cppmode' , lineNumbers : true ,
590- indentUnit : 2 , tabSize : 2 , autofocus : false ,
590+ indentUnit : 2 , tabSize : 2 , autofocus : false , lineWrapping : false ,
591591} ) ;
592592heroEditor . setValue ( HERO_DEFAULT ) ;
593- heroEditor . setSize ( '100%' , '320px' ) ;
593+ heroEditor . setSize ( '100%' , '300px' ) ;
594+
595+ let heroEditorOpen = false ;
596+ function toggleHeroEditor ( ) {
597+ heroEditorOpen = ! heroEditorOpen ;
598+ const panel = document . getElementById ( 'hero-editor-panel' ) ;
599+ const arrow = document . getElementById ( 'hero-arrow-svg' ) ;
600+ const runBtn = document . getElementById ( 'hero-sketch-run-btn' ) ;
601+ if ( heroEditorOpen ) {
602+ panel . style . maxHeight = '400px' ;
603+ panel . style . opacity = '1' ;
604+ arrow . style . transform = 'rotate(180deg)' ;
605+ runBtn . style . display = 'block' ;
606+ setTimeout ( ( ) => heroEditor . refresh ( ) , 420 ) ;
607+ } else {
608+ panel . style . maxHeight = '0' ;
609+ panel . style . opacity = '0' ;
610+ arrow . style . transform = '' ;
611+ runBtn . style . display = 'none' ;
612+ }
613+ }
594614
595615function heroLaunch ( html ) {
596616 const area = document . getElementById ( 'hero-preview' ) ;
@@ -603,9 +623,10 @@ <h3>New to C++ Mode?</h3>
603623 else area . appendChild ( iframe ) ;
604624}
605625
606- document . getElementById ( 'hero-run-btn' ) . addEventListener ( 'click' , async function ( ) {
607- const btn = this ;
608- btn . textContent = '...' ; btn . disabled = true ;
626+ async function heroRun ( ) {
627+ const btn = document . getElementById ( 'hero-run-btn' ) ;
628+ const btn2 = document . getElementById ( 'hero-sketch-run-btn' ) ;
629+ [ btn , btn2 ] . forEach ( b => { b . textContent = '...' ; b . disabled = true ; } ) ;
609630 try {
610631 const resp = await fetch ( HERO_API + '/compile' , {
611632 method : 'POST' , headers : { 'Content-Type' :'application/json' } ,
@@ -616,14 +637,16 @@ <h3>New to C++ Mode?</h3>
616637 else {
617638 const jsUrl = URL . createObjectURL ( new Blob ( [ data . js ] , { type :'application/javascript' } ) ) ;
618639 function b64 ( s ) { var b = atob ( s ) , a = new Uint8Array ( b . length ) ; for ( var i = 0 ; i < b . length ; i ++ ) a [ i ] = b . charCodeAt ( i ) ; return a ; }
619- const wa = b64 ( data . wasm ) ;
620- const da = data . data ? b64 ( data . data ) : new Uint8Array ( 0 ) ;
640+ const wa = b64 ( data . wasm ) , da = data . data ? b64 ( data . data ) : new Uint8Array ( 0 ) ;
621641 const html = `<!DOCTYPE html><html><head><style>*{margin:0;padding:0;overflow:hidden}body{background:#fff}canvas{display:block}<\/style><\/head><body><canvas id="canvas"><\/canvas><script>(function(){window.Module={canvas:document.getElementById("canvas"),wasmBinary:new Uint8Array(${ JSON . stringify ( Array . from ( wa ) ) } ),getPreloadedPackage:function(){return new Uint8Array(${ JSON . stringify ( Array . from ( da ) ) } ).buffer;},print:console.log,printErr:console.warn};})();<\/script><script src="${ jsUrl } "><\/script><\/body><\/html>` ;
622642 heroLaunch ( html ) ;
623643 }
624644 } catch ( e ) { alert ( 'Server unreachable: ' + e . message ) ; }
625- btn . textContent = '▶ Run' ; btn . disabled = false ;
626- } ) ;
645+ [ btn , btn2 ] . forEach ( b => { b . textContent = '▶ Run' ; b . disabled = false ; } ) ;
646+ }
647+
648+ document . getElementById ( 'hero-run-btn' ) . addEventListener ( 'click' , heroRun ) ;
649+ document . getElementById ( 'hero-sketch-run-btn' ) . addEventListener ( 'click' , heroRun ) ;
627650</ script >
628651
629652</ body >
0 commit comments