yakindu.js 1.2 KB

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