2015-09-30 18:09:45 -04:00
|
|
|
#= require clipboard
|
|
|
|
|
2015-11-24 18:35:24 -05:00
|
|
|
genericSuccess = (e) ->
|
|
|
|
showTooltip(e.trigger, 'Copied!')
|
|
|
|
|
|
|
|
# Clear the selection and blur the trigger so it loses its border
|
|
|
|
e.clearSelection()
|
|
|
|
$(e.trigger).blur()
|
2015-09-30 18:09:45 -04:00
|
|
|
|
2015-11-24 18:35:24 -05:00
|
|
|
# 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 = '⌘' # Command
|
|
|
|
else
|
|
|
|
key = 'Ctrl'
|
2015-09-30 18:09:45 -04:00
|
|
|
|
2015-11-24 18:35:24 -05:00
|
|
|
showTooltip(e.trigger, "Press #{key}-C to copy")
|
2015-09-30 18:09:45 -04:00
|
|
|
|
2015-11-24 18:35:24 -05:00
|
|
|
showTooltip = (target, title) ->
|
|
|
|
$(target).
|
|
|
|
tooltip(
|
|
|
|
container: 'body'
|
|
|
|
html: 'true'
|
|
|
|
placement: 'auto bottom'
|
|
|
|
title: title
|
|
|
|
trigger: 'manual'
|
|
|
|
).
|
|
|
|
tooltip('show').
|
|
|
|
one('mouseleave', -> $(this).tooltip('hide'))
|
2015-11-19 15:46:05 -05:00
|
|
|
|
2015-11-24 18:35:24 -05:00
|
|
|
$ ->
|
|
|
|
clipboard = new Clipboard '[data-clipboard-target], [data-clipboard-text]'
|
|
|
|
clipboard.on 'success', genericSuccess
|
|
|
|
clipboard.on 'error', genericError
|