gitlab-org--gitlab-foss/app/assets/javascripts/copy_to_clipboard.js
Mike Greiling 69e4072f89 Merge branch 'master' into go-go-gadget-webpack
* master: (389 commits)
  Document "No gems fetched from git repositories" policy [ci skip]
  Typos
  Small gramatical tweaks
  Typos
  Added PHP & NPM doc
  Use `:empty_project` where possible in request specs
  Add caching of droplab ajax requests
  Use `:empty_project` where possible in model specs
  Revert 3f17f29a
  Remove unused js response from refs controller
  Add MR id to changelog entry
  fixed small mini pipeline graph line glitch
  Prevent form to be submitted twice
  Fix Error 500 when repositories contain annotated tags pointing to blobs
  Fix /explore sorting (trending)
  Simplify wording in "adding an image" docs
  Remove "official merge window" from CONTRIBUTING.md [ci skip]
  Update repository check documentation
  Fixed flexbox and wrap issues
  Update two_factor_authentication.md
  ...
2017-01-27 19:33:58 -06:00

49 lines
1.4 KiB
JavaScript

/* 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 */
/* global Clipboard */
window.Clipboard = require('vendor/clipboard');
(function() {
var genericError, genericSuccess, showTooltip;
genericSuccess = function(e) {
showTooltip(e.trigger, 'Copied');
// Clear the selection and blur the trigger so it loses its border
e.clearSelection();
return $(e.trigger).blur();
};
// Safari doesn't support `execCommand`, so instead we inform the user to
// copy manually.
//
// See http://clipboardjs.com/#browser-support
genericError = function(e) {
var key;
if (/Mac/i.test(navigator.userAgent)) {
key = '⌘'; // Command
} else {
key = 'Ctrl';
}
return showTooltip(e.trigger, "Press " + key + "-C to copy");
};
showTooltip = function(target, title) {
var $target = $(target);
var originalTitle = $target.data('original-title');
$target
.attr('title', 'Copied')
.tooltip('fixTitle')
.tooltip('show')
.attr('title', originalTitle)
.tooltip('fixTitle');
};
$(function() {
var clipboard;
clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
clipboard.on('success', genericSuccess);
return clipboard.on('error', genericError);
});
}).call(this);