1+ var fontSize = 16 ;
2+ var editor = ace . edit ( "editor" ) ;
3+ editor . setTheme ( "ace/theme/monokai" ) ;
4+ editor . session . setMode ( "ace/mode/html" ) ;
5+ editor . setAutoScrollEditorIntoView ( true ) ;
6+ editor . setFontSize ( fontSize ) ;
7+
8+ if ( localStorage . HTMLcode != null ) {
9+ editor . setValue ( localStorage . HTMLcode ) ;
10+ if ( localStorage . HTMLcode [ 0 ] == ' ' ) {
11+ window . frames [ 0 ] . document . body . innerHTML = '' +
12+ '<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);">' +
13+ localStorage . HTMLcode +
14+ '</div>' ;
15+ } else {
16+ window . frames [ 0 ] . document . body . innerHTML = localStorage . HTMLcode ;
17+ }
18+ }
19+
20+ editor . setOptions ( {
21+ wrap : true
22+ } ) ;
23+
24+ function setFontSize ( plus ) {
25+ if ( plus ) {
26+ fontSize = fontSize + 4 ;
27+ editor . setFontSize ( fontSize ) ;
28+ } else {
29+ if ( ( fontSize - 4 ) > 0 ) {
30+ fontSize = fontSize - 4 ;
31+ editor . setFontSize ( fontSize ) ;
32+ }
33+ }
34+ }
35+
36+ document . getElementById ( 'btnRun' ) . onclick = function ( ) {
37+ var text = editor . getValue ( ) ;
38+ localStorage . setItem ( 'HTMLcode' , text ) ;
39+ try {
40+ if ( text == '' ) {
41+ alert ( 'EMPTY CODE' ) ;
42+ } else {
43+ if ( text [ 0 ] == ' ' ) {
44+ window . frames [ 0 ] . document . body . innerHTML = '' +
45+ '<div style="position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);">' +
46+ text +
47+ '</div>' ;
48+ } else {
49+ window . frames [ 0 ] . document . body . innerHTML = text ;
50+ }
51+ }
52+ } catch ( e ) {
53+ alert ( 'ERROR -> ' + e ) ;
54+ }
55+ }
56+
57+ if ( window . screen . width < window . screen . height ) {
58+ document . getElementById ( 'editor' ) . style . width = '100%' ;
59+ document . getElementById ( 'editor' ) . style . height = 'calc(50% - 24px)' ;
60+ document . getElementById ( 'viewer' ) . style . width = 'calc(100% - 4px)' ;
61+ document . getElementById ( 'viewer' ) . style . height = 'calc(50% - 28px)' ; document . getElementById ( 'viewer' ) . style . top = 'calc(50% + 24px)' ;
62+ editor . resize ( ) ;
63+ }
0 commit comments