| 1 |
/** |
| 2 |
* Just copy content to the clipboard |
| 3 |
* using the .copy-to-clipboard class |
| 4 |
* |
| 5 |
* @version 1.0 |
| 6 |
*/ |
| 7 |
(function($){ |
| 8 |
/* |
| 9 |
* Add the icon which indicates the copy to clipboard |
| 10 |
*/ |
| 11 |
$(document).ready(function() { |
| 12 |
$(document).find('.copy-to-clipboard').each(function () { |
| 13 |
$(this).wrap('<div class="copy-to-clipboard-wrapper"></div>'); |
| 14 |
$(this).parent().append('<div class="copy-icon dashicons dashicons-admin-page"></div>'); |
| 15 |
}); |
| 16 |
}); |
| 17 |
|
| 18 |
/* |
| 19 |
* Add the copy to clipboard function |
| 20 |
*/ |
| 21 |
$(document).on('click','.copy-to-clipboard-wrapper .copy-icon', function(){ |
| 22 |
var copyText = $(this).parent().find('.copy-to-clipboard').html(); |
| 23 |
copyText = copyText.trim(); |
| 24 |
navigator.clipboard.writeText(copyText); |
| 25 |
|
| 26 |
$(this).removeClass('dashicons-admin-page').addClass('dashicons-yes'); |
| 27 |
|
| 28 |
var c = $(this); |
| 29 |
setTimeout(function(){ |
| 30 |
c.removeClass('dashicons-yes').addClass('dashicons-admin-page'); |
| 31 |
}, 2500); |
| 32 |
}); |
| 33 |
})(jQuery) |