-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.rb
32 lines (31 loc) · 1.1 KB
/
init.rb
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
Redmine::Plugin.register :redmine_copy_macro do
name 'Redmine Copy Macro plugin'
author 'Frank Schwarz'
description 'Macro for copy-to-clipboard button'
version '0.0.1.dev'
url 'https://github.com/buschmais/redmine_copy_macro'
author_url 'https://www.buschmais.de/author/frank/'
Redmine::WikiFormatting::Macros.register do
desc "Add copy macro: {{copy(some text)}}"
macro :copy do |obj, args, text|
html_id = "copy-#{Redmine::Utils.random_hex(4)}"
js = "navigator.clipboard.writeText($('##{html_id}').text())"
value = args.length > 0 ? args[0] : text
out = ''.html_safe
out << content_tag(
'span',
value,
:id => "#{html_id}",
:class => 'copy-text',
:style => 'display: inline-block; padding: 1px; border: 1px solid darkgrey; background-color: #eee; border-radius: 2px;'
)
out << link_to_function(
'📋',
js,
:title => 'Copy',
:class => 'copy-text-button',
:style => 'padding-left: 5px; text-decoration: none;')
out
end
end
end