CKEDITOR.plugins.add('droploader', {
	init: function (editor) {

		var pluginDirectory = this.path;
		editor.addContentsCss(pluginDirectory + 'styles/droploader.css');

		function handleUpload(originalFilenames, url) {
			if (isImg.test(url)) {
				// var img = new CKEDITOR.dom.element('img');
				originalFilenames.forEach(function(originalFilename) {
					var img = editor.document.$.querySelector(
						'[data-filename="' + originalFilename + '"]');
					img.setAttribute('src', url);
					img = new CKEDITOR.dom.element(img);
					img.removeClass('placeholder');
				})
				// editor.insertElement(img);
			} else if (isAnotherSupportedType.test(url)) {
				var link = new CKEDITOR.dom.element('a');
				link.setAttribute('href', url);
				link.textContents = url;
				editor.insertElement(link);
			}
		}

		var isImg = /.*\.(png|jpe?g|gif)$/;
		var isAnotherSupportedType = /\.(pdf)$/;

		editor.on('contentDom', function () {
			editor.document.on('dragover', function(e) {
				var types = e.data.$.dataTransfer.types
				// in Webkit types is an array, DOMStringList elsewhere
				if ((types.indexOf && types.indexOf('Files') > -1) ||
					(types.contains && types.contains('Files'))) {
					e.data.$.preventDefault();
				}
			});

			var lastTarget;

			editor.document.on('dragenter', function(e) {
				e.data.stopPropagation();
				editor.document.getBody().addClass('droploader-dragover');
				lastTarget = e.data.$.target;
			});

			editor.document.on('dragleave', function(e) {
				e.data.stopPropagation();
				if (lastTarget == e.data.$.target) {
					editor.document.getBody().removeClass('droploader-dragover');
				}
			})

			editor.document.on('drop', function (e) {
				editor.document.getBody().removeClass('droploader-dragover');
				// Prepare dropped file for upload
				if (e.data.$.dataTransfer.files.length > 0) {
					e.data.$.preventDefault();
					var files = e.data.$.dataTransfer.files;
					var fd = new FormData();
				    var filesToUpload = [];
					for (var i=0; i<files.length; i++) {
						if (isImg.test(files[i].name) || 
							isAnotherSupportedType.test(files[i].name)) {
							fd.append('upload', files[i]);
							filesToUpload.push(files[i].name);
						}
						if (isImg.test(files[i].name)) {
							var placeholder = new CKEDITOR.dom.element('img');
							placeholder.addClass('placeholder');
							placeholder.setAttribute('data-filename', files[i].name);
							editor.insertElement(placeholder);
							var fr = new FileReader();
							fr.onload = function(e) {
								placeholder.setAttribute('src', fr.result);
							}
							fr.onerror = function(e) {
								throw new Error('Cannot load file: ' + files[i].name);
							}
							fr.readAsDataURL(files[i]);


						}
					}
					if (filesToUpload.length > 0) {
						// make a handler which remembers the original filename
						// and tell CKEditor to store it for execution
						fileUploadedHandler = CKEDITOR.tools.addFunction(
							handleUpload.bind(null, filesToUpload));

						var xhr = new XMLHttpRequest();
						xhr.open('POST', editor.config.filebrowserUploadUrl + 
							'?CKEditorFuncNum=' + fileUploadedHandler);
						xhr.responseType = 'document';
						xhr.onload = function (e) {
							if (this.status == 200) {
								//  run the callback returned as script tag 
								callbackScript = this.response.getElementsByTagName('script');
								if (callbackScript.length > 0) {
									var responseCallback = new Function("", callbackScript[0].innerHTML);
									responseCallback();
								}
							}
						}
						xhr.send(fd);
					}					
				}
			});
		});
	}
});

@@ -202,17 +202,16 @@
 Filename
-s
 , url) %7B
@@ -211,16 +211,16 @@
  url) %7B%0A
+
 %09%09%09if (i
@@ -241,118 +241,8 @@
 ) %7B%0A
-%09%09%09%09// var img = new CKEDITOR.dom.element('img');%0A%09%09%09%09originalFilenames.forEach(function(originalFilename) %7B%0A%09
 %09%09%09%09
@@ -284,17 +284,16 @@
 lector(%0A
-%09
 %09%09%09%09%09'%5Bd
@@ -336,25 +336,24 @@
  '%22%5D');%0A%09%09%09%09
-%09
 img.setAttri
@@ -370,17 +370,16 @@
 , url);%0A
-%09
 %09%09%09%09img 
@@ -415,17 +415,16 @@
 g);%0A%09%09%09%09
-%09
 img.remo
@@ -451,49 +451,8 @@
 ');%0A
-%09%09%09%09%7D)%0A%09%09%09%09// editor.insertElement(img);%0A
 %09%09%09%7D
@@ -1868,28 +1868,42 @@
 ++) %7B%0A%09%09%09%09%09%09
-if (
+var fileIsImage = 
 isImg.test(f
@@ -1919,20 +1919,42 @@
 ame)
- %7C%7C 
+;
 %0A%09%09%09%09%09%09
-%09
+var fileIsSupportedType = 
 isAn
@@ -1983,32 +1983,80 @@
 t(files%5Bi%5D.name)
+;%0A%09%09%09%09%09%09if ( fileIsImage %7C%7C fileIsSupportedType 
 ) %7B%0A%09%09%09%09%09%09%09fd.ap
@@ -2145,33 +2145,19 @@
 if (
-isImg.test(files%5Bi%5D.name)
+fileIsImage
 ) %7B%0A
@@ -2648,52 +2648,8 @@
 %09%09%7D%0A
-%09%09%09%09%09%7D%0A%09%09%09%09%09if (filesToUpload.length %3E 0) %7B%0A
 %09%09%09%09
@@ -2851,24 +2851,24 @@
 l, files
-ToUpload
+%5Bi%5D.name
 ));%0A%0A%09%09%09

Fix handling of multiple files