Last active
January 21, 2016 20:46
-
-
Save dan-westall/ec07b51168dc58bb6f2a to your computer and use it in GitHub Desktop.
Browser snippet to add a copy slug to clipboard link to wp plugin page. Handy for when working with dev sites and wp cli
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
( function($){ | |
function copyToClipboard(text) { | |
const input = document.createElement('input'); | |
input.style.position = 'fixed'; | |
input.style.opacity = 0; | |
input.value = text; | |
document.body.appendChild(input); | |
input.select(); | |
document.execCommand('Copy'); | |
document.body.removeChild(input); | |
}; | |
$('[data-slug]').each( function(i, el ){ | |
var $el = $(this); | |
var $link = $('<a />') | |
.attr('href', 'javascript:void(0);') | |
.attr('data-plugin-slug', $el.data('slug') ) | |
.text('Copy Slug'); | |
$el.find('.row-actions') | |
.append( $('<span> | </span>') | |
.append( $link ) ); | |
$link.click( function(e){ | |
e.preventDefault(); | |
copyToClipboard( $(this).data('plugin-slug') ); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment