@@ -64,6 +64,8 @@ function blitCachedCanvas() {
64
64
65
65
function clipboard ( selector ) {
66
66
var copyText = document . querySelector ( selector ) . innerText ;
67
+ // strip whitespace on left and right
68
+ copyText = copyText . replace ( / ^ \s + | \s + $ / g, '' ) ;
67
69
navigator . clipboard . writeText ( copyText ) ;
68
70
}
69
71
@@ -244,12 +246,12 @@ window.addEventListener('keyup', function(e) {
244
246
245
247
document . querySelector ( '#copyPythonButton' ) . addEventListener ( 'click' , function ( e ) {
246
248
e . preventDefault ( ) ;
247
- clipboard ( "#pythonCode " ) ;
249
+ clipboard ( "#python " ) ;
248
250
} ) ;
249
251
250
252
document . querySelector ( '#copyJSONButton' ) . addEventListener ( 'click' , function ( e ) {
251
253
e . preventDefault ( ) ;
252
- clipboard ( "#jsonCode " ) ;
254
+ clipboard ( "#json " ) ;
253
255
} ) ;
254
256
255
257
canvas . addEventListener ( 'dragover' , function ( e ) {
@@ -422,8 +424,8 @@ function writePoints(parentPoints) {
422
424
parentPoints = parentPoints . filter ( points => ! ! points . length ) ;
423
425
424
426
if ( ! parentPoints . length ) {
425
- document . querySelector ( '#pythonCode ' ) . innerHTML = '' ;
426
- document . querySelector ( '#jsonCode ' ) . innerHTML ;
427
+ document . querySelector ( '#python ' ) . innerHTML = '' ;
428
+ document . querySelector ( '#json ' ) . innerHTML ;
427
429
return ;
428
430
}
429
431
@@ -433,14 +435,14 @@ function writePoints(parentPoints) {
433
435
return `[${ point [ 0 ] } , ${ point [ 1 ] } ]` ; } ) . join ( ', ' ) } ])`;
434
436
} ) . join ( ',\n' ) } \n]`;
435
437
436
- document . querySelector ( '#pythonCode ' ) . innerHTML = code_template ;
438
+ document . querySelector ( '#python ' ) . innerHTML = code_template ;
437
439
438
440
var json_template = `{\n${ parentPoints . map ( function ( points ) {
439
441
return ` [${ points . map ( function ( point ) {
440
442
return `{"x": ${ point [ 0 ] } , "y": ${ point [ 1 ] } }` ; } ) . join ( ', ' ) } ]`;
441
443
} ) . join ( ',\n' ) } \n}`;
442
444
443
- document . querySelector ( '#jsonCode ' ) . innerHTML = json_template ;
445
+ document . querySelector ( '#json ' ) . innerHTML = json_template ;
444
446
}
445
447
446
448
canvas . addEventListener ( 'mousedown' , function ( e ) {
0 commit comments