http://www.mediawiki.org/wiki/Special:Code/MediaWiki/83586

Revision: 83586
Author:   catrope
Date:     2011-03-09 13:54:02 +0000 (Wed, 09 Mar 2011)
Log Message:
-----------
(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.

Modified Paths:
--------------
    trunk/extensions/Vector/modules/ext.vector.simpleSearch.js
    trunk/phase3/resources/jquery/jquery.placeholder.js

Modified: trunk/extensions/Vector/modules/ext.vector.simpleSearch.js
===================================================================
--- trunk/extensions/Vector/modules/ext.vector.simpleSearch.js  2011-03-09 
12:55:51 UTC (rev 83585)
+++ trunk/extensions/Vector/modules/ext.vector.simpleSearch.js  2011-03-09 
13:54:02 UTC (rev 83586)
@@ -78,8 +78,9 @@
                        positionFromLeft: $( 'body' ).is( '.rtl' ),
                        highlightInput: true
                } )
-               .bind( 'paste cut', function( e ) {
-                       // make sure paste and cut events from the mouse 
trigger the keypress handler and cause the suggestions to update
+               .bind( 'paste cut drop', function( e ) {
+                       // make sure paste and cut events from the mouse and 
drag&drop events
+                       // trigger the keypress handler and cause the 
suggestions to update
                        $( this ).trigger( 'keypress' );
                } );
        // Special suggestions functionality for skin-provided search box

Modified: trunk/phase3/resources/jquery/jquery.placeholder.js
===================================================================
--- trunk/phase3/resources/jquery/jquery.placeholder.js 2011-03-09 12:55:51 UTC 
(rev 83585)
+++ trunk/phase3/resources/jquery/jquery.placeholder.js 2011-03-09 13:54:02 UTC 
(rev 83586)
@@ -37,9 +37,16 @@
                        } )
 
                        // 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' );
                                }
                        } );


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to