From e8468e12f867cb71eb0d2b50c4904a1236b50e47 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sun, 10 Jun 2012 23:38:35 -0700 Subject: port clipboard.js to coffeescript --- lib/clipboard.coffee | 29 +++++++++++++++++++++++++++++ lib/clipboard.js | 29 ----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) create mode 100644 lib/clipboard.coffee delete mode 100644 lib/clipboard.js (limited to 'lib') diff --git a/lib/clipboard.coffee b/lib/clipboard.coffee new file mode 100644 index 00000000..2b28df70 --- /dev/null +++ b/lib/clipboard.coffee @@ -0,0 +1,29 @@ +Clipboard = + _createTextArea: -> + textArea = document.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 diff --git a/lib/clipboard.js b/lib/clipboard.js deleted file mode 100644 index b6d3940e..00000000 --- a/lib/clipboard.js +++ /dev/null @@ -1,29 +0,0 @@ -var Clipboard = { - _createTextArea: function() { - var textArea = document.createElement("textarea"); - textArea.style.position = "absolute"; - textArea.style.left = "-100%"; - return textArea; - }, - - // http://groups.google.com/group/chromium-extensions/browse_thread/thread/49027e7f3b04f68/f6ab2457dee5bf55 - copy: function(data) { - var textArea = this._createTextArea(); - textArea.value = data; - - document.body.appendChild(textArea); - textArea.select(); - document.execCommand("Copy"); - document.body.removeChild(textArea); - }, - - paste: function() { - var textArea = this._createTextArea(); - document.body.appendChild(textArea); - textArea.focus(); - document.execCommand("Paste"); - var rv = textArea.value; - document.body.removeChild(textArea); - return rv; - } -}; -- cgit v1.2.3