summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/copy_to_clipboard.js.coffee
diff options
context:
space:
mode:
authorJacob Vosmaer <contact@jacobvosmaer.nl>2015-12-08 12:35:54 +0100
committerJacob Vosmaer <contact@jacobvosmaer.nl>2015-12-08 12:35:54 +0100
commit6d2be0212c444c6a3d25ae6a3c75822fa1c8614f (patch)
tree66c12a4f7863ded395300a56de689b5cb669e84b /app/assets/javascripts/copy_to_clipboard.js.coffee
parentad37f58ebd97fee3c06a531e4067c8adb4c9ecc7 (diff)
parentf5430e48b42227f1c1874ca27c6907f0f704be28 (diff)
downloadgitlab-ce-6d2be0212c444c6a3d25ae6a3c75822fa1c8614f.tar.gz
Merge branch 'master' into sync-all-repos
Diffstat (limited to 'app/assets/javascripts/copy_to_clipboard.js.coffee')
-rw-r--r--app/assets/javascripts/copy_to_clipboard.js.coffee37
1 files changed, 37 insertions, 0 deletions
diff --git a/app/assets/javascripts/copy_to_clipboard.js.coffee b/app/assets/javascripts/copy_to_clipboard.js.coffee
new file mode 100644
index 00000000000..24301e01b10
--- /dev/null
+++ b/app/assets/javascripts/copy_to_clipboard.js.coffee
@@ -0,0 +1,37 @@
+#= require clipboard
+
+genericSuccess = (e) ->
+ showTooltip(e.trigger, 'Copied!')
+
+ # Clear the selection and blur the trigger so it loses its border
+ e.clearSelection()
+ $(e.trigger).blur()
+
+# Safari doesn't support `execCommand`, so instead we inform the user to
+# copy manually.
+#
+# See http://clipboardjs.com/#browser-support
+genericError = (e) ->
+ if /Mac/i.test(navigator.userAgent)
+ key = '&#8984;' # Command
+ else
+ key = 'Ctrl'
+
+ showTooltip(e.trigger, "Press #{key}-C to copy")
+
+showTooltip = (target, title) ->
+ $(target).
+ tooltip(
+ container: 'body'
+ html: 'true'
+ placement: 'auto bottom'
+ title: title
+ trigger: 'manual'
+ ).
+ tooltip('show').
+ one('mouseleave', -> $(this).tooltip('hide'))
+
+$ ->
+ clipboard = new Clipboard '[data-clipboard-target], [data-clipboard-text]'
+ clipboard.on 'success', genericSuccess
+ clipboard.on 'error', genericError