@@ -64,6 +64,7 @@ const playButton = $("#play");
6464const stopButton = $ ( "#stop" ) ;
6565const shareButton = $ ( "#share" ) ;
6666const copyButton = $ ( "#copy" ) ;
67+ const hideEditor = $ ( "#hide-editor" ) ;
6768/** @type {HTMLIFrameElement } */
6869const iframe = $ ( "#frame" ) ;
6970const iframeOverlay = $ ( "#frame-overlay" ) ;
@@ -102,11 +103,12 @@ shareButton.addEventListener("click", (evt) => {
102103 "Your browser not support this feature. Consider installing Firefox or Chrome."
103104 ) ;
104105 }
105- const code = codeEditor . state . doc . toString ( ) ;
106+ const code = window . codeEditor . state . doc . toString ( ) ;
106107 const url =
107108 location . origin + "?c=" + encodeURIComponent ( compressString ( code ) ) ;
108109
109- if ( url . length > 2048 ) {
110+ if ( url . length > 2000 ) {
111+ console . log ( "Your too long URL:" , url ) ;
110112 return alert ( "Code too long to encode in URL" ) ;
111113 }
112114
@@ -127,7 +129,7 @@ copyButton.addEventListener("click", (evt) => {
127129 "Your browser not support this feature. Consider installing Firefox or Chrome."
128130 ) ;
129131 }
130- const code = codeEditor . state . doc . toString ( ) ;
132+ const code = window . codeEditor . state . doc . toString ( ) ;
131133
132134 navigator . clipboard . writeText ( code ) . then (
133135 ( ) => { } ,
@@ -138,12 +140,23 @@ copyButton.addEventListener("click", (evt) => {
138140 ) ;
139141} ) ;
140142
143+ hideEditor . addEventListener ( "click" , ( evt ) => {
144+ if ( code . hasAttribute ( "hidden" ) ) {
145+ code . removeAttribute ( "hidden" ) ;
146+ hideEditor . classList . remove ( "active" ) ;
147+ } else {
148+ code . setAttribute ( "hidden" , true ) ;
149+ hideEditor . classList . add ( "active" ) ;
150+ }
151+ iframe . focus ( ) ;
152+ } ) ;
153+
141154function runCode ( ) {
142155 iframe . src = "preview.html" ; // reload the iframe
143156}
144157
145158iframe . addEventListener ( "load" , ( ) => {
146- const code = codeEditor . state . doc . toString ( ) ;
159+ const code = window . codeEditor . state . doc . toString ( ) ;
147160 iframe . contentDocument . querySelector ( "#code" ) . innerHTML = code ;
148161} ) ;
149162
@@ -220,13 +233,14 @@ iframeOverlay.onmousedown = iframeOverlay.ontouchstart = (evt) => {
220233 if ( evt . target === iframeOverlay ) {
221234 hide ( iframeOverlay ) ;
222235 iframe . focus ( ) ;
223- return ;
224236 }
225237} ;
226238
227239window . addEventListener ( "click" , ( evt ) => {
228240 if ( evt . target === iframeOverlay ) return ;
229241 if ( evt . target === playButton ) return ;
242+ if ( evt . target === hideEditor ) return ;
243+
230244 show ( iframeOverlay ) ;
231245 iframe . blur ( ) ;
232246} ) ;
@@ -291,7 +305,10 @@ if (config.autosave) {
291305}
292306
293307function saveCode ( ) {
294- localStorage . setItem ( "litecanvas_code" , codeEditor . state . doc . toString ( ) ) ;
308+ localStorage . setItem (
309+ "litecanvas_code" ,
310+ window . codeEditor . state . doc . toString ( )
311+ ) ;
295312}
296313
297314function loadFromStorage ( ) {
@@ -303,7 +320,7 @@ function resetStorage() {
303320}
304321
305322if ( isMobile ) {
306- mobileBar ( codeEditor ) ;
323+ mobileBar ( window . codeEditor ) ;
307324}
308325
309326window . isUpdateAvailable = new Promise ( function ( resolve ) {
@@ -353,6 +370,7 @@ window.isUpdateAvailable.then((isAvailable) => {
353370
354371if ( ! smallScreen ) {
355372 show ( iframeOverlay ) ;
373+ show ( hideEditor ) ;
356374 if ( autoplay ) runCode ( ) ;
357375} else {
358376 show ( playButton ) ;
0 commit comments