diff options
author | Robert Speicher <robert@gitlab.com> | 2015-11-20 02:23:31 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2015-11-20 02:23:31 +0300 |
commit | b3cd7243e9668fc0e823b6f6cf9868171f3af456 (patch) | |
tree | b2d3ff16b37ceee32db5b8529d59c7171917ab3c | |
parent | 0383f84d88d95183638d0e227f3446974eb4e387 (diff) | |
parent | 2a3680219bb5a4d35aa9b98ba2a2c43855aea27a (diff) |
Merge branch 'rs-safari-clipboard-fallback' into 'master'
Add a fallback for Safari copy-to-clipboard
Also, hide the tooltip in a less stupid way.
Closes #3547
See merge request !1844
-rw-r--r-- | app/assets/javascripts/copy_to_clipboard.js.coffee | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/app/assets/javascripts/copy_to_clipboard.js.coffee b/app/assets/javascripts/copy_to_clipboard.js.coffee index ec4b80cca6f..9c68c5cc1bc 100644 --- a/app/assets/javascripts/copy_to_clipboard.js.coffee +++ b/app/assets/javascripts/copy_to_clipboard.js.coffee @@ -9,13 +9,24 @@ $ -> clipboard.on 'success', (e) -> $(e.trigger). tooltip(trigger: 'manual', placement: 'auto bottom', title: 'Copied!'). - tooltip('show') + tooltip('show'). + one('mouseleave', -> $(this).tooltip('hide')) # Clear the selection and blur the trigger so it loses its border e.clearSelection() $(e.trigger).blur() - # Manually hide the tooltip after 1 second - setTimeout(-> - $(e.trigger).tooltip('hide') - , 1000) + # Safari doesn't support `execCommand`, so instead we inform the user to + # copy manually. + # + # See http://clipboardjs.com/#browser-support + clipboard.on 'error', (e) -> + if /Mac/i.test(navigator.userAgent) + title = "Press ⌘-C to copy" + else + title = "Press Ctrl-C to copy" + + $(e.trigger). + tooltip(trigger: 'manual', placement: 'auto bottom', html: true, title: title). + tooltip('show'). + one('mouseleave', -> $(this).tooltip('hide')) |