Skip to content

Commit

Permalink
Merge branch 'robertmuehsig-enhance-copytoclipboard' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenba committed May 12, 2016
2 parents 9c0cde5 + 965ff93 commit 9626cb8
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 23 deletions.
4 changes: 2 additions & 2 deletions content/PROD/Home.html
Expand Up @@ -31,10 +31,10 @@ <h1>What is NuGet?</h1>
<section class="release">
<h2>Latest NuGet Releases</h2>
<p>
NuGet 3.4.2 for Visual Studio 2015 was released on November April 9th 2016. NuGet 2.8.7 for Visual Studio 2013 was released on July 27th 2015. <strong>Upgrade now</strong> using the Visual Studio Extension Manager.
NuGet 3.4.3 for Visual Studio 2015 was released on April 22nd, 2016. NuGet 2.8.7 for Visual Studio 2013 was released on July 27th 2015. <strong>Upgrade now</strong> using the Visual Studio Extension Manager.
</p>
<p>
For details about what's in the 3.4.2 release, read the <a href="https://docs.nuget.org/release-notes/nuget-3.4.2">release notes</a>.
For details about what's in the 3.4.3 release, read the <a href="https://docs.nuget.org/release-notes/nuget-3.4.3">release notes</a>.
</p>
<p>
For details about what's in the 2.8.7 release, read the <a href="https://docs.nuget.org/release-notes/nuget-2.8.7">release notes</a>.
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Pages/About.cshtml
Expand Up @@ -38,7 +38,7 @@

<h3>The NuGet Team</h3>
<p>
These are contributors from the NuGet team, including current and past team members. The NuGet team works on the <a href="https://github.com/NuGet">NuGet Gallery</a>, and the <a href="https://nuget.codeplex.com">NuGet Client tools</a> (Visual Studio Extension, nuget.exe, etc).
These are contributors from the NuGet team, including current and past team members. The NuGet team works on the <a href="https://github.com/NuGet">NuGet Gallery</a>, and the <a href="https://github.com/NuGet/Home">NuGet Client tools</a> (Visual Studio Extension, nuget.exe, etc).
</p>
<ul class="contributor-list" id="team"></ul>

Expand Down
95 changes: 75 additions & 20 deletions src/NuGetGallery/Views/Users/Account.cshtml
Expand Up @@ -421,7 +421,7 @@
else
{
<span id="key">@apiKey.Value</span>
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyToClipboard('@apiKey.Value', this)"><i class="icon-copy"></i></button>
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyTextToClipboard('@apiKey.Value')"><i class="icon-copy"></i></button>
}
</text>,
actions: @<text>
Expand All @@ -443,7 +443,7 @@
{
<p>
Your API key provides you with a token that can identify you to the gallery. The
<a href="http://nuget.codeplex.com/">NuGet</a> command-line utility allows you to
<a href="https://docs.nuget.org/Consume/Command-Line-Reference">NuGet</a> command-line utility allows you to
submit a NuGet package to the gallery using your API key to authenticate.
To get an API Key you will need to <a href="@Url.ConfirmationRequired()">confirm your account.</a>
</p>
Expand All @@ -452,7 +452,7 @@
{
<p>
An API key provides you with a token that can identify you to the gallery. The
<a href="http://nuget.codeplex.com/">NuGet</a> command-line utility allows you to
<a href="https://docs.nuget.org/Consume/Command-Line-Reference">NuGet</a> command-line utility allows you to
submit a NuGet package to the gallery using your API key to authenticate.
</p>
}
Expand All @@ -462,7 +462,7 @@
Your API key provides you with a token that identifies you to the gallery.
Keep this a secret. You can always regenerate your key at any time (invalidating
previous keys) if your token is accidentally revealed. The
<a href="http://nuget.codeplex.com/">NuGet</a> command-line utility allows you to
<a href="https://docs.nuget.org/Consume/Command-Line-Reference">NuGet</a> command-line utility allows you to
submit a NuGet package to the gallery, and you would pass your token like this:
</p>

Expand All @@ -471,9 +471,9 @@
<div id="account-apikeysample">
<div>
nuget.exe setApiKey @apiKey.Value
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyToClipboard('nuget.exe setApiKey @apiKey.Value', this)"><i class="icon-copy"></i></button>
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyTextToClipboard('nuget.exe setApiKey @apiKey.Value -Source https://www.nuget.org/api/v2/package')"><i class="icon-copy"></i></button>
</div>
<div>nuget.exe push MyPackage.1.0.nupkg</div>
<div>nuget.exe push MyPackage.1.0.nupkg -Source https://www.nuget.org/api/v2/package</div>
</div>
</p>
}
Expand Down Expand Up @@ -503,22 +503,77 @@
return false;
}

// use execCommand copy and a dynamic textarea as source for the text
// requestingElement is used as the parent for the dynamic textarea, otherwise
// MS Edge might "jump" to the newly created item if you append it as child of the body
function copyToClipboard(text, requestingElement) {
// source: http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
// enhancement with special case for IEs, otherwise the temp textarea will be visible
function copyTextToClipboard(text) {
if (detectIE()) {
window.clipboardData.setData('Text', text);
} else {
var textField = document.createElement('textarea');
textField.setAttribute('style', 'display: hidden');
textField.innerText = text;
requestingElement.appendChild(textField);
textField.select();
document.execCommand('copy');
textField.remove();
try {
window.clipboardData.setData('Text', text);
console.log('Copying text command via IE-setData');
} catch (err) {
console.log('Oops, unable to copy via IE-setData');
}
}

else {

var textArea = document.createElement("textarea");

//
// This styling is an extra step which is likely not required.
//
// Why is it here? To ensure:
// 1. the element is able to have focus and selection.
// 2. if element was to flash render it has minimal visual impact.
// 3. less flakyness with selection and copying which might occur if
// the textarea element is not visible.
//
// The likelihood is the element won't even render, not even a flash,
// so some of these are just precautions.
//
// However in IE the element
// is visible whilst the popup box asking the user for permission for
// the web page to copy to the clipboard. To prevent this, we are using
// the detectIE workaround.
// Place in top-left corner of screen regardless of scroll position.
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;

// Ensure it has a small width and height. Setting to 1px / 1em
// doesn't work as this gives a negative w/h on some browsers.
textArea.style.width = '2em';
textArea.style.height = '2em';

// We don't need padding, reducing the size if it does flash render.
textArea.style.padding = 0;

// Clean up any borders.
textArea.style.border = 'none';
textArea.style.outline = 'none';
textArea.style.boxShadow = 'none';

// Avoid flash of white box if rendered for any reason.
textArea.style.background = 'transparent';


textArea.value = text;

document.body.appendChild(textArea);

textArea.select();

try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}

document.body.removeChild(textArea);
}

}
</script>
}

0 comments on commit 9626cb8

Please sign in to comment.