Skip to content

Commit eb917aa

Browse files
authored
Merge pull request #14 from mwomick/bug-fix-copy
bug fix: copy button should copy points not static text
2 parents c70d0eb + 65929b6 commit eb917aa

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

index.html

+2-3
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>
@@ -138,7 +138,6 @@ <h2>JSON Points</h2>
138138
</div>
139139
</div>
140140
</div>
141-
142141
<div class="image-container">
143142
<canvas id="canvas"></canvas>
144143
</div>

script.js

+13-5
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

@@ -242,14 +244,14 @@ window.addEventListener('keyup', function(e) {
242244
}
243245
});
244246

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

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

255257
canvas.addEventListener('dragover', function(e) {
@@ -423,7 +425,7 @@ function writePoints(parentPoints) {
423425

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

@@ -620,6 +622,12 @@ function clearAll() {
620622
offScreenCtx.clearRect(0, 0, offScreenCanvas.width, offScreenCanvas.height);
621623
mainCtx.drawImage(img, 0, 0);
622624
offScreenCtx.drawImage(img, 0, 0);
625+
points = [];
626+
masterPoints = [];
627+
masterColors = [];
628+
rgb_color = color_choices[0];
629+
document.querySelector('#jsonCode').innerHTML = '';
630+
document.querySelector('#pythonCode').innerHTML = '';
623631
}
624632

625633
document.querySelector('#clear').addEventListener('click', function(e) {

0 commit comments

Comments
 (0)