text: "use strict";layui.define(function(e){function p(t,n){try{return new Blob(t,{type:n})}catch(e){var r=new(window.BlobBuilder||window.WebKitBlobBuilder||window.MSBlobBuilder);return t.forEach(function(e){r.append(e)}),r.getBlob(n)}}function c(){var a=this,o=[],i=Array(21).join("-")+(new Date*(1e16*Math.random())).toString(36),s=XMLHttpRequest.prototype.send;this.append=function(e,t,n){o.push("--"+i+'\r\nContent-Disposition: form-data; name="'+e+'"'),t instanceof Blob?(o.push('; filename="'+(n||"blob")+'"\r\nContent-Type: '+t.type+"\r\n\r\n"),o.push(t)):o.push("\r\n\r\n"+t),o.push("\r\n")},XMLHttpRequest.prototype.send=function(e){var t,n,r=this;e===a?(o.push("--"+i+"--\r\n"),n=p(o),(t=new FileReader).onload=function(){s.call(r,t.result)},t.onerror=function(e){throw e},t.readAsArrayBuffer(n),this.setRequestHeader("Content-Type","multipart/form-data; boundary="+i),XMLHttpRequest.prototype.send=s):s.call(this,e)}}document.getElementById("choose");var u=document.createElement("canvas"),h=u.getContext("2d"),f=document.createElement("canvas"),g=f.getContext("2d"),m={elem:"j_mupload",url:"/interface/core/upload",done:{}};e("mupload",{render:function(e){var o=this;m=$.extend(m,e),$(m.elem)[0].onchange=function(){var e;this.files.length&&(1<(e=Array.prototype.slice.call(this.files)).length?alert("最多同时只可上传1张图片"):e.forEach(function(r,e){var t,a;/\/(?:jpeg|png|gif)/i.test(r.type)&&(t=new FileReader,a=document.createElement("li"),1024<r.size/1024?r.size:r.size,a.innerHTML='<div class="progress"><span></span></div>',$(".img-list").append($(a)),t.onload=function(){function e(){var e=o.compress(n);o.upload(e,r.type,$(a)),n=null}var t=this.result,n=new Image;if(n.src=t,$(a).css("background-image","url("+t+")"),t.length<=102400)return n=null,void o.upload(t,r.type,$(a));n.complete?e():n.onload=e},t.readAsDataURL(r))}))},$(m.elem).click()},compress:function(e){e.src.length;var t,n,r=e.width,a=e.height;if(1<(t=r*a/4e6)?(r/=t=Math.sqrt(t),a/=t):t=1,u.width=r,u.height=a,h.fillStyle="#fff",h.fillRect(0,0,u.width,u.height),1<(n=r*a/1e6)){var o=~~(r/(n=~~(Math.sqrt(n)+1))),i=~~(a/n);f.width=o,f.height=i;for(var s=0;s<n;s++)for(var l=0;l<n;l++)g.drawImage(e,s*o*t,l*i*t,o*t,i*t,0,0,o,i),h.drawImage(f,s*o,l*i,o,i)}else h.drawImage(e,0,0,r,a);var d=u.toDataURL("image/jpeg",.1);return f.width=f.height=u.width=u.height=0,d},upload:function(e,t,n){for(var r=window.atob(e.split(",")[1]),a=new Uint8Array(r.length),o=0,i=null,s=0;s<r.length;s++)a[s]=r.charCodeAt(s);var l=p([a],t),d=new XMLHttpRequest,u=new(~navigator.userAgent.indexOf("Android")&&~navigator.vendor.indexOf("Google")&&!~navigator.userAgent.indexOf("Chrome")&&navigator.userAgent.match(/AppleWebKit\/(\d+)/).pop()<=534?c:FormData);u.append("file",l),d.open("post",m.url),d.setRequestHeader("X-Requested-With","XMLHttpRequest"),d.setRequestHeader("X-CSRF-TOKEN",$('meta[name="csrf-token"]').attr("content")),d.onreadystatechange=function(){if(4==d.readyState&&200==d.status){var e=JSON.parse(d.responseText).data||{},t=e.url?"上传成功":"上传失败";if(clearInterval(i),n.find(".progress span").animate({width:"100%"},o<95?200:0,function(){$(this).html(t)}),!e.url)return;"function"==typeof m.done&&m.done(e.url)}},d.upload.addEventListener("progress",function(e){i||(o=~~(100*e.loaded/e.total)/2,n.find(".progress span").css("width",o+"%"),50==o&&(i=i||setInterval(function(){o++,n.find(".progress span").css("width",o+"%"),99==o&&clearInterval(i)},100)))},!1),d.send(u)}})});