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

[JENKINS-21052] Warn user that the copy button requires HTTPS #7665

Merged
merged 1 commit into from
Feb 26, 2023
Merged
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
45 changes: 26 additions & 19 deletions core/src/main/resources/lib/layout/copyButton/copyButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,35 @@ Behaviour.specify(
0,
function (copyButton) {
copyButton.addEventListener("click", () => {
// Make an invisible textarea element containing the text
const fakeInput = document.createElement("textarea");
fakeInput.value = copyButton.getAttribute("text");
fakeInput.style.width = "1px";
fakeInput.style.height = "1px";
fakeInput.style.border = "none";
fakeInput.style.padding = "0px";
fakeInput.style.position = "absolute";
fakeInput.style.top = "-99999px";
fakeInput.style.left = "-99999px";
fakeInput.setAttribute("tabindex", "-1");
document.body.appendChild(fakeInput);
if (isSecureContext) {
// Make an invisible textarea element containing the text
const fakeInput = document.createElement("textarea");
fakeInput.value = copyButton.getAttribute("text");
fakeInput.style.width = "1px";
fakeInput.style.height = "1px";
fakeInput.style.border = "none";
fakeInput.style.padding = "0px";
fakeInput.style.position = "absolute";
fakeInput.style.top = "-99999px";
fakeInput.style.left = "-99999px";
fakeInput.setAttribute("tabindex", "-1");
document.body.appendChild(fakeInput);

// Select the text and copy it to the clipboard
fakeInput.select();
navigator.clipboard.writeText(fakeInput.value);
// Select the text and copy it to the clipboard
fakeInput.select();
navigator.clipboard.writeText(fakeInput.value);

// Remove the textarea element
document.body.removeChild(fakeInput);
// Remove the textarea element
document.body.removeChild(fakeInput);

// Show the completion message
hoverNotification(copyButton.getAttribute("message"), copyButton);
// Show the completion message
hoverNotification(copyButton.getAttribute("message"), copyButton);
} else {
hoverNotification(
"Copy is only supported with a secure (HTTPS) connection",
copyButton
);
}
});
}
);