github.com/rabbouni145/gg@v0.47.1/docs/themes/gohugoioTheme/src/js/clipboardjs.js (about) 1 var Clipboard = require('clipboard/dist/clipboard.js'); 2 new Clipboard('.copy', { 3 target: function(trigger) { 4 if(trigger.classList.contains('copy-toggle')){ 5 return trigger.previousElementSibling; 6 } 7 return trigger.nextElementSibling; 8 } 9 }).on('success', function(e) { 10 successMessage(e.trigger, 'Copied!'); 11 e.clearSelection(); 12 }).on('error', function(e) { 13 successMessage(e.trigger, fallbackMessage(e.action)); 14 }); 15 16 function successMessage(elem, msg) { 17 elem.setAttribute('class', 'copied bg-primary-color-dark f6 absolute top-0 right-0 lh-solid hover-bg-primary-color-dark bn white ph3 pv2'); 18 elem.setAttribute('aria-label', msg); 19 } 20 21 function fallbackMessage(elem, action) { 22 var actionMsg = ''; 23 var actionKey = (action === 'cut' ? 'X' : 'C'); 24 if (isMac) { 25 actionMsg = 'Press ⌘-' + actionKey; 26 } else { 27 actionMsg = 'Press Ctrl-' + actionKey; 28 } 29 return actionMsg; 30 }