From ada5d2f9dc0198226e8566fb06a04b2f8d09b3d3 Mon Sep 17 00:00:00 2001 From: r00ster Date: Fri, 30 Apr 2021 10:18:14 +0200 Subject: [PATCH 1/3] Reset the docs' copy path button after 1 second --- src/librustdoc/html/static/main.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 95b18490641ff..772a63c86b8a8 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1490,6 +1490,8 @@ function hideThemeButtonState() { searchState.setup(); }()); +let reset_button_timeout; + function copy_path(but) { var parent = but.parentElement; var path = []; @@ -1513,4 +1515,12 @@ function copy_path(but) { document.body.removeChild(el); but.textContent = '✓'; + + window.clearTimeout(reset_button_timeout); + + function reset_button() { + but.textContent = '⎘'; + } + + reset_button_timeout = window.setTimeout(reset_button, 1000); } From c4fe7c4a309f4403e42f11edc08a3bfac53dfce1 Mon Sep 17 00:00:00 2001 From: r00ster Date: Fri, 30 Apr 2021 11:42:07 +0200 Subject: [PATCH 2/3] Apply suggestions --- src/librustdoc/html/static/main.js | 63 ++++++++++++++++-------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 772a63c86b8a8..ed590e17af044 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1490,37 +1490,42 @@ function hideThemeButtonState() { searchState.setup(); }()); -let reset_button_timeout; +(function () { + var reset_button_timeout = null; + + function copy_path(but) { + var parent = but.parentElement; + var path = []; + + onEach(parent.childNodes, function(child) { + if (child.tagName === 'A') { + path.push(child.textContent); + } + }); + + var el = document.createElement('textarea'); + el.value = 'use ' + path.join('::') + ';'; + el.setAttribute('readonly', ''); + // To not make it appear on the screen. + el.style.position = 'absolute'; + el.style.left = '-9999px'; -function copy_path(but) { - var parent = but.parentElement; - var path = []; + document.body.appendChild(el); + el.select(); + document.execCommand('copy'); + document.body.removeChild(el); - onEach(parent.childNodes, function(child) { - if (child.tagName === 'A') { - path.push(child.textContent); + but.textContent = '✓'; + + if (reset_button_timeout !== null) { + window.clearTimeout(reset_button_timeout); + } + + function reset_button() { + but.textContent = '⎘'; + reset_button_timeout = null; } - }); - var el = document.createElement('textarea'); - el.value = 'use ' + path.join('::') + ';'; - el.setAttribute('readonly', ''); - // To not make it appear on the screen. - el.style.position = 'absolute'; - el.style.left = '-9999px'; - - document.body.appendChild(el); - el.select(); - document.execCommand('copy'); - document.body.removeChild(el); - - but.textContent = '✓'; - - window.clearTimeout(reset_button_timeout); - - function reset_button() { - but.textContent = '⎘'; + reset_button_timeout = window.setTimeout(reset_button, 1000); } - - reset_button_timeout = window.setTimeout(reset_button, 1000); -} +}()); From bea99a5da6acaa30cf27cd8d6268527ff24ee77e Mon Sep 17 00:00:00 2001 From: r00ster Date: Fri, 30 Apr 2021 12:06:15 +0200 Subject: [PATCH 3/3] `copy_path` -> `window.copy_path` + add semicolon --- src/librustdoc/html/static/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index ed590e17af044..e81eaca8f0e40 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1493,7 +1493,7 @@ function hideThemeButtonState() { (function () { var reset_button_timeout = null; - function copy_path(but) { + window.copy_path = function(but) { var parent = but.parentElement; var path = []; @@ -1527,5 +1527,5 @@ function hideThemeButtonState() { } reset_button_timeout = window.setTimeout(reset_button, 1000); - } + }; }());