yakindu.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. function copyPermalinkToClipboard(event, element) {
  2. event.preventDefault();
  3. var origin = (window.location.origin != 'null') ? window.location.origin : window.location.href;
  4. var permalink = origin + window.location.pathname + '#' + jQuery(element).parent().attr('id');
  5. var textInput = document.createElement("input");
  6. textInput.style.position = 'fixed';
  7. textInput.style.top = '230px';
  8. textInput.style.left = 0;
  9. textInput.style.width = '2em';
  10. textInput.style.height = '2em';
  11. textInput.style.padding = 0;
  12. textInput.style.border = 'none';
  13. textInput.style.outline = 'none';
  14. textInput.style.boxShadow = 'none';
  15. textInput.style.background = 'transparent';
  16. textInput.value = permalink;
  17. document.body.appendChild(textInput);
  18. textInput.select();
  19. try {
  20. if (document.execCommand('copy')) {
  21. jQuery(element).find('.tooltip').html('Copied');
  22. }
  23. } catch (err) {
  24. alert('Permalink: ' + permalink);
  25. console.log('Oops, unable to copy', err);
  26. }
  27. document.body.removeChild(textInput);
  28. return false;
  29. }
  30. jQuery(document).ready(function() {
  31. jQuery('.permalink').on('focusout, mouseout', function() {
  32. jQuery(this).find('.tooltip').html('Copy link to clipboard');
  33. });
  34. });