/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/plugin/dragUpload/index",function(e,o){function g(e){this.config=e||{}}var q=e.Node,l=e.Event,r=o.Utils,k=e.DOM;e.augment(g,{renderUI:function(g){function p(b){b=b.originalEvent.target;"img"==k.nodeName(b)&&b.src.match(/^file:\/\//)&&(m[b.src]=b)}function s(b,d){var j=new window.FileReader;j.onload=function(f){var a=b.name,f=f.target.result,c=new XMLHttpRequest;c.open("POST",t,!0);c.onreadystatechange=function(){if(4==c.readyState){if(200==c.status||304==c.status){if(""!=c.responseText){var a=
window.JSON.parse(c.responseText);d[0].src=a.imgUrl}}else alert("服务器端出错！"),d.remove();c.onreadystatechange=null}};a="\r\n------kissy-editor-yiminghe\r\n"+('Content-Disposition: form-data; name="'+u+'"; filename="'+encodeURIComponent(a)+'"\r\n');a+="Content-Type: "+(b.type||"application/octet-stream")+"\r\n\r\n";a+=f+"\r\n";h=o.Utils.normParams(h);for(var e in h)h.hasOwnProperty(e)&&(a+="------kissy-editor-yiminghe\r\n",a+='Content-Disposition: form-data; name="'+e+'"\r\n\r\n',a+=h[e]+"\r\n");a+="------kissy-editor-yiminghe--";
c.setRequestHeader("Content-Type","multipart/form-data, boundary=----kissy-editor-yiminghe");c.sendAsBinary("Content-Type: multipart/form-data; boundary=----kissy-editor-yiminghe\r\nContent-Length: "+a.length+"\r\n"+a+"\r\n");j.onload=null};j.readAsBinaryString(b)}var i=this.config,u=i.fileInput||"Filedata",v=i.sizeLimit||Number.MAX_VALUE,h=i.serverParams||{},t=i.serverUrl||"",w=RegExp((i.suffix||"png,jpg,jpeg,gif").split(/,/).join("|")+"$","i"),m={},n=!1;g.docReady(function(){var b=g.get("document")[0];
l.on(b,"dragenter",function(){n||(l.on(b,"DOMNodeInserted",p),n=!0)});l.on(b,"drop",function(d){l.remove(b,"DOMNodeInserted",p);n=!1;d.halt();var d=d.originalEvent,j,f;e.isEmptyObject(m)?(f=b.elementFromPoint(d.clientX,d.clientY),j=f.lastChild):(e.each(m,function(a){"img"==k.nodeName(a)&&(j=a.nextSibling,f=a.parentNode,k.remove(a))}),m={});d=d.dataTransfer;d.dropEffect="copy";if(d=d.files)for(var a=0;a<d.length;a++){var c=d[a],g=c.size;if(c.name.match(w)&&!(g/1E3>v)){var g=new q("<img src='"+r.debugUrl("theme/tao-loading.gif")+
"'/>"),h=g[0];f.insertBefore(h,j);var i=k.nodeName(h.parentNode);("head"==i||"html"==i)&&k.insertBefore(h,b.body.firstChild);s(c,g)}}})});window.XMLHttpRequest&&!XMLHttpRequest.prototype.sendAsBinary&&(XMLHttpRequest.prototype.sendAsBinary=function(b,d){for(var e=new (window.BlobBuilder||window.WebKitBlobBuilder),f=b.length,a=new window.Uint8Array(f),c=0;c<f;c++)a[c]=b.charCodeAt(c);e.append(a.buffer);this.send(e.getBlob(d))})}});return g},{requires:["editor"]});
