BigW Consortium Gitlab

copy_to_clipboard.js 980 Bytes
Newer Older
Fatih Acet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

/*= require clipboard */

(function() {
  var genericError, genericSuccess, showTooltip;

  genericSuccess = function(e) {
    showTooltip(e.trigger, 'Copied!');
    e.clearSelection();
    return $(e.trigger).blur();
  };

  genericError = function(e) {
    var key;
    if (/Mac/i.test(navigator.userAgent)) {
      key = '⌘';
    } 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;
Phil Hughes committed
37

38 39 40
    clipboard = new Clipboard('[data-clipboard-target], [data-clipboard-text]');
    clipboard.on('success', genericSuccess);
    return clipboard.on('error', genericError);
Fatih Acet committed
41 42 43
  });

}).call(this);