Skip to content

Instantly share code, notes, and snippets.

@ritcheyer
Last active April 13, 2017 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritcheyer/1e3d947602964d41496bdb6a61ffb6b0 to your computer and use it in GitHub Desktop.
Save ritcheyer/1e3d947602964d41496bdb6a61ffb6b0 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
/// other things up here
$('.tsla-card_container').on('click', '.tsla-card_tile', function() {
var $this = $(this);
if ($this.hasClass('tsla-card-has_overlay')) {
var toCopy = $this.find('.tsla-card_tile--meta').text();
copyColorVariable(toCopy, $this);
}
});
// create temporary input holder for copying to clipboard
// once copied, destroy temp input holder
// if copy is successful, alert the user
function copyColorVariable(text) {
var $tempInput = document.createElement('input'),
$body = document.getElementsByTagName('body')[0];
$tempInput.value = text;
$body.appendChild($tempInput);
$tempInput.select();
try {
success = document.execCommand('copy');
} catch (e) {
console.log('Was unable to copy');
}
if (success) {
// remove temp element.
$tempInput.remove();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment