From dc0c358c00dee596d04a8574640b977aede0b96b Mon Sep 17 00:00:00 2001 From: Yaroslav <91559310+yaroslavafenkin@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:54:13 +0300 Subject: [PATCH] [JENKINS-73944] Extract inline event handler from `POSTHyperlinkNote` (#284) --- .../support/steps/input/POSTHyperlinkNote.java | 2 +- .../support/steps/input/POSTHyperlinkNote/script.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote/script.js diff --git a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote.java b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote.java index 2d31998e..3bec0361 100644 --- a/src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote.java +++ b/src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote.java @@ -83,7 +83,7 @@ public POSTHyperlinkNote(String url, int length) { @Override protected String extraAttributes() { // TODO perhaps add hoverNotification - return " onclick=\"fetch(decodeURIComponent(atob('" + encodeForJavascript(url) + "')), { method: 'post', headers: crumb.wrap({})}); return false\""; + return " data-encoded-url='" + encodeForJavascript(url) + "' class='post-hyperlink-note-button'"; } /** diff --git a/src/main/resources/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote/script.js b/src/main/resources/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote/script.js new file mode 100644 index 00000000..2d5b0a29 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/workflow/support/steps/input/POSTHyperlinkNote/script.js @@ -0,0 +1,10 @@ +Behaviour.specify("A.post-hyperlink-note-button", "POSTHyperLinkNote", 0, function (element) { + element.addEventListener("click", (event) => { + event.preventDefault(); + const url = decodeURIComponent(atob(element.dataset.encodedUrl)); + fetch(url, { + method: "post", + headers: crumb.wrap({}), + }); + }); +});