Drag/drop on the editor to upload: don't trigger the uploader when selected text is being dragged from one window to another.

Merges [28189] to the 3.9 branch.

props azaozz.
fixes #27880.

Built from https://develop.svn.wordpress.org/branches/3.9@28262


git-svn-id: http://core.svn.wordpress.org/branches/3.9@28090 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-05-06 03:28:15 +00:00
parent f2512c50eb
commit c85dc97274
5 changed files with 28 additions and 8 deletions

View File

@ -3270,6 +3270,7 @@
localDrag: false, localDrag: false,
overContainer: false, overContainer: false,
overDropzone: false, overDropzone: false,
draggingFile: null,
initialize: function() { initialize: function() {
var self = this; var self = this;
@ -3309,6 +3310,21 @@
return supports; return supports;
}, },
isDraggingFile: function( event ) {
if ( this.draggingFile !== null ) {
return this.draggingFile;
}
if ( _.isUndefined( event.originalEvent ) || _.isUndefined( event.originalEvent.dataTransfer ) ) {
return false;
}
this.draggingFile = _.indexOf( event.originalEvent.dataTransfer.types, 'Files' ) > -1 &&
_.indexOf( event.originalEvent.dataTransfer.types, 'text/plain' ) === -1;
return this.draggingFile;
},
refresh: function( e ) { refresh: function( e ) {
var dropzone_id; var dropzone_id;
for ( dropzone_id in this.dropzones ) { for ( dropzone_id in this.dropzones ) {
@ -3320,6 +3336,10 @@
$( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone ); $( e.target ).closest( '.uploader-editor' ).toggleClass( 'droppable', this.overDropzone );
} }
if ( ! this.overContainer && ! this.overDropzone ) {
this.draggingFile = null;
}
return this; return this;
}, },
@ -3383,8 +3403,8 @@
return this; return this;
}, },
containerDragover: function() { containerDragover: function( event ) {
if ( this.localDrag ) { if ( this.localDrag || ! this.isDraggingFile( event ) ) {
return; return;
} }
@ -3399,13 +3419,13 @@
_.delay( _.bind( this.refresh, this ), 50 ); _.delay( _.bind( this.refresh, this ), 50 );
}, },
dropzoneDragover: function( e ) { dropzoneDragover: function( event ) {
if ( this.localDrag ) { if ( this.localDrag || ! this.isDraggingFile( event ) ) {
return; return;
} }
this.overDropzone = true; this.overDropzone = true;
this.refresh( e ); this.refresh( event );
return false; return false;
}, },

File diff suppressed because one or more lines are too long

View File

@ -317,7 +317,7 @@ tinymce.PluginManager.add( 'wordpress', function( editor ) {
dom.bind( doc, 'dragstart dragend dragover drop', function( event ) { dom.bind( doc, 'dragstart dragend dragover drop', function( event ) {
if ( typeof window.jQuery !== 'undefined' ) { if ( typeof window.jQuery !== 'undefined' ) {
// Trigger the jQuery handlers. // Trigger the jQuery handlers.
window.jQuery( document ).triggerHandler( event.type ); window.jQuery( document ).trigger( new window.jQuery.Event( event ) );
} }
}); });
} }

File diff suppressed because one or more lines are too long