Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
7dab8ed7
Commit
7dab8ed7
authored
Nov 24, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rework the copy_to_clipboard logic
It needed to be more flexible in how we set the target text or element.
parent
acc0f162
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
34 deletions
+55
-34
app/assets/javascripts/copy_to_clipboard.js.coffee
app/assets/javascripts/copy_to_clipboard.js.coffee
+31
-26
app/helpers/button_helper.rb
app/helpers/button_helper.rb
+18
-2
app/views/projects/commits/_commit.html.haml
app/views/projects/commits/_commit.html.haml
+2
-2
app/views/projects/issues/_discussion.html.haml
app/views/projects/issues/_discussion.html.haml
+2
-2
app/views/projects/merge_requests/_discussion.html.haml
app/views/projects/merge_requests/_discussion.html.haml
+2
-2
No files found.
app/assets/javascripts/copy_to_clipboard.js.coffee
View file @
7dab8ed7
#= require clipboard
#= require clipboard
$
->
genericSuccess
=
(
e
)
->
clipboard
=
new
Clipboard
'.js-clipboard-trigger'
,
showTooltip
(
e
.
trigger
,
'Copied!'
)
text
:
(
trigger
)
->
$target
=
$
(
trigger
.
nextElementSibling
||
trigger
.
previousElementSibling
)
# Clear the selection and blur the trigger so it loses its border
$target
.
data
(
'clipboard-text'
)
||
$target
.
text
().
trim
()
e
.
clearSelection
()
$
(
e
.
trigger
).
blur
()
clipboard
.
on
'success'
,
(
e
)
->
# Safari doesn't support `execCommand`, so instead we inform the user to
$
(
e
.
trigger
).
# copy manually.
tooltip
(
trigger
:
'manual'
,
placement
:
'auto bottom'
,
title
:
'Copied!'
).
#
tooltip
(
'show'
).
# See http://clipboardjs.com/#browser-support
one
(
'mouseleave'
,
->
$
(
this
).
tooltip
(
'hide'
))
genericError
=
(
e
)
->
if
/Mac/i
.
test
(
navigator
.
userAgent
)
key
=
'⌘'
# Command
else
key
=
'Ctrl'
# Clear the selection and blur the trigger so it loses its border
showTooltip
(
e
.
trigger
,
"Press
#{
key
}
-C to copy"
)
e
.
clearSelection
()
$
(
e
.
trigger
).
blur
()
# Safari doesn't support `execCommand`, so instead we inform the user to
showTooltip
=
(
target
,
title
)
->
# copy manually.
$
(
target
).
#
tooltip
(
# See http://clipboardjs.com/#browser-support
container
:
'body'
clipboard
.
on
'error'
,
(
e
)
->
html
:
'true'
if
/Mac/i
.
test
(
navigator
.
userAgent
)
placement
:
'auto bottom'
title
=
"Press ⌘-C to copy"
title
:
title
else
trigger
:
'manual'
title
=
"Press Ctrl-C to copy"
).
tooltip
(
'show'
).
one
(
'mouseleave'
,
->
$
(
this
).
tooltip
(
'hide'
))
$
(
e
.
trigger
).
$
->
tooltip
(
trigger
:
'manual'
,
placement
:
'auto bottom'
,
html
:
true
,
title
:
title
).
clipboard
=
new
Clipboard
'[data-clipboard-target], [data-clipboard-text]'
tooltip
(
'show'
).
clipboard
.
on
'success'
,
genericSuccess
one
(
'mouseleave'
,
->
$
(
this
).
tooltip
(
'hide'
))
clipboard
.
on
'error'
,
genericError
app/helpers/button_helper.rb
View file @
7dab8ed7
module
ButtonHelper
module
ButtonHelper
def
clipboard_button
# Output a "Copy to Clipboard" button
#
# data - Data attributes passed to `content_tag`
#
# Examples:
#
# # Define the clipboard's text
# clipboard_button(clipboard_text: "Foo")
# # => "<button class='...' data-clipboard-text='Foo'>...</button>"
#
# # Define the target element
# clipboard_button(clipboard_target: "#foo")
# # => "<button class='...' data-clipboard-target='#foo'>...</button>"
#
# See http://clipboardjs.com/#usage
def
clipboard_button
(
data
=
{})
content_tag
:button
,
content_tag
:button
,
icon
(
'clipboard'
),
icon
(
'clipboard'
),
class:
'btn btn-xs btn-clipboard js-clipboard-trigger'
,
class:
'btn btn-xs btn-clipboard'
,
data:
data
,
type: :button
type: :button
end
end
...
...
app/views/projects/commits/_commit.html.haml
View file @
7dab8ed7
...
@@ -20,8 +20,8 @@
...
@@ -20,8 +20,8 @@
-
if
ci_commit
-
if
ci_commit
=
render_ci_status
(
ci_commit
)
=
render_ci_status
(
ci_commit
)
=
clipboard_button
=
clipboard_button
(
clipboard_text:
commit
.
id
)
=
link_to
commit
.
short_id
,
namespace_project_commit_path
(
project
.
namespace
,
project
,
commit
),
class:
"commit_short_id"
,
data:
{
clipboard_text:
commit
.
id
}
=
link_to
commit
.
short_id
,
namespace_project_commit_path
(
project
.
namespace
,
project
,
commit
),
class:
"commit_short_id"
.notes_count
.notes_count
-
if
note_count
>
0
-
if
note_count
>
0
...
...
app/views/projects/issues/_discussion.html.haml
View file @
7dab8ed7
...
@@ -18,9 +18,9 @@
...
@@ -18,9 +18,9 @@
=
link_to_member
(
@project
,
participant
,
name:
false
,
size:
24
)
=
link_to_member
(
@project
,
participant
,
name:
false
,
size:
24
)
.col-md-3
.col-md-3
.input-group.cross-project-reference
.input-group.cross-project-reference
%span
.slead.has_tooltip
{
title:
'Cross-project reference'
}
%span
#cross-project-reference
.slead.has_tooltip
{
title:
'Cross-project reference'
}
=
cross_project_reference
(
@project
,
@issue
)
=
cross_project_reference
(
@project
,
@issue
)
=
clipboard_button
=
clipboard_button
(
clipboard_target:
'#cross-project-reference'
)
.row
.row
%section
.col-md-9
%section
.col-md-9
...
...
app/views/projects/merge_requests/_discussion.html.haml
View file @
7dab8ed7
...
@@ -15,9 +15,9 @@
...
@@ -15,9 +15,9 @@
=
render
"projects/merge_requests/show/participants"
=
render
"projects/merge_requests/show/participants"
.col-md-3
.col-md-3
.input-group.cross-project-reference
.input-group.cross-project-reference
%span
.slead.has_tooltip
{
title:
'Cross-project reference'
}
%span
#cross-project-reference
.slead.has_tooltip
{
title:
'Cross-project reference'
}
=
cross_project_reference
(
@project
,
@merge_request
)
=
cross_project_reference
(
@project
,
@merge_request
)
=
clipboard_button
=
clipboard_button
(
clipboard_target:
'#cross-project-reference'
)
.row
.row
%section
.col-md-9
%section
.col-md-9
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment