Skip to content

Commit 87be663

Browse files
committed
Merge branch 't/12264' into major
2 parents 2ab5c72 + 11c6422 commit 87be663

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

plugins/clipboard/plugin.js

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,12 @@
13071307
}
13081308
} );
13091309

1310+
// We need to call preventDefault on dragover because otherwise if
1311+
// we drop image it will overwrite document.
1312+
editable.attachListener( dropTarget, 'dragover', function( evt ) {
1313+
evt.data.preventDefault();
1314+
} );
1315+
13101316
editable.attachListener( dropTarget, 'drop', function( evt ) {
13111317
// Cancel native drop.
13121318
evt.data.preventDefault();
@@ -1807,6 +1813,7 @@
18071813
chromeWindowsRegExp: /<!--StartFragment-->([\s\S]*)<!--EndFragment-->/,
18081814

18091815
data: {},
1816+
files: [],
18101817

18111818
normalizeType: function( type ) {
18121819
type = type.toLowerCase();
@@ -2017,7 +2024,8 @@
20172024
return;
20182025
}
20192026

2020-
var that = this;
2027+
var that = this,
2028+
i;
20212029

20222030
function getAndSetData( type ) {
20232031
var data = that.getData( type );
@@ -2026,14 +2034,48 @@
20262034
}
20272035
}
20282036

2037+
// Copy data.
20292038
if ( CKEDITOR.env.ie ) {
20302039
getAndSetData( 'Text' );
20312040
getAndSetData( 'URL' );
20322041
} else if ( this.$.types ) {
2033-
for ( var i = 0; i < this.$.types.length; i++ ) {
2042+
for ( i = 0; i < this.$.types.length; i++ ) {
20342043
getAndSetData( this.$.types[ i ] );
20352044
}
20362045
}
2046+
2047+
// Copy files references.
2048+
if ( this.$ && this.$.files ) {
2049+
this._.files = [];
2050+
2051+
for ( i = 0; i < this.$.files.length; i++ ) {
2052+
this._.files.push( this.$.files[ i ] );
2053+
}
2054+
}
2055+
},
2056+
2057+
getFilesCount: function() {
2058+
if ( this._.files.length ) {
2059+
return this._.files.length;
2060+
}
2061+
2062+
if ( this.$ && this.$.files && this.$.files.length ) {
2063+
return this.$.files.length;
2064+
}
2065+
2066+
return 0;
2067+
},
2068+
2069+
getFile: function( i ) {
2070+
if ( this._.files.length ) {
2071+
return this._.files[ i ];
2072+
}
2073+
2074+
if ( this.$ && this.$.files && this.$.files.length ) {
2075+
return this.$.files[ i ];
2076+
}
2077+
2078+
return null;
20372079
},
20382080

20392081
/**
@@ -2045,6 +2087,11 @@
20452087
var typesToCheck = {},
20462088
type;
20472089

2090+
// If dataTransfer contains files it is not empty.
2091+
if ( this.getFilesCount() ) {
2092+
return false;
2093+
}
2094+
20482095
// Add custom types.
20492096
for ( type in this._.data ) {
20502097
typesToCheck[ type ] = 1;

tests/_benderjs/ckeditor/static/tools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@
777777
mockNativeDataTransfer: function() {
778778
return {
779779
types: [],
780+
files: CKEDITOR.env.ie && CKEDITOR.env.version < 10 ? undefined : [],
780781
_data: [],
781782
// Emulate browsers native behavior for getDeta/setData.
782783
setData: function( type, data ) {

tests/plugins/clipboard/datatransfer.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,58 @@ bender.test( {
348348

349349
assert.areSame( 'foo', dataTransfer.getData( 'cke/custom' ) );
350350
assert.areSame( '', dataTransfer.getData( 'cke/undefined' ) );
351+
},
352+
353+
'test files empty': function() {
354+
var nativeData = bender.tools.mockNativeDataTransfer(),
355+
dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );
351356

357+
dataTransfer.cacheData();
358+
359+
assert.areSame( 0, dataTransfer.getFilesCount() );
360+
assert.isFalse( !!dataTransfer.getFile( 0 ) );
361+
},
362+
363+
'test files': function() {
364+
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {
365+
assert.ignore();
366+
}
367+
368+
var nativeData = bender.tools.mockNativeDataTransfer(),
369+
dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );
370+
371+
nativeData.files.push( 'foo' );
372+
nativeData.files.push( 'bar' );
373+
374+
assert.areSame( 2, dataTransfer.getFilesCount() );
375+
assert.areSame( 'foo', dataTransfer.getFile( 0 ) );
376+
assert.areSame( 'bar', dataTransfer.getFile( 1 ) );
377+
},
378+
379+
'test files with cache': function() {
380+
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {
381+
assert.ignore();
382+
}
383+
384+
var nativeData = bender.tools.mockNativeDataTransfer(),
385+
dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );
386+
387+
nativeData.files.push( 'foo' );
388+
nativeData.files.push( 'bar' );
389+
390+
dataTransfer.cacheData();
391+
392+
assert.areSame( 2, dataTransfer.getFilesCount() );
393+
assert.areSame( 'foo', dataTransfer.getFile( 0 ) );
394+
assert.areSame( 'bar', dataTransfer.getFile( 1 ) );
395+
assert.isFalse( !!dataTransfer.getFile( 2 ) );
396+
397+
nativeData.files = [];
398+
399+
assert.areSame( 2, dataTransfer.getFilesCount() );
400+
assert.areSame( 'foo', dataTransfer.getFile( 0 ) );
401+
assert.areSame( 'bar', dataTransfer.getFile( 1 ) );
402+
assert.isFalse( !!dataTransfer.getFile( 2 ) );
352403
},
353404

354405
'test isEmpty 1': function() {
@@ -437,6 +488,34 @@ bender.test( {
437488
assert.isFalse( dataTransfer.isEmpty() );
438489
},
439490

491+
'test isEmpty 11': function() {
492+
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {
493+
assert.ignore();
494+
}
495+
496+
var nativeData = bender.tools.mockNativeDataTransfer(),
497+
dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );
498+
499+
nativeData.files.push( 'foo' );
500+
501+
assert.isFalse( dataTransfer.isEmpty() );
502+
},
503+
504+
'test isEmpty 12': function() {
505+
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 10 ) {
506+
assert.ignore();
507+
}
508+
509+
var nativeData = bender.tools.mockNativeDataTransfer(),
510+
dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );
511+
512+
nativeData.files.push( 'foo' );
513+
dataTransfer.cacheData();
514+
nativeData.files = [];
515+
516+
assert.isFalse( dataTransfer.isEmpty() );
517+
},
518+
440519
'test initDragDataTransfer binding': function() {
441520
var nativeData1 = bender.tools.mockNativeDataTransfer(),
442521
nativeData2 = bender.tools.mockNativeDataTransfer(),

0 commit comments

Comments
 (0)