From 3ff0518014a51f237d1d98ebc15c0ce4be24c2b5 Mon Sep 17 00:00:00 2001 From: Jez Ng Date: Sun, 15 Jan 2012 15:40:49 +0800 Subject: Add URL pasting functions. Closes #353. --- lib/clipboard.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'lib') 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; + } }; -- cgit v1.2.3