From: Roan Kattouw Date: Wed, 9 Mar 2011 13:54:02 +0000 (+0000) Subject: (bug 27944) Search placeholder was inserted even when the search box was already... X-Git-Tag: 1.31.0-rc.0~31544 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=324b9997f34962a2f43b6bbbffe5024fcca1ae0c;p=lhc%2Fweb%2Fwiklou.git (bug 27944) Search placeholder was inserted even when the search box was already focused, leading to the placeholder being added to the search string. This revision doesn't fix the initial insertion of the placeholder if the search box is focused but empty, but it does remove it upon keydown (and paste), which fixes the search string munging. (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. --- diff --git a/resources/jquery/jquery.placeholder.js b/resources/jquery/jquery.placeholder.js index 1445738c92..16c715a04e 100644 --- a/resources/jquery/jquery.placeholder.js +++ b/resources/jquery/jquery.placeholder.js @@ -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' ); } } );