2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
/*= require clipboard */
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
var genericError, genericSuccess, showTooltip;
|
|
|
|
|
|
|
|
genericSuccess = function(e) {
|
|
|
|
showTooltip(e.trigger, 'Copied!');
|
2016-09-29 09:46:39 +05:30
|
|
|
// Clear the selection and blur the trigger so it loses its border
|
2016-09-13 17:45:13 +05:30
|
|
|
e.clearSelection();
|
|
|
|
return $(e.trigger).blur();
|
|
|
|
};
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
// Safari doesn't support `execCommand`, so instead we inform the user to
|
|
|
|
// copy manually.
|
|
|
|
//
|
|
|
|
// See http://clipboardjs.com/#browser-support
|
2016-09-13 17:45:13 +05:30
|
|
|
genericError = function(e) {
|
|
|
|
var key;
|
|
|
|
if (/Mac/i.test(navigator.userAgent)) {
|
2016-09-29 09:46:39 +05:30
|
|
|
key = '⌘'; // Command
|
2016-09-13 17:45:13 +05:30
|
|
|
} else {
|
|
|
|
key = 'Ctrl';
|
|
|
|
}
|
|
|
|
return showTooltip(e.trigger, "Press " + key + "-C to copy");
|
|
|
|
};
|
|
|
|
|
|
|
|
showTooltip = function(target, title) {
|
2016-11-03 12:29:30 +05:30
|
|
|
var $target = $(target);
|
|
|
|
var originalTitle = $target.data('original-title');
|
|
|
|
|
|
|
|
$target
|
|
|
|
.attr('title', 'Copied!')
|
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip('show')
|
|
|
|
.attr('title', originalTitle)
|
|
|
|
.tooltip('fixTitle');
|
2016-09-13 17:45:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
var clipboard;
|
|
|
|
|
|
|
|
clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
|
|
|
|
clipboard.on('success', genericSuccess);
|
|
|
|
return clipboard.on('error', genericError);
|
|
|
|
});
|
|
|
|
|
|
|
|
}).call(this);
|