2017-01-10 18:02:20 -05:00
|
|
|
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, prefer-template, quotes, no-unused-vars, prefer-arrow-callback, max-len */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Clipboard */
|
2016-07-24 16:45:11 -04:00
|
|
|
|
2016-11-03 17:38:54 -04:00
|
|
|
window.Clipboard = require('vendor/clipboard');
|
2016-07-24 16:45:11 -04:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
var genericError, genericSuccess, showTooltip;
|
|
|
|
|
|
|
|
genericSuccess = function(e) {
|
2016-12-09 16:48:23 -05:00
|
|
|
showTooltip(e.trigger, 'Copied');
|
2016-07-26 23:32:10 -04:00
|
|
|
// Clear the selection and blur the trigger so it loses its border
|
2016-07-24 16:45:11 -04:00
|
|
|
e.clearSelection();
|
|
|
|
return $(e.trigger).blur();
|
|
|
|
};
|
|
|
|
|
2016-07-26 23:32:10 -04:00
|
|
|
// Safari doesn't support `execCommand`, so instead we inform the user to
|
|
|
|
// copy manually.
|
|
|
|
//
|
|
|
|
// See http://clipboardjs.com/#browser-support
|
2016-07-24 16:45:11 -04:00
|
|
|
genericError = function(e) {
|
|
|
|
var key;
|
|
|
|
if (/Mac/i.test(navigator.userAgent)) {
|
2016-07-26 23:32:10 -04:00
|
|
|
key = '⌘'; // Command
|
2016-07-24 16:45:11 -04:00
|
|
|
} else {
|
|
|
|
key = 'Ctrl';
|
|
|
|
}
|
|
|
|
return showTooltip(e.trigger, "Press " + key + "-C to copy");
|
|
|
|
};
|
|
|
|
|
|
|
|
showTooltip = function(target, title) {
|
2016-09-10 15:14:24 -04:00
|
|
|
var $target = $(target);
|
|
|
|
var originalTitle = $target.data('original-title');
|
|
|
|
|
|
|
|
$target
|
2016-12-09 16:48:23 -05:00
|
|
|
.attr('title', 'Copied')
|
2016-09-10 15:14:24 -04:00
|
|
|
.tooltip('fixTitle')
|
|
|
|
.tooltip('show')
|
|
|
|
.attr('title', originalTitle)
|
|
|
|
.tooltip('fixTitle');
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
var clipboard;
|
2016-08-02 04:58:09 -04:00
|
|
|
|
2016-08-10 09:35:14 -04:00
|
|
|
clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
|
|
|
|
clipboard.on('success', genericSuccess);
|
|
|
|
return clipboard.on('error', genericError);
|
2016-07-24 16:45:11 -04:00
|
|
|
});
|
2017-02-10 01:50:50 -05:00
|
|
|
}).call(window);
|