aboutsummaryrefslogtreecommitdiffstats
path: root/lib/clipboard.coffee
blob: b37caf72753f2b21074d6f30762de48af8f337d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Clipboard =
  _createTextArea: ->
    textArea = document.createElement "textarea"
    textArea.style.position = "absolute"
    textArea.style.left = "-100%"
    textArea.contentEditable = "true"
    textArea

  # http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55
  copy: ({data}) ->
    textArea = @_createTextArea()
    textArea.value = data

    document.body.appendChild(textArea)
    textArea.select()
    document.execCommand("Copy")
    document.body.removeChild(textArea)

  paste: ->
    textArea = @_createTextArea()
    document.body.appendChild(textArea)
    textArea.focus()
    document.execCommand("Paste")
    value = textArea.value
    document.body.removeChild(textArea)
    value


root = exports ? (window.root ?= {})
root.Clipboard = Clipboard
extend window, root unless exports?