aboutsummaryrefslogtreecommitdiffstats
path: root/lib/clipboard.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'lib/clipboard.coffee')
-rw-r--r--lib/clipboard.coffee12
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/clipboard.coffee b/lib/clipboard.coffee
index d015cdad..11542b11 100644
--- a/lib/clipboard.coffee
+++ b/lib/clipboard.coffee
@@ -1,8 +1,9 @@
Clipboard =
- _createTextArea: ->
- textArea = document.createElement "textarea"
+ _createTextArea: (tagName = "textarea") ->
+ textArea = document.createElement tagName
textArea.style.position = "absolute"
textArea.style.left = "-100%"
+ textArea.contentEditable = "true"
textArea
# http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55
@@ -16,14 +17,15 @@ Clipboard =
document.body.removeChild(textArea)
paste: ->
- textArea = @_createTextArea()
+ textArea = @_createTextArea "div" # Use a <div> so Firefox pastes rich text.
document.body.appendChild(textArea)
textArea.focus()
document.execCommand("Paste")
- value = textArea.value
+ value = textArea.innerText
document.body.removeChild(textArea)
value.replace /\xa0/g, " "
-root = exports ? window
+root = exports ? (window.root ?= {})
root.Clipboard = Clipboard
+extend window, root unless exports?