aboutsummaryrefslogtreecommitdiffstats
path: root/lib/clipboard.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/clipboard.js')
-rw-r--r--lib/clipboard.js33
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/clipboard.js b/lib/clipboard.js
index 1d414892..b6d3940e 100644
--- a/lib/clipboard.js
+++ b/lib/clipboard.js
@@ -1,14 +1,29 @@
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 = document.createElement("textarea");
- textArea.style.position = "absolute";
- textArea.style.left = "-100%";
- textArea.value = data;
+ var textArea = this._createTextArea();
+ textArea.value = data;
+
+ document.body.appendChild(textArea);
+ textArea.select();
+ document.execCommand("Copy");
+ document.body.removeChild(textArea);
+ },
- 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;
+ }
};