Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: copy button should copy points not static text #14

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2>How to use</h2>
</ol>
<h2>Coordinates</h2>
<p>Copy the points below, formatted as NumPy arrays, into your Python code.</p>
<a href="" id="clipboard" class="widgetButton left">Copy Python to Clipboard</a>
<a href="" id="copyPythonButton" class="widgetButton left">Copy Python to Clipboard</a>
<label for="normalize-checkbox">Show Normalized Points from 0-1</label>
<input type="checkbox" id="normalize-checkbox" name="normalize-checkbox" value="normalize-checkbox">
<pre id="python">
Expand All @@ -58,7 +58,7 @@ <h2>Coordinates</h2>
<details>
<summary>View JSON Points</summary>
<h2>JSON Points</h2>
<a href="" id="clipboardJSON" class="widgetButton">Copy JSON to Clipboard</a>
<a href="" id="copyJSONButton" class="widgetButton">Copy JSON to Clipboard</a>
<pre id="json">
<code>
</code>
Expand Down Expand Up @@ -138,7 +138,6 @@ <h2>JSON Points</h2>
</div>
</div>
</div>

<div class="image-container">
<canvas id="canvas"></canvas>
</div>
Expand Down
18 changes: 13 additions & 5 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function blitCachedCanvas() {

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

Expand Down Expand Up @@ -242,14 +244,14 @@ window.addEventListener('keyup', function(e) {
}
});

document.querySelector('#clipboard').addEventListener('click', function(e) {
document.querySelector('#copyPythonButton').addEventListener('click', function(e) {
e.preventDefault();
clipboard("#clipboard");
clipboard("#python");
});

document.querySelector('#clipboardJSON').addEventListener('click', function(e) {
document.querySelector('#copyJSONButton').addEventListener('click', function(e) {
e.preventDefault();
clipboard("#clipboardJSON");
clipboard("#json");
});

canvas.addEventListener('dragover', function(e) {
Expand Down Expand Up @@ -423,7 +425,7 @@ function writePoints(parentPoints) {

if (!parentPoints.length) {
document.querySelector('#python').innerHTML = '';
document.querySelector('#json').innerHTML = '';
document.querySelector('#json').innerHTML;
return;
}

Expand Down Expand Up @@ -620,6 +622,12 @@ function clearAll() {
offScreenCtx.clearRect(0, 0, offScreenCanvas.width, offScreenCanvas.height);
mainCtx.drawImage(img, 0, 0);
offScreenCtx.drawImage(img, 0, 0);
points = [];
masterPoints = [];
masterColors = [];
rgb_color = color_choices[0];
document.querySelector('#jsonCode').innerHTML = '';
document.querySelector('#pythonCode').innerHTML = '';
}

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