This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 654ec2c Move the script for copying text to clipboard
654ec2c is described below
commit 654ec2c3bae241810075796500ce95d78d2cb3bb
Author: Sean B. Palmer <[email protected]>
AuthorDate: Wed Dec 10 14:47:46 2025 +0000
Move the script for copying text to clipboard
---
atr/get/vote.py | 2 +-
atr/static/js/atr.js | 40 ---------------------------------------
atr/static/js/clipboard-copy.js | 32 +++++++++++++++++++++++++++++++
atr/template.py | 15 +++++++++++++--
atr/templates/blank.html | 3 ---
atr/templates/check-selected.html | 2 --
atr/templates/layouts/base.html | 1 -
7 files changed, 46 insertions(+), 49 deletions(-)
diff --git a/atr/get/vote.py b/atr/get/vote.py
index f2fe7e0..d8b8b7b 100644
--- a/atr/get/vote.py
+++ b/atr/get/vote.py
@@ -122,7 +122,7 @@ async def render_options_page(
return await template.blank(
f"Vote on {release.project.short_display_name} {release.version}",
content=page.collect(),
- init_js=True,
+ javascripts=["clipboard-copy"],
)
diff --git a/atr/static/js/atr.js b/atr/static/js/atr.js
deleted file mode 100644
index daee006..0000000
--- a/atr/static/js/atr.js
+++ /dev/null
@@ -1,40 +0,0 @@
-function init() {
- document.addEventListener("DOMContentLoaded", function () {
- const copyButtons = document.querySelectorAll(".atr-copy-btn");
-
- copyButtons.forEach(button => {
- button.addEventListener("click", function () {
- const targetId = this.getAttribute("data-clipboard-target");
- const targetElement = document.querySelector(targetId);
-
- if (targetElement) {
- const textToCopy = targetElement.textContent;
-
- navigator.clipboard.writeText(textToCopy)
- .then(() => {
- const originalText = this.innerHTML;
- this.innerHTML = '<i class="fas fa-check"></i>
Copied!';
-
- // Reset the button text after 2000ms
- setTimeout(() => {
- this.innerHTML = originalText;
- }, 2000);
- })
- .catch(err => {
- console.error("Failed to copy: ", err);
- this.innerHTML = '<i class="fas
fa-exclamation-triangle"></i> Failed!';
-
- setTimeout(() => {
- this.innerHTML = '<i class="fas
fa-clipboard"></i> Copy';
- }, 2000);
- });
- }
- });
- });
- });
-}
-
-function updateDeleteButton(inputElement, buttonId) {
- let button = document.getElementById(buttonId);
- button.disabled = inputElement.value !== "DELETE";
-}
diff --git a/atr/static/js/clipboard-copy.js b/atr/static/js/clipboard-copy.js
new file mode 100644
index 0000000..b15eccc
--- /dev/null
+++ b/atr/static/js/clipboard-copy.js
@@ -0,0 +1,32 @@
+document.addEventListener("DOMContentLoaded", function () {
+ const copyButtons = document.querySelectorAll(".atr-copy-btn");
+
+ copyButtons.forEach(button => {
+ button.addEventListener("click", function () {
+ const targetId = this.getAttribute("data-clipboard-target");
+ const targetElement = document.querySelector(targetId);
+
+ if (targetElement) {
+ const textToCopy = targetElement.textContent;
+
+ navigator.clipboard.writeText(textToCopy)
+ .then(() => {
+ const originalText = this.innerHTML;
+ this.innerHTML = '<i class="bi bi-check"></i> Copied!';
+
+ setTimeout(() => {
+ this.innerHTML = originalText;
+ }, 2000);
+ })
+ .catch(err => {
+ console.error("Failed to copy: ", err);
+ this.innerHTML = '<i class="bi
bi-exclamation-triangle"></i> Failed!';
+
+ setTimeout(() => {
+ this.innerHTML = '<i class="bi bi-clipboard"></i>
Copy';
+ }, 2000);
+ });
+ }
+ });
+ });
+});
diff --git a/atr/template.py b/atr/template.py
index d175a6d..979c995 100644
--- a/atr/template.py
+++ b/atr/template.py
@@ -24,13 +24,24 @@ import quart.app as app
import quart.signals as signals
import atr.htm as htm
+import atr.util as util
render_async = quart.render_template
-async def blank(title: str, content: str | htm.Element, description: str |
None = None, init_js: bool = False) -> str:
+async def blank(
+ title: str,
+ content: str | htm.Element,
+ description: str | None = None,
+ javascripts: list[str] | None = None,
+) -> str:
+ js_urls = [util.static_url(f"js/{name}.js") for name in javascripts or []]
return await render_sync(
- "blank.html", title=title, description=description or title,
content=content, init_js=init_js
+ "blank.html",
+ title=title,
+ description=description or title,
+ content=content,
+ javascripts=js_urls,
)
diff --git a/atr/templates/blank.html b/atr/templates/blank.html
index 0994483..45f7602 100644
--- a/atr/templates/blank.html
+++ b/atr/templates/blank.html
@@ -13,7 +13,4 @@
{% if javascripts %}
{% for js in javascripts %}<script src="{{- js -}}"></script>{% endfor %}
{% endif %}
- {% if init_js %}<script>
- init();
- </script>{% endif %}
{% endblock javascripts %}
diff --git a/atr/templates/check-selected.html
b/atr/templates/check-selected.html
index c798f3e..9f86cdd 100644
--- a/atr/templates/check-selected.html
+++ b/atr/templates/check-selected.html
@@ -196,8 +196,6 @@
{% block javascripts %}
{{ super() }}
<script>
- init();
-
(function() {
const banner = document.getElementById("ongoing-tasks-banner");
if (!banner) return;
diff --git a/atr/templates/layouts/base.html b/atr/templates/layouts/base.html
index c80ea46..01fe976 100644
--- a/atr/templates/layouts/base.html
+++ b/atr/templates/layouts/base.html
@@ -65,7 +65,6 @@
{% block javascripts %}
<script src="{{ static_url('js/bootstrap.bundle.min.js') }}"></script>
- <script src="{{ static_url('js/atr.js') }}"></script>
{% endblock javascripts %}
</body>
</html>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]