Index: trunk/phase3/resources/jquery/jquery.placeholder.js |
— | — | @@ -41,9 +41,26 @@ |
42 | 42 | // already focused when the events were bound |
43 | 43 | .bind( 'focus drop keydown paste', function( e ) { |
44 | 44 | if ( $input.hasClass( 'placeholder' ) ) { |
45 | | - // Support for drag&drop in Firefox |
46 | 45 | if ( e.type == 'drop' && e.originalEvent.dataTransfer ) { |
47 | | - this.value = e.originalEvent.dataTransfer.getData( 'text/plain' ); |
| 46 | + // Support for drag&drop. Instead of inserting the dropped |
| 47 | + // text somewhere in the middle of the placeholder string, |
| 48 | + // we want to set the contents of the search box to the |
| 49 | + // dropped text. |
| 50 | + |
| 51 | + // IE wants getData( 'text' ) but Firefox wants getData( 'text/plain' ) |
| 52 | + // Firefox fails gracefully with an empty string, IE barfs with an error |
| 53 | + try { |
| 54 | + // Try the Firefox way |
| 55 | + this.value = e.originalEvent.dataTransfer.getData( 'text/plain' ); |
| 56 | + } catch ( exception ) { |
| 57 | + // Got an exception, so use the IE way |
| 58 | + this.value = e.originalEvent.dataTransfer.getData( 'text' ); |
| 59 | + } |
| 60 | + |
| 61 | + // On Firefox, drop fires after the dropped text has been inserted, |
| 62 | + // but on IE it fires before. If we don't prevent the default action, |
| 63 | + // IE will insert the dropped text twice. |
| 64 | + e.preventDefault(); |
48 | 65 | } else { |
49 | 66 | this.value = ''; |
50 | 67 | } |