2016-07-24 20:45:11 +00:00
|
|
|
|
|
|
|
/*= require clipboard */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var genericError, genericSuccess, showTooltip;
|
|
|
|
|
|
|
|
genericSuccess = function(e) {
|
|
|
|
showTooltip(e.trigger, 'Copied!');
|
2016-07-27 03:32:10 +00:00
|
|
|
// Clear the selection and blur the trigger so it loses its border
|
2016-07-24 20:45:11 +00:00
|
|
|
e.clearSelection();
|
|
|
|
return $(e.trigger).blur();
|
|
|
|
};
|
|
|
|
|
2016-07-27 03:32:10 +00:00
|
|
|
// Safari doesn't support `execCommand`, so instead we inform the user to
|
|
|
|
// copy manually.
|
|
|
|
//
|
|
|
|
// See http://clipboardjs.com/#browser-support
|
2016-07-24 20:45:11 +00:00
|
|
|
genericError = function(e) {
|
|
|
|
var key;
|
|
|
|
if (/Mac/i.test(navigator.userAgent)) {
|
2016-07-27 03:32:10 +00:00
|
|
|
key = '⌘'; // Command
|
2016-07-24 20:45:11 +00:00
|
|
|
} else {
|
|
|
|
key = 'Ctrl';
|
|
|
|
}
|
|
|
|
return showTooltip(e.trigger, "Press " + key + "-C to copy");
|
|
|
|
};
|
|
|
|
|
|
|
|
showTooltip = function(target, title) {
|
|
|
|
return $(target).tooltip({
|
|
|
|
container: 'body',
|
|
|
|
html: 'true',
|
|
|
|
placement: 'auto bottom',
|
|
|
|
title: title,
|
|
|
|
trigger: 'manual'
|
|
|
|
}).tooltip('show').one('mouseleave', function() {
|
|
|
|
return $(this).tooltip('hide');
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
var clipboard;
|
2016-08-02 08:58:09 +00:00
|
|
|
|
2016-08-10 13:35:14 +00:00
|
|
|
clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
|
|
|
|
clipboard.on('success', genericSuccess);
|
|
|
|
return clipboard.on('error', genericError);
|
2016-07-24 20:45:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|