mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
5ac0f751aa
723da4a37 Vendor the theme git-subtree-dir: docs git-subtree-split: 723da4a3769ee8a6c02758b553618143f92fccef
30 lines
925 B
JavaScript
30 lines
925 B
JavaScript
var Clipboard = require('clipboard/dist/clipboard.js');
|
|
new Clipboard('.copy', {
|
|
target: function(trigger) {
|
|
if(trigger.classList.contains('copy-toggle')){
|
|
return trigger.previousElementSibling;
|
|
}
|
|
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;
|
|
}
|