44window . onunload = function ( ) { } ;
55
66// Global variable, shared between modules
7- function playpen_text ( playpen ) {
8- let code_block = playpen . querySelector ( "code" ) ;
7+ function playground_text ( playground ) {
8+ let code_block = playground . querySelector ( "code" ) ;
99
1010 if ( window . ace && code_block . classList . contains ( "editable" ) ) {
1111 let editor = window . ace . edit ( code_block ) ;
@@ -23,8 +23,8 @@ function playpen_text(playpen) {
2323 ] ) ;
2424 }
2525
26- var playpens = Array . from ( document . querySelectorAll ( ".playpen " ) ) ;
27- if ( playpens . length > 0 ) {
26+ var playgrounds = Array . from ( document . querySelectorAll ( ".playground " ) ) ;
27+ if ( playgrounds . length > 0 ) {
2828 fetch_with_timeout ( "https://play.rust-lang.org/meta/crates" , {
2929 headers : {
3030 'Content-Type' : "application/json" ,
@@ -36,21 +36,21 @@ function playpen_text(playpen) {
3636 . then ( response => {
3737 // get list of crates available in the rust playground
3838 let playground_crates = response . crates . map ( item => item [ "id" ] ) ;
39- playpens . forEach ( block => handle_crate_list_update ( block , playground_crates ) ) ;
39+ playgrounds . forEach ( block => handle_crate_list_update ( block , playground_crates ) ) ;
4040 } ) ;
4141 }
4242
43- function handle_crate_list_update ( playpen_block , playground_crates ) {
43+ function handle_crate_list_update ( playground_block , playground_crates ) {
4444 // update the play buttons after receiving the response
45- update_play_button ( playpen_block , playground_crates ) ;
45+ update_play_button ( playground_block , playground_crates ) ;
4646
4747 // and install on change listener to dynamically update ACE editors
4848 if ( window . ace ) {
49- let code_block = playpen_block . querySelector ( "code" ) ;
49+ let code_block = playground_block . querySelector ( "code" ) ;
5050 if ( code_block . classList . contains ( "editable" ) ) {
5151 let editor = window . ace . edit ( code_block ) ;
5252 editor . addEventListener ( "change" , function ( e ) {
53- update_play_button ( playpen_block , playground_crates ) ;
53+ update_play_button ( playground_block , playground_crates ) ;
5454 } ) ;
5555 // add Ctrl-Enter command to execute rust code
5656 editor . commands . addCommand ( {
@@ -59,7 +59,7 @@ function playpen_text(playpen) {
5959 win : "Ctrl-Enter" ,
6060 mac : "Ctrl-Enter"
6161 } ,
62- exec : _editor => run_rust_code ( playpen_block )
62+ exec : _editor => run_rust_code ( playground_block )
6363 } ) ;
6464 }
6565 }
@@ -77,7 +77,7 @@ function playpen_text(playpen) {
7777 }
7878
7979 // get list of `extern crate`'s from snippet
80- var txt = playpen_text ( pre_block ) ;
80+ var txt = playground_text ( pre_block ) ;
8181 var re = / e x t e r n \s + c r a t e \s + ( [ a - z A - Z _ 0 - 9 ] + ) \s * ; / g;
8282 var snippet_crates = [ ] ;
8383 var item ;
@@ -106,7 +106,7 @@ function playpen_text(playpen) {
106106 code_block . append ( result_block ) ;
107107 }
108108
109- let text = playpen_text ( code_block ) ;
109+ let text = playground_text ( code_block ) ;
110110 let classes = code_block . querySelector ( 'code' ) . classList ;
111111 let has_2018 = classes . contains ( "edition2018" ) ;
112112 let edition = has_2018 ? "2018" : "2015" ;
@@ -200,10 +200,10 @@ function playpen_text(playpen) {
200200 } ) ;
201201 } ) ;
202202
203- if ( window . playpen_copyable ) {
203+ if ( window . playground_copyable ) {
204204 Array . from ( document . querySelectorAll ( 'pre code' ) ) . forEach ( function ( block ) {
205205 var pre_block = block . parentNode ;
206- if ( ! pre_block . classList . contains ( 'playpen ' ) ) {
206+ if ( ! pre_block . classList . contains ( 'playground ' ) ) {
207207 var buttons = pre_block . querySelector ( ".buttons" ) ;
208208 if ( ! buttons ) {
209209 buttons = document . createElement ( 'div' ) ;
@@ -222,8 +222,8 @@ function playpen_text(playpen) {
222222 } ) ;
223223 }
224224
225- // Process playpen code blocks
226- Array . from ( document . querySelectorAll ( ".playpen " ) ) . forEach ( function ( pre_block ) {
225+ // Process playground code blocks
226+ Array . from ( document . querySelectorAll ( ".playground " ) ) . forEach ( function ( pre_block ) {
227227 // Add play button
228228 var buttons = pre_block . querySelector ( ".buttons" ) ;
229229 if ( ! buttons ) {
@@ -243,7 +243,7 @@ function playpen_text(playpen) {
243243 run_rust_code ( pre_block ) ;
244244 } ) ;
245245
246- if ( window . playpen_copyable ) {
246+ if ( window . playground_copyable ) {
247247 var copyCodeClipboardButton = document . createElement ( 'button' ) ;
248248 copyCodeClipboardButton . className = 'fa fa-copy clip-button' ;
249249 copyCodeClipboardButton . innerHTML = '<i class="tooltiptext"></i>' ;
@@ -456,6 +456,11 @@ function playpen_text(playpen) {
456456 // Toggle sidebar
457457 sidebarToggleButton . addEventListener ( 'click' , function sidebarToggle ( ) {
458458 if ( html . classList . contains ( "sidebar-hidden" ) ) {
459+ var current_width = parseInt (
460+ document . documentElement . style . getPropertyValue ( '--sidebar-width' ) , 10 ) ;
461+ if ( current_width < 150 ) {
462+ document . documentElement . style . setProperty ( '--sidebar-width' , '150px' ) ;
463+ }
459464 showSidebar ( ) ;
460465 } else if ( html . classList . contains ( "sidebar-visible" ) ) {
461466 hideSidebar ( ) ;
@@ -476,7 +481,16 @@ function playpen_text(playpen) {
476481 html . classList . add ( 'sidebar-resizing' ) ;
477482 }
478483 function resize ( e ) {
479- document . documentElement . style . setProperty ( '--sidebar-width' , ( e . clientX - sidebar . offsetLeft ) + 'px' ) ;
484+ var pos = ( e . clientX - sidebar . offsetLeft ) ;
485+ if ( pos < 20 ) {
486+ hideSidebar ( ) ;
487+ } else {
488+ if ( html . classList . contains ( "sidebar-hidden" ) ) {
489+ showSidebar ( ) ;
490+ }
491+ pos = Math . min ( pos , window . innerWidth - 100 ) ;
492+ document . documentElement . style . setProperty ( '--sidebar-width' , pos + 'px' ) ;
493+ }
480494 }
481495 //on mouseup remove windows functions mousemove & mouseup
482496 function stopResize ( e ) {
@@ -558,8 +572,8 @@ function playpen_text(playpen) {
558572 var clipboardSnippets = new ClipboardJS ( '.clip-button' , {
559573 text : function ( trigger ) {
560574 hideTooltip ( trigger ) ;
561- let playpen = trigger . closest ( "pre" ) ;
562- return playpen_text ( playpen ) ;
575+ let playground = trigger . closest ( "pre" ) ;
576+ return playground_text ( playground ) ;
563577 }
564578 } ) ;
565579
0 commit comments