BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7b893d1b
Unverified
Commit
7b893d1b
authored
Nov 28, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix eslint errors
parent
5d523fdd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
33 deletions
+32
-33
copy_to_clipboard.js
app/assets/javascripts/copy_to_clipboard.js
+32
-33
No files found.
app/assets/javascripts/copy_to_clipboard.js
View file @
7b893d1b
/* eslint-disable func-names, space-before-function-paren, one-var, no-var, one-var-declaration-per-line, prefer-template, quotes, no-unused-vars, prefer-arrow-callback, max-len */
import
Clipboard
from
'clipboard'
;
var
genericError
,
genericSuccess
,
showTooltip
;
function
showTooltip
(
target
,
title
)
{
const
$target
=
$
(
target
);
const
originalTitle
=
$target
.
data
(
'original-title'
);
if
(
!
$target
.
data
(
'hideTooltip'
))
{
$target
.
attr
(
'title'
,
title
)
.
tooltip
(
'fixTitle'
)
.
tooltip
(
'show'
)
.
attr
(
'title'
,
originalTitle
)
.
tooltip
(
'fixTitle'
);
}
}
genericSuccess
=
function
(
e
)
{
function
genericSuccess
(
e
)
{
showTooltip
(
e
.
trigger
,
'Copied'
);
// Clear the selection and blur the trigger so it loses its border
e
.
clearSelection
();
return
$
(
e
.
trigger
).
blur
();
}
;
$
(
e
.
trigger
).
blur
();
}
// Safari doesn't support `execCommand`, so instead we inform the user to
// copy manually.
//
// See http://clipboardjs.com/#browser-support
genericError
=
function
(
e
)
{
var
key
;
function
genericError
(
e
)
{
let
key
;
if
(
/Mac/i
.
test
(
navigator
.
userAgent
))
{
key
=
'⌘'
;
// Command
}
else
{
key
=
'Ctrl'
;
}
return
showTooltip
(
e
.
trigger
,
"Press "
+
key
+
"-C to copy"
);
};
showTooltip
=
function
(
target
,
title
)
{
var
$target
=
$
(
target
);
var
originalTitle
=
$target
.
data
(
'original-title'
);
if
(
!
$target
.
data
(
'hideTooltip'
))
{
$target
.
attr
(
'title'
,
'Copied'
)
.
tooltip
(
'fixTitle'
)
.
tooltip
(
'show'
)
.
attr
(
'title'
,
originalTitle
)
.
tooltip
(
'fixTitle'
);
}
};
showTooltip
(
e
.
trigger
,
`Press
${
key
}
-C to copy`
);
}
$
(
function
()
{
$
(
()
=>
{
const
clipboard
=
new
Clipboard
(
'[data-clipboard-target], [data-clipboard-text]'
);
clipboard
.
on
(
'success'
,
genericSuccess
);
clipboard
.
on
(
'error'
,
genericError
);
// This a workaround around ClipboardJS limitations to allow the context-specific copy/pasting of plain text or GFM.
// The Ruby `clipboard_button` helper sneaks a JSON hash with `text` and `gfm` keys into the `data-clipboard-text`
// attribute that ClipboardJS reads from.
// When ClipboardJS creates a new `textarea` (directly inside `body`, with a `readonly` attribute`), sets its value
// to the value of this data attribute, focusses on it, and finally programmatically issues the 'Copy' command,
// this code intercepts the copy command/event at the last minute to deconstruct this JSON hash and set the
// `text/plain` and `text/x-gfm` copy data types to the intended values.
$
(
document
).
on
(
'copy'
,
'body > textarea[readonly]'
,
function
(
e
)
{
/**
* This a workaround around ClipboardJS limitations to allow the context-specific copy/pasting
* of plain text or GFM. The Ruby `clipboard_button` helper sneaks a JSON hash with `text` and
* `gfm` keys into the `data-clipboard-text` attribute that ClipboardJS reads from.
* When ClipboardJS creates a new `textarea` (directly inside `body`, with a `readonly`
* attribute`), sets its value to the value of this data attribute, focusses on it, and finally
* programmatically issues the 'Copy' command, this code intercepts the copy command/event at
* the last minute to deconstruct this JSON hash and set the `text/plain` and `text/x-gfm` copy
* data types to the intended values.
*/
$
(
document
).
on
(
'copy'
,
'body > textarea[readonly]'
,
(
e
)
=>
{
const
clipboardData
=
e
.
originalEvent
.
clipboardData
;
if
(
!
clipboardData
)
return
;
...
...
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