Created
January 18, 2012 04:17
-
-
Save endtwist/1630921 to your computer and use it in GitHub Desktop.
Paste event in Safari
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
// Safe to say...textarea is a good idea: <textarea id="pasteField"></textarea> | |
$( '#pasteField' ).on( 'paste', function( evt ) { | |
// Safari has a weird "types" list that we need to loop through and no "items" array. | |
var i = 0, items = [], item, key = 'text/plain', kind = 'string'; | |
while (i < evt.originalEvent.clipboardData.types.length) { | |
var key = evt.originalEvent.clipboardData.types[i]; | |
if( !key.match( /(text\/)|(plain-text)/i ) ) { | |
kind = 'file'; | |
} | |
items.push( { kind: kind, type: key } ); | |
i++; | |
} | |
// Let's just get content of the first item. | |
item = items[0]; | |
console.log( evt.originalEvent.clipboardData.getData( item.type ) ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment