1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-08 12:44:03 +00:00
seahub/media/js/jquery.fileupload.min.js

47 lines
34 KiB
JavaScript
Raw Normal View History

// tmpl.min.js
(function(a){"use strict";var b=function(a,c){var d=/[^\w\-\.:]/.test(a)?new Function(b.arg+",tmpl","var _e=tmpl.encode"+b.helper+",_s='"+a.replace(b.regexp,b.func)+"';return _s;"):b.cache[a]=b.cache[a]||b(b.load(a));return c?d(c,b):function(a){return d(a,b)}};b.cache={},b.load=function(a){return document.getElementById(a).innerHTML},b.regexp=/([\s'\\])(?![^%]*%\})|(?:\{%(=|#)([\s\S]+?)%\})|(\{%)|(%\})/g,b.func=function(a,b,c,d,e,f){if(b)return{"\n":"\\n","\r":"\\r","\t":"\\t"," ":" "}[a]||"\\"+a;if(c)return c==="="?"'+_e("+d+")+'":"'+("+d+"||'')+'";if(e)return"';";if(f)return"_s+='"},b.encReg=/[<>&"'\x00]/g,b.encMap={"<":"&lt;",">":"&gt;","&":"&amp;",'"':"&quot;","'":"&#39;"},b.encode=function(a){return String(a||"").replace(b.encReg,function(a){return b.encMap[a]||""})},b.arg="o",b.helper=",print=function(s,e){_s+=e&&(s||'')||_e(s);},include=function(s,d){_s+=tmpl(s,d);}",typeof define=="function"&&define.amd?define(function(){return b}):a.tmpl=b})(this);
/*
* jQuery Iframe Transport Plugin 1.4
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2011, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory);}else{factory(window.jQuery);}}(function($){var counter=0;$.ajaxTransport("iframe",function(options){if(options.async&&(options.type==="POST"||options.type==="GET")){var form,iframe;return{send:function(_,completeCallback){form=$('<form style="display:none;"></form>');iframe=$('<iframe src="javascript:false;" name="iframe-transport-'+(counter+=1)+'"></iframe>').bind("load",function(){var fileInputClones,paramNames=$.isArray(options.paramName)?options.paramName:[options.paramName];iframe.unbind("load").bind("load",function(){var response;try{response=iframe.contents();if(!response.length||!response[0].firstChild){throw new Error();}}catch(e){response=undefined;}completeCallback(200,"success",{"iframe":response});$('<iframe src="javascript:false;"></iframe>').appendTo(form);form.remove();});form.prop("target",iframe.prop("name")).prop("action",options.url).prop("method",options.type);if(options.formData){$.each(options.formData,function(index,field){$('<input type="hidden"/>').prop("name",field.name).val(field.value).appendTo(form);});}if(options.fileInput&&options.fileInput.length&&options.type==="POST"){fileInputClones=options.fileInput.clone();options.fileInput.after(function(index){return fileInputClones[index];});if(options.paramName){options.fileInput.each(function(index){$(this).prop("name",paramNames[index]||options.paramName);});}form.append(options.fileInput).prop("enctype","multipart/form-data").prop("encoding","multipart/form-data");}form.submit();if(fileInputClones&&fileInputClones.length){options.fileInput.each(function(index,input){var clone=$(fileInputClones[index]);$(input).prop("name",clone.prop("name"));clone.replaceWith(input);});}});form.append(iframe).appendTo(document.body);},abort:function(){if(iframe){iframe.unbind("load").prop("src","javascript".concat(":false;"));}if(form){form.remove();}}};}});$.ajaxSetup({converters:{"iframe text":function(iframe){return $(iframe[0].body).text();},"iframe json":function(iframe){return $.parseJSON($(iframe[0].body).text());},"iframe html":function(iframe){return $(iframe[0].body).html();},"iframe script":function(iframe){return $.globalEval($(iframe[0].body).text());}}});}));
/*
* jQuery File Upload Plugin 5.11.2
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","jquery.ui.widget"],factory);}else{factory(window.jQuery);}}(function($){$.support.xhrFileUpload=!!(window.XMLHttpRequestUpload&&window.FileReader);$.support.xhrFormDataFileUpload=!!window.FormData;$.widget("blueimp.fileupload",{options:{namespace:undefined,dropZone:$(document),fileInput:undefined,replaceFileInput:true,paramName:undefined,singleFileUploads:true,limitMultiFileUploads:undefined,sequentialUploads:false,limitConcurrentUploads:undefined,forceIframeTransport:false,redirect:undefined,redirectParamName:undefined,postMessage:undefined,multipart:true,maxChunkSize:undefined,uploadedBytes:undefined,recalculateProgress:true,progressInterval:100,bitrateInterval:500,formData:function(form){return form.serializeArray();},add:function(e,data){data.submit();},processData:false,contentType:false,cache:false},_refreshOptionsList:["namespace","dropZone","fileInput","multipart","forceIframeTransport"],_BitrateTimer:function(){this.timestamp=+(new Date());this.loaded=0;this.bitrate=0;this.getBitrate=function(now,loaded,interval){var timeDiff=now-this.timestamp;if(!this.bitrate||!interval||timeDiff>interval){this.bitrate=(loaded-this.loaded)*(1000/timeDiff)*8;this.loaded=loaded;this.timestamp=now;}return this.bitrate;};},_isXHRUpload:function(options){return !options.forceIframeTransport&&((!options.multipart&&$.support.xhrFileUpload)||$.support.xhrFormDataFileUpload);},_getFormData:function(options){var formData;if(typeof options.formData==="function"){return options.formData(options.form);}if($.isArray(options.formData)){return options.formData;}if(options.formData){formData=[];$.each(options.formData,function(name,value){formData.push({name:name,value:value});});return formData;}return[];},_getTotal:function(files){var total=0;$.each(files,function(index,file){total+=file.size||1;});return total;},_onProgress:function(e,data){if(e.lengthComputable){var now=+(new Date()),total,loaded;if(data._time&&data.progressInterval&&(now-data._time<data.progressInterval)&&e.loaded!==e.total){return;}data._time=now;total=data.total||this._getTotal(data.files);loaded=parseInt(e.loaded/e.total*(data.chunkSize||total),10)+(data.uploadedBytes||0);this._loaded+=loaded-(data.loaded||data.uploadedBytes||0);data.lengthComputable=true;data.loaded=loaded;data.total=total;data.bitrate=data._bitrateTimer.getBitrate(now,loaded,data.bitrateInterval);this._trigger("progress",e,data);this._trigger("progressall",e,{lengthComputable:true,loaded:this._loaded,total:this._total,bitrate:this._bitrateTimer.getBitrate(now,this._loaded,data.bitrateInterval)});}},_initProgressListener:function(options){var that=this,xhr=options.xhr?options.xhr():$.ajaxSettings.xhr();if(xhr.upload){$(xhr.upload).bind("progress",function(e){var oe=e.originalEvent;e.lengthComputable=oe.lengthComputable;e.loaded=oe.loaded;e.total=oe.total;that._onProgress(e,options);});options.xhr=function(){return xhr;};}},_initXHRData:function(options){var formData,file=options.files[0],multipart=options.multipart||!$.support.xhrFileUpload,paramName=options.paramName[0];if(!multipart||options.blob){options.headers=$.extend(options.headers,{"X-File-Name":file.name,"X-File-Type":file.type,"X-File-Size":file.size});if(!options.blob){options.contentType=file.type;options.data=file;}else{if(!multipart){options.contentType="application/octet-stream";options.data=options.blob;}}}if(multipart&&$.support.xhrFormDataFileUpload){if(options.postMessage){formData=this._getFormData(options);if(options.blob){formData.push({name:paramName,value:options.blob});}else{$.each(options.files,function(index,file){formData.push({name:options.paramName[index]||paramName,value:file});});}}else{if(options.formData instanceof FormData){formData=options.formData;}else{formData=new FormData();$.each(this._getFormData(options),function(index,field){formData.append(field.name,field.value);});}if(options.blob){formData.append(paramName,options.blob,file.name);}else{$.each(options.files,function(index,file){if(file instanceof Blob){formData.append(option
/*
* jQuery File Upload File Processing Plugin 1.0
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2012, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","load-image","canvas-to-blob","./jquery.fileupload"],factory);}else{factory(window.jQuery,window.loadImage);}}(function($,loadImage){$.widget("blueimpFP.fileupload",$.blueimp.fileupload,{options:{process:[],add:function(e,data){$(this).fileupload("process",data).done(function(){data.submit();});}},processActions:{load:function(data,options){var that=this,file=data.files[data.index],dfd=$.Deferred();if(window.HTMLCanvasElement&&window.HTMLCanvasElement.prototype.toBlob&&($.type(options.maxFileSize)!=="number"||file.size<options.maxFileSize)&&(!options.fileTypes||options.fileTypes.test(file.type))){loadImage(file,function(canvas){data.canvas=canvas;dfd.resolveWith(that,[data]);},{canvas:true});}else{dfd.rejectWith(that,[data]);}return dfd.promise();},resize:function(data,options){if(data.canvas){var canvas=loadImage.scale(data.canvas,options);if(canvas.width!==data.canvas.width||canvas.height!==data.canvas.height){data.canvas=canvas;data.processed=true;}}return data;},save:function(data,options){if(!data.canvas||!data.processed){return data;}var that=this,file=data.files[data.index],name=file.name,dfd=$.Deferred(),callback=function(blob){if(!blob.name){if(file.type===blob.type){blob.name=file.name;}else{if(file.name){blob.name=file.name.replace(/\..+$/,"."+blob.type.substr(6));}}}data.files[data.index]=blob;dfd.resolveWith(that,[data]);};if(data.canvas.mozGetAsFile){callback(data.canvas.mozGetAsFile((/^image\/(jpeg|png)$/.test(file.type)&&name)||((name&&name.replace(/\..+$/,""))||"blob")+".png",file.type));}else{data.canvas.toBlob(callback,file.type);}return dfd.promise();}},_processFile:function(files,index,options){var that=this,dfd=$.Deferred().resolveWith(that,[{files:files,index:index}]),chain=dfd.promise();that._processing+=1;$.each(options.process,function(i,settings){chain=chain.pipe(function(data){return that.processActions[settings.action].call(this,data,settings);});});chain.always(function(){that._processing-=1;if(that._processing===0){that.element.removeClass("fileupload-processing");}});if(that._processing===1){that.element.addClass("fileupload-processing");}return chain;},process:function(data){var that=this,options=$.extend({},this.options,data);if(options.process&&options.process.length&&this._isXHRUpload(options)){$.each(data.files,function(index,file){that._processingQueue=that._processingQueue.pipe(function(){var dfd=$.Deferred();that._processFile(data.files,index,options).always(function(){dfd.resolveWith(that);});return dfd.promise();});});}return this._processingQueue;},_create:function(){$.blueimp.fileupload.prototype._create.call(this);this._processing=0;this._processingQueue=$.Deferred().resolveWith(this).promise();}});}));
/*
* jQuery File Upload User Interface Plugin 6.8.1
* https://github.com/blueimp/jQuery-File-Upload
*
* Copyright 2010, Sebastian Tschan
* https://blueimp.net
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","tmpl","load-image","./jquery.fileupload-fp"],factory);}else{factory(window.jQuery,window.tmpl,window.loadImage);}}(function($,tmpl,loadImage){var parentWidget=($.blueimpFP||$.blueimp).fileupload;$.widget("blueimpUI.fileupload",parentWidget,{options:{autoUpload:false,maxNumberOfFiles:undefined,maxFileSize:undefined,minFileSize:undefined,acceptFileTypes:/.+$/i,previewSourceFileTypes:/^image\/(gif|jpeg|png)$/,previewSourceMaxFileSize:5000000,previewMaxWidth:80,previewMaxHeight:80,previewAsCanvas:true,uploadTemplateId:"template-upload",downloadTemplateId:"template-download",filesContainer:undefined,prependFiles:false,dataType:"json",add:function(e,data){var that=$(this).data("fileupload"),options=that.options,files=data.files;$(this).fileupload("process",data).done(function(){that._adjustMaxNumberOfFiles(-files.length);data.isAdjusted=true;data.files.valid=data.isValidated=that._validate(files);data.context=that._renderUpload(files).data("data",data);options.filesContainer[options.prependFiles?"prepend":"append"](data.context);that._renderPreviews(files,data.context);that._forceReflow(data.context);that._transition(data.context).done(function(){if((that._trigger("added",e,data)!==false)&&(options.autoUpload||data.autoUpload)&&data.autoUpload!==false&&data.isValidated){data.submit();}});});},send:function(e,data){var that=$(this).data("fileupload");if(!data.isValidated){if(!data.isAdjusted){that._adjustMaxNumberOfFiles(-data.files.length);}if(!that._validate(data.files)){return false;}}if(data.context&&data.dataType&&data.dataType.substr(0,6)==="iframe"){data.context.find(".progress").addClass(!$.support.transition&&"progress-animated").find(".bar").css("width",parseInt(100,10)+"%");}return that._trigger("sent",e,data);},done:function(e,data){$(".saving-tip",$(this)).addClass("hide");var that=$(this).data("fileupload"),template;if(data.context){data.context.each(function(index){var file=($.isArray(data.result)&&data.result[index])||{error:"emptyResult"};file.size=data.files[index].size;if(file.error){file.error=data.result.error||"emptyResult";file.name=data.files[index].name;that._adjustMaxNumberOfFiles(1);}that._transition($(this)).done(function(){var node=$(this);template=that._renderDownload([file]).css("height",node.height()).replaceAll(node);that._forceReflow(template);that._transition(template).done(function(){data.context=$(this);that._trigger("completed",e,data);});});});}else{template=that._renderDownload(data.result).appendTo(that.options.filesContainer);that._forceReflow(template);that._transition(template).done(function(){data.context=$(this);that._trigger("completed",e,data);});}},fail:function(e,data){$(".saving-tip",$(this)).addClass("hide");var that=$(this).data("fileupload"),template;that._adjustMaxNumberOfFiles(data.files.length);if(data.context){data.context.each(function(index){if(data.errorThrown!=="abort"){var file=data.files[index];var r_error;if(data.jqXHR.responseText){try{r_error=$.parseJSON(data.jqXHR.responseText).error;}catch(e){r_error="";}}if(data.dataType=="iframe json"){data.errorThrown="";}file.error=r_error||file.error||data.errorThrown||"can not connect the server";that._transition($(this)).done(function(){var node=$(this);template=that._renderDownload([file]).replaceAll(node);that._forceReflow(template);that._transition(template).done(function(){data.context=$(this);that._trigger("failed",e,data);});});}else{that._transition($(this)).done(function(){$(this).remove();that._trigger("failed",e,data);});}});}else{if(data.errorThrown!=="abort"){that._adjustMaxNumberOfFiles(-data.files.length);data.context=that._renderUpload(data.files).appendTo(that.options.filesContainer).data("data",data);that._forceReflow(data.context);that._transition(data.context).done(function(){data.context=$(this);that._trigger("failed",e,data);});}else{that._trigger("failed",e,data);}}},progress:function(e,data){if(data.context){data.context.find(".bar").css("width",parseInt(data.loaded/data.total*100,10)+"%");}},progressall:function(e,da