-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implements #8263, Adds a re-usable Copy to Clipboard service. #13976
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,13 @@ | |
> | ||
View single document | ||
</a> | ||
<a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This link isn't keyboard accessible, since it doesn't have an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
class="kuiButton kuiButton--small kuiButton--secondary" | ||
data-test-subj="docTableRowAction" | ||
ng-click="copyToClipboard(uriescape)" | ||
> | ||
Copy Link | ||
</a> | ||
</div> | ||
<doc-viewer | ||
columns="columns" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
import './directives/share'; | ||
import './services/copyToClipboard'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Notifier } from 'ui/notify/notifier'; | ||
import { uiModules } from 'ui/modules'; | ||
|
||
const app = uiModules.get('kibana'); | ||
|
||
app.factory('copyToClipboardService', () => { | ||
const notify = new Notifier({ | ||
location: `Copy To Clipboard`, | ||
}); | ||
return { | ||
copyText: text => { | ||
const temp = document.createElement('textarea'); | ||
temp.value = text; | ||
temp.cols = 1; | ||
temp.rows = 1; | ||
temp.style.color = 'transparent'; | ||
temp.style.border = 'none'; | ||
document.body.appendChild(temp); | ||
temp.select(); | ||
let isCopied = false; | ||
try { | ||
isCopied = document.execCommand('copy'); | ||
if (isCopied) { | ||
notify.info('URL copied to clipboard.'); | ||
} else { | ||
notify.error('Failed to Copy to Clipboard.'); | ||
} | ||
} catch (err) { | ||
notify.error('Failed to Copy to Clipboard.'); | ||
} | ||
document.body.removeChild(temp); | ||
} | ||
}; | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please use template strings instead of concatenation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.