Skip to content
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

Module Inclusion #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
12 changes: 5 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* global DOMException */

module.exports = clipboardCopy

function clipboardCopy (text) {
export default function clipboardCopy (text) {
// Use the Async Clipboard API when available. Requires a secure browsing
// context (i.e. HTTPS)
if (navigator.clipboard) {
Expand All @@ -14,7 +12,7 @@ function clipboardCopy (text) {
// ...Otherwise, use document.execCommand() fallback

// Put the text to copy into a <span>
var span = document.createElement('span')
const span = document.createElement('span')
span.textContent = text

// Preserve consecutive spaces and newlines
Expand All @@ -24,14 +22,14 @@ function clipboardCopy (text) {
document.body.appendChild(span)

// Make a selection object representing the range of text selected by the user
var selection = window.getSelection()
var range = window.document.createRange()
const selection = window.getSelection()
const range = window.document.createRange()
selection.removeAllRanges()
range.selectNode(span)
selection.addRange(range)

// Copy text to the clipboard
var success = false
let success = false
try {
success = window.document.execCommand('copy')
} catch (err) {
Expand Down