r83587 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83586‎ | r83587 | r83588 >
Date:14:27, 9 March 2011
Author:catrope
Status:ok
Tags:
Comment:
Fix r83586 (drag and drop support for placeholder plugin) to work in IE, whose drag&drop API is surprisingly similar to Firefox's but with slight differences
Modified paths:
  • /trunk/phase3/resources/jquery/jquery.placeholder.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.placeholder.js
@@ -41,9 +41,26 @@
4242 // already focused when the events were bound
4343 .bind( 'focus drop keydown paste', function( e ) {
4444 if ( $input.hasClass( 'placeholder' ) ) {
45 - // Support for drag&drop in Firefox
4645 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();
4865 } else {
4966 this.value = '';
5067 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r844201.17wmf1: MFT r76372, r76377, r83586, r83587, r83817, r83876, r83979, r84118,...catrope21:04, 20 March 2011
r85354MFT r82518, r82530, r82538, r82547, r82550, r82565, r82572, r82608, r82696, r...demon18:25, 4 April 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83586(bug 27944) Search placeholder was inserted even when the search box was alre...catrope13:54, 9 March 2011

Status & tagging log