2017-08-10 11:18:22 -04:00
|
|
|
var Clipboard = require('clipboard/dist/clipboard.js');
|
|
|
|
new Clipboard('.copy', {
|
|
|
|
target: function(trigger) {
|
2018-04-02 02:53:34 -04:00
|
|
|
if(trigger.classList.contains('copy-toggle')){
|
|
|
|
return trigger.previousElementSibling;
|
|
|
|
}
|
2017-08-10 11:18:22 -04:00
|
|
|
return trigger.nextElementSibling;
|
|
|
|
}
|
|
|
|
}).on('success', function(e) {
|
|
|
|
successMessage(e.trigger, 'Copied!');
|
|
|
|
e.clearSelection();
|
|
|
|
}).on('error', function(e) {
|
|
|
|
successMessage(e.trigger, fallbackMessage(e.action));
|
|
|
|
});
|
|
|
|
|
|
|
|
function successMessage(elem, msg) {
|
|
|
|
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');
|
|
|
|
elem.setAttribute('aria-label', msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function fallbackMessage(elem, action) {
|
|
|
|
var actionMsg = '';
|
|
|
|
var actionKey = (action === 'cut' ? 'X' : 'C');
|
|
|
|
if (isMac) {
|
|
|
|
actionMsg = 'Press ⌘-' + actionKey;
|
|
|
|
} else {
|
|
|
|
actionMsg = 'Press Ctrl-' + actionKey;
|
|
|
|
}
|
|
|
|
return actionMsg;
|
|
|
|
}
|