aboutsummaryrefslogtreecommitdiffstats
path: root/lib/clipboard.coffee
blob: 26cd2fad16951dfc06426dceaa6b4d72228e1ef7 (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
Clipboard =
  _createTextArea: ->
    textArea = DomUtils.createElement("textarea")
    textArea.style.position = "absolute"
    textArea.style.left = "-100%"
    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.Clipboard = Clipboard