Comparing version 3.1.0 to 3.1.1
30
index.js
@@ -11,3 +11,15 @@ export async function clippie(content, {reject = false} = {}) { | ||
} catch { | ||
return fallback(c); | ||
if (!document.execCommand) return false; | ||
const el = document.createElement("textarea"); | ||
el.value = c; | ||
el.style.top = 0; | ||
el.style.left = 0; | ||
el.style.position = "fixed"; | ||
el.style.clip = "rect(0, 0, 0, 0)"; | ||
el.ariaHidden = "true"; | ||
document.body.appendChild(el); | ||
el.select(); | ||
const success = document.execCommand("copy"); | ||
document.body.removeChild(el); | ||
return success; | ||
} | ||
@@ -22,17 +34,1 @@ } | ||
} | ||
function fallback(text) { | ||
if (!document.execCommand) return false; | ||
const el = document.createElement("textarea"); | ||
el.value = text; | ||
el.style.top = 0; | ||
el.style.left = 0; | ||
el.style.position = "fixed"; | ||
el.style.clip = "rect(0, 0, 0, 0)"; | ||
el.ariaHidden = "true"; | ||
document.body.appendChild(el); | ||
el.select(); | ||
const success = document.execCommand("copy"); | ||
document.body.removeChild(el); | ||
return success; | ||
} |
{ | ||
"name": "clippie", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Teeny-tiny browser clipboard copy", | ||
@@ -5,0 +5,0 @@ "author": "silverwind", |
@@ -21,12 +21,12 @@ # clippie | ||
- `content` *String*, *Blob*, *Array*: Content to copy. If an Array is passed, will copy all items in sequence. | ||
- `content` *String*, *Blob*, *Array[String,Blob]*: Content to copy. If an Array is passed, will copy all items in sequence. | ||
- `options` *Object* | ||
- `reject`: *Boolean*: Whether to reject on unexpected errors. Default: `false`. | ||
Returns `true` when successful and `false` when not. Will never throw. | ||
Returns `true` when successful and `false` when not. Will never throw unless `reject` is `true`. | ||
## Notes | ||
To enable image copy in Firefox, enable `dom.events.asyncClipboard.clipboardItem` in `about:config`. Track [Bug 1619947](https://bugzilla.mozilla.org/show_bug.cgi?id=1619947) for updates. | ||
Firefox needs `dom.events.asyncClipboard.clipboardItem` in `about:config` to enable image copying. Track [Bug 1619947](https://bugzilla.mozilla.org/show_bug.cgi?id=1619947) for updates. | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2779
32