KISSY.Editor.add("dragupload",function(q){function r(a){a=a.originalEvent.target;if(n._4e_name(a)=="img"&&a.src.match(/^file:\/\//))m[a.src]=a}function t(a,g){var d=new FileReader;d.onload=function(e){var h=a.name;e=e.target.result;var b=new XMLHttpRequest;b.open("POST",u,true);b.onreadystatechange=function(){if(b.readyState==4){if(b.status==200||b.status==304){if(b.responseText!=""){var v=window.JSON.parse(b.responseText);g[0].src=v.imgUrl}}else{alert("\u670d\u52a1\u5668\u7aef\u51fa\u9519\uff01");g._4e_remove();f.log(b)}b.onreadystatechange=
null}};var c="\r\n------kissy-editor-2.1\r\n";c+='Content-Disposition: form-data; name="'+w+'"; filename="'+encodeURIComponent(h)+'"\r\n';c+="Content-Type: "+(a.type||"application/octet-stream")+"\r\n\r\n";c+=e+"\r\n";j=s.Utils.normParams(j);for(var o in j)if(j.hasOwnProperty(o)){c+="------kissy-editor-2.1\r\n";c+='Content-Disposition: form-data; name="'+o+'"\r\n\r\n';c+=j[o]+"\r\n"}c+="------kissy-editor-2.1--";b.setRequestHeader("Content-Type","multipart/form-data, boundary=----kissy-editor-2.1");
b.sendAsBinary("Content-Type: multipart/form-data; boundary=----kissy-editor-2.1\r\nContent-Length: "+c.length+"\r\n"+c+"\r\n");d.onload=null};d.readAsBinaryString(a)}var f=KISSY,s=f.Editor,x=f.Node,k=f.Event,y=f.UA,n=f.DOM,l=q.cfg.pluginConfig.dragupload||{},w=l.fileInput||"Filedata",z=l.sizeLimit||Number.MAX_VALUE,j=l.serverParams||{},u=l.serverUrl||"",A=RegExp((l.suffix||"png,jpg,jpeg,gif").split(/,/).join("|")+"$","i"),i=q.document;if(!y.ie){var m={},p=false;k.on(i,"dragenter",function(){if(!p){k.on(i,
"DOMNodeInserted",r);p=true}});k.on(i,"dragenter dragover",function(a){a.halt()});k.on(i,"drop",function(a){k.remove(i,"DOMNodeInserted",r);p=false;a.halt();a=a.originalEvent;f.log(a);var g,d;if(f.isEmptyObject(m)){d=i.elementFromPoint(a.clientX,a.clientY);g=d.lastChild}else{f.each(m,function(c){if(n._4e_name(c)=="img"){g=c.nextSibling;d=c.parentNode;n._4e_remove(c)}});m={}}a=a.dataTransfer;a.dropEffect="copy";if(a=a.files)for(var e=0;e<a.length;e++){var h=a[e],b=h.size;if(h.name.match(A))if(!(b/
1E3>z)){b=new x("<img src='"+(s.Config.base+"../theme/loading.gif")+"'/>");d.insertBefore(b[0],g);t(h,b)}}});if(window.XMLHttpRequest&&!XMLHttpRequest.prototype.sendAsBinary)XMLHttpRequest.prototype.sendAsBinary=function(a,g){for(var d=new BlobBuilder,e=a.length,h=new Uint8Array(e),b=0;b<e;b++)h[b]=a.charCodeAt(b);d.append(h.buffer);this.send(d.getBlob(g))}}},{attach:false});
