4
4
window . onunload = function ( ) { } ;
5
5
6
6
// 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" ) ;
9
9
10
10
if ( window . ace && code_block . classList . contains ( "editable" ) ) {
11
11
let editor = window . ace . edit ( code_block ) ;
@@ -23,8 +23,8 @@ function playpen_text(playpen) {
23
23
] ) ;
24
24
}
25
25
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 ) {
28
28
fetch_with_timeout ( "https://play.rust-lang.org/meta/crates" , {
29
29
headers : {
30
30
'Content-Type' : "application/json" ,
@@ -36,21 +36,21 @@ function playpen_text(playpen) {
36
36
. then ( response => {
37
37
// get list of crates available in the rust playground
38
38
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 ) ) ;
40
40
} ) ;
41
41
}
42
42
43
- function handle_crate_list_update ( playpen_block , playground_crates ) {
43
+ function handle_crate_list_update ( playground_block , playground_crates ) {
44
44
// update the play buttons after receiving the response
45
- update_play_button ( playpen_block , playground_crates ) ;
45
+ update_play_button ( playground_block , playground_crates ) ;
46
46
47
47
// and install on change listener to dynamically update ACE editors
48
48
if ( window . ace ) {
49
- let code_block = playpen_block . querySelector ( "code" ) ;
49
+ let code_block = playground_block . querySelector ( "code" ) ;
50
50
if ( code_block . classList . contains ( "editable" ) ) {
51
51
let editor = window . ace . edit ( code_block ) ;
52
52
editor . addEventListener ( "change" , function ( e ) {
53
- update_play_button ( playpen_block , playground_crates ) ;
53
+ update_play_button ( playground_block , playground_crates ) ;
54
54
} ) ;
55
55
// add Ctrl-Enter command to execute rust code
56
56
editor . commands . addCommand ( {
@@ -59,7 +59,7 @@ function playpen_text(playpen) {
59
59
win : "Ctrl-Enter" ,
60
60
mac : "Ctrl-Enter"
61
61
} ,
62
- exec : _editor => run_rust_code ( playpen_block )
62
+ exec : _editor => run_rust_code ( playground_block )
63
63
} ) ;
64
64
}
65
65
}
@@ -77,7 +77,7 @@ function playpen_text(playpen) {
77
77
}
78
78
79
79
// get list of `extern crate`'s from snippet
80
- var txt = playpen_text ( pre_block ) ;
80
+ var txt = playground_text ( pre_block ) ;
81
81
var re = / e x t e r n \s + c r a t e \s + ( [ a - z A - Z _ 0 - 9 ] + ) \s * ; / g;
82
82
var snippet_crates = [ ] ;
83
83
var item ;
@@ -106,7 +106,7 @@ function playpen_text(playpen) {
106
106
code_block . append ( result_block ) ;
107
107
}
108
108
109
- let text = playpen_text ( code_block ) ;
109
+ let text = playground_text ( code_block ) ;
110
110
let classes = code_block . querySelector ( 'code' ) . classList ;
111
111
let has_2018 = classes . contains ( "edition2018" ) ;
112
112
let edition = has_2018 ? "2018" : "2015" ;
@@ -200,10 +200,10 @@ function playpen_text(playpen) {
200
200
} ) ;
201
201
} ) ;
202
202
203
- if ( window . playpen_copyable ) {
203
+ if ( window . playground_copyable ) {
204
204
Array . from ( document . querySelectorAll ( 'pre code' ) ) . forEach ( function ( block ) {
205
205
var pre_block = block . parentNode ;
206
- if ( ! pre_block . classList . contains ( 'playpen ' ) ) {
206
+ if ( ! pre_block . classList . contains ( 'playground ' ) ) {
207
207
var buttons = pre_block . querySelector ( ".buttons" ) ;
208
208
if ( ! buttons ) {
209
209
buttons = document . createElement ( 'div' ) ;
@@ -222,8 +222,8 @@ function playpen_text(playpen) {
222
222
} ) ;
223
223
}
224
224
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 ) {
227
227
// Add play button
228
228
var buttons = pre_block . querySelector ( ".buttons" ) ;
229
229
if ( ! buttons ) {
@@ -243,7 +243,7 @@ function playpen_text(playpen) {
243
243
run_rust_code ( pre_block ) ;
244
244
} ) ;
245
245
246
- if ( window . playpen_copyable ) {
246
+ if ( window . playground_copyable ) {
247
247
var copyCodeClipboardButton = document . createElement ( 'button' ) ;
248
248
copyCodeClipboardButton . className = 'fa fa-copy clip-button' ;
249
249
copyCodeClipboardButton . innerHTML = '<i class="tooltiptext"></i>' ;
@@ -456,6 +456,11 @@ function playpen_text(playpen) {
456
456
// Toggle sidebar
457
457
sidebarToggleButton . addEventListener ( 'click' , function sidebarToggle ( ) {
458
458
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
+ }
459
464
showSidebar ( ) ;
460
465
} else if ( html . classList . contains ( "sidebar-visible" ) ) {
461
466
hideSidebar ( ) ;
@@ -476,7 +481,16 @@ function playpen_text(playpen) {
476
481
html . classList . add ( 'sidebar-resizing' ) ;
477
482
}
478
483
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
+ }
480
494
}
481
495
//on mouseup remove windows functions mousemove & mouseup
482
496
function stopResize ( e ) {
@@ -558,8 +572,8 @@ function playpen_text(playpen) {
558
572
var clipboardSnippets = new ClipboardJS ( '.clip-button' , {
559
573
text : function ( trigger ) {
560
574
hideTooltip ( trigger ) ;
561
- let playpen = trigger . closest ( "pre" ) ;
562
- return playpen_text ( playpen ) ;
575
+ let playground = trigger . closest ( "pre" ) ;
576
+ return playground_text ( playground ) ;
563
577
}
564
578
} ) ;
565
579
0 commit comments