Skip to content
Merged
Changes from 2 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
55 changes: 35 additions & 20 deletions src/librustdoc/html/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1490,27 +1490,42 @@ function hideThemeButtonState() {
searchState.setup();
}());

function copy_path(but) {
var parent = but.parentElement;
var path = [];
(function () {
var reset_button_timeout = null;

onEach(parent.childNodes, function(child) {
if (child.tagName === 'A') {
path.push(child.textContent);
}
});
function copy_path(but) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to put this function into window, otherwise the onclick event won't find it.

window.copy_path = copy_path;

Or you can declare it directly like this:

Suggested change
function copy_path(but) {
window.copy_path = function(but) {

(and don't forget the ; at the end ;) )

var parent = but.parentElement;
var path = [];

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';
onEach(parent.childNodes, function(child) {
if (child.tagName === 'A') {
path.push(child.textContent);
}
});

document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
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';

but.textContent = '✓';
}
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);

but.textContent = '✓';

if (reset_button_timeout !== null) {
window.clearTimeout(reset_button_timeout);
}

function reset_button() {
but.textContent = '⎘';
reset_button_timeout = null;
}

reset_button_timeout = window.setTimeout(reset_button, 1000);
}
}());