Last active
April 13, 2017 06:12
-
-
Save ritcheyer/1e3d947602964d41496bdb6a61ffb6b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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