diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-11-19 15:46:05 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-11-19 16:06:53 -0500 |
commit | 2a3680219bb5a4d35aa9b98ba2a2c43855aea27a (patch) | |
tree | f79d372f6bf882882bb368fb71f6b66ddd868176 | |
parent | e1780825eeae0b1b839502da06dfb0e843b1b292 (diff) | |
download | gitlab-ce-2a3680219bb5a4d35aa9b98ba2a2c43855aea27a.tar.gz |
Add a fallback for Safari copy-to-clipboardrs-safari-clipboard-fallback
Also, hide the tooltip in a less stupid way.
Closes #3547
-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')) |