From 4f4ca061dda9d727cadd7eefc66182bd24497802 Mon Sep 17 00:00:00 2001 From: Benjamin Chen Date: Tue, 7 Jul 2020 11:52:01 -0400 Subject: [PATCH] www: Correct UX of the copy button --- www/index.html | 53 +++++++++++++++++++++++++++++++++++++++++++------- www/rustup.js | 42 ++++++++++++++++++++++++++++++++++----- 2 files changed, 83 insertions(+), 12 deletions(-) diff --git a/www/index.html b/www/index.html index d9c33a52bc..ad979890ef 100644 --- a/www/index.html +++ b/www/index.html @@ -5,7 +5,6 @@ rustup.rs - The Rust toolchain installer - @@ -27,13 +26,13 @@

Run the following in your terminal, then follow the onscreen instructions.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-

You appear to be running Unix. If not, display all supported installers.

@@ -46,7 +45,17 @@ then follow the onscreen instructions.

If you're a Windows Subsystem for Linux user run the following in your terminal, then follow the onscreen instructions to install Rust.

-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+ +

You appear to be running Windows 32-bit. If not, display all supported installers.

@@ -57,7 +66,17 @@ then follow the onscreen instructions.

If you're a Windows Subsystem for Linux user run the following in your terminal, then follow the onscreen instructions to install Rust.

-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+ +

You appear to be running Windows 64-bit. If not, display all supported installers.

@@ -81,7 +100,17 @@

If you are running Unix,
run the following in your terminal, then follow the onscreen instructions.

-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+ +

@@ -110,7 +139,17 @@

To install Rust, if you are running Unix,
run the following in your terminal, then follow the onscreen instructions.

-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
+ +

diff --git a/www/rustup.js b/www/rustup.js index b6fdc394a4..9318fa003d 100644 --- a/www/rustup.js +++ b/www/rustup.js @@ -165,24 +165,56 @@ function fill_in_bug_report_values() { nav_app.textContent = navigator.appVersion; } -function clear_copy_status_message() { - document.getElementById('copy-status-message').innerText = ''; +function clear_copy_status_message(id) { + document.getElementById(id).innerText = ''; } -function handle_copy_button_click() { +function process_copy_button_click(id) { try { navigator.clipboard.writeText(rustup_install_command).then(function() { - document.getElementById('copy-status-message').innerText = 'Copied!' + document.getElementById(id).innerText = 'Copied!'; }); - setTimeout(clear_copy_status_message, 5000); + setTimeout(function () { + clear_copy_status_message(id); + }, 5000); } catch (e) { console.log('Hit a snag when copying to clipboard:', e); } } +function handle_copy_button_click(e) { + switch (e.id) { + case 'copy-button-unix': + process_copy_button_click('copy-status-message-unix'); + break; + case 'copy-button-win32': + process_copy_button_click('copy-status-message-win32'); + break; + case 'copy-button-win64': + process_copy_button_click('copy-status-message-win64'); + break; + case 'copy-button-unknown': + process_copy_button_click('copy-status-message-unknown'); + break; + case 'copy-button-default': + process_copy_button_click('copy-status-message-default'); + break; + } +} + +function set_up_copy_button_clicks() { + var buttons = document.querySelectorAll(".copy-button"); + buttons.forEach(function (element) { + element.addEventListener('click', function() { + handle_copy_button_click(element); + }); + }) +} + (function () { adjust_for_platform(); set_up_cycle_button(); set_up_default_platform_buttons(); + set_up_copy_button_clicks(); fill_in_bug_report_values(); }());