Skip to content

Commit 65929b6

Browse files
committed
fix merge conflicts, fix buttons
1 parent 60b4597 commit 65929b6

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ <h2>How to use</h2>
4848
</ol>
4949
<h2>Coordinates</h2>
5050
<p>Copy the points below, formatted as NumPy arrays, into your Python code.</p>
51-
<a href="" id="clipboard" class="widgetButton left">Copy Python to Clipboard</a>
51+
<a href="" id="copyPythonButton" class="widgetButton left">Copy Python to Clipboard</a>
5252
<label for="normalize-checkbox">Show Normalized Points from 0-1</label>
5353
<input type="checkbox" id="normalize-checkbox" name="normalize-checkbox" value="normalize-checkbox">
5454
<pre id="python">
@@ -58,7 +58,7 @@ <h2>Coordinates</h2>
5858
<details>
5959
<summary>View JSON Points</summary>
6060
<h2>JSON Points</h2>
61-
<a href="" id="clipboardJSON" class="widgetButton">Copy JSON to Clipboard</a>
61+
<a href="" id="copyJSONButton" class="widgetButton">Copy JSON to Clipboard</a>
6262
<pre id="json">
6363
<code>
6464
</code>

script.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function blitCachedCanvas() {
6464

6565
function clipboard(selector) {
6666
var copyText = document.querySelector(selector).innerText;
67+
// strip whitespace on left and right
68+
copyText = copyText.replace(/^\s+|\s+$/g, '');
6769
navigator.clipboard.writeText(copyText);
6870
}
6971

@@ -244,12 +246,12 @@ window.addEventListener('keyup', function(e) {
244246

245247
document.querySelector('#copyPythonButton').addEventListener('click', function(e) {
246248
e.preventDefault();
247-
clipboard("#pythonCode");
249+
clipboard("#python");
248250
});
249251

250252
document.querySelector('#copyJSONButton').addEventListener('click', function(e) {
251253
e.preventDefault();
252-
clipboard("#jsonCode");
254+
clipboard("#json");
253255
});
254256

255257
canvas.addEventListener('dragover', function(e) {
@@ -422,8 +424,8 @@ function writePoints(parentPoints) {
422424
parentPoints = parentPoints.filter(points => !!points.length);
423425

424426
if (!parentPoints.length) {
425-
document.querySelector('#pythonCode').innerHTML = '';
426-
document.querySelector('#jsonCode').innerHTML;
427+
document.querySelector('#python').innerHTML = '';
428+
document.querySelector('#json').innerHTML;
427429
return;
428430
}
429431

@@ -433,14 +435,14 @@ function writePoints(parentPoints) {
433435
return `[${point[0]}, ${point[1]}]`;}).join(', ')}])`;
434436
}).join(',\n')}\n]`;
435437

436-
document.querySelector('#pythonCode').innerHTML = code_template;
438+
document.querySelector('#python').innerHTML = code_template;
437439

438440
var json_template = `{\n${parentPoints.map(function(points) {
439441
return ` [${points.map(function(point) {
440442
return `{"x": ${point[0]}, "y": ${point[1]}}`;}).join(', ')}]`;
441443
}).join(',\n')}\n}`;
442444

443-
document.querySelector('#jsonCode').innerHTML = json_template;
445+
document.querySelector('#json').innerHTML = json_template;
444446
}
445447

446448
canvas.addEventListener('mousedown', function(e) {

0 commit comments

Comments
 (0)