Created
January 18, 2012 04:04
-
-
Save endtwist/1630862 to your computer and use it in GitHub Desktop.
Paste event in Firefox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textarea id="pasteField"></textarea> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var $pasteField = $( '#pasteField' ); | |
function onPaste( evt, retries ) { | |
// No clipboardData object, so we fake it and just return the field's content, when we receive it. | |
var text = $pasteField.val(); | |
$pasteField.val( '' ); // reset the field | |
clipboardObj = { getData: function() { return text; } }; | |
items = [ { kind: 'string', type: 'text' } ]; | |
// If we didn't find any content on this attempt, and we haven't tried > 3 times, | |
// try again in 100 ms to find content in the textarea. | |
if( !text.length && ( retries < 3 || typeof retries === 'undefined' ) ) { | |
if( typeof retries === 'undefined' ) | |
retries = 0; | |
setTimeout( function() { | |
onPaste( evt, ++retries ); | |
}, 100 ); | |
return true; | |
} | |
// Now you finally have the item's content, with an API similar to that of Chrome -- at least, for plain text. | |
} | |
$pasteField.bind( 'paste', onPaste ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment