(bug 27944) Search placeholder was inserted even when the search box was already...
authorRoan Kattouw <catrope@users.mediawiki.org>
Wed, 9 Mar 2011 13:54:02 +0000 (13:54 +0000)
committerRoan Kattouw <catrope@users.mediawiki.org>
Wed, 9 Mar 2011 13:54:02 +0000 (13:54 +0000)
(bug 26135) Support drag and drop in the search box in Firefox. Done by adding 'drop' to the list of events to update search suggestions for and to remove the placeholder for. Removing the placeholder is trickier in this case because 'drop' fires after the text has already been inserted, and because it could have been inserted at any offset in the placeholder string. Used dataTransfer magic to obtain the text being dropped and just overwrote the search box text with that.

resources/jquery/jquery.placeholder.js

index 1445738..16c715a 100644 (file)
@@ -37,9 +37,16 @@ $.fn.placeholder = function() {
                        } )
 
                        // Hide on focus
-                       .focus( function() {
+                       // Also listen for other events in case $input was
+                       // already focused when the events were bound
+                       .bind( 'focus drop keydown paste', function( e ) {
                                if ( $input.hasClass( 'placeholder' ) ) {
-                                       this.value = '';
+                                       // Support for drag&drop in Firefox
+                                       if ( e.type == 'drop' && e.originalEvent.dataTransfer ) {
+                                               this.value = e.originalEvent.dataTransfer.getData( 'text/plain' );
+                                       } else {
+                                               this.value = '';
+                                       }
                                        $input.removeClass( 'placeholder' );
                                }
                        } );