All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.bower_components.blueimpfileupload.js.jquery.fileupload-ui.min.js Maven / Gradle / Ivy

Go to download

File Upload widget with multiple file selection, drag and drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.

There is a newer version: 1.2.2.1-jre17
Show newest version
(function(a){if(typeof define==="function"&&define.amd){define(["jquery","blueimp-tmpl","./jquery.fileupload-image","./jquery.fileupload-audio","./jquery.fileupload-video","./jquery.fileupload-validate"],a)}else{if(typeof exports==="object"){a(require("jquery"),require("blueimp-tmpl"),require("./jquery.fileupload-image"),require("./jquery.fileupload-audio"),require("./jquery.fileupload-video"),require("./jquery.fileupload-validate"))}else{a(window.jQuery,window.tmpl)}}}(function(b,a){b.blueimp.fileupload.prototype._specialOptions.push("filesContainer","uploadTemplateId","downloadTemplateId");b.widget("blueimp.fileupload",b.blueimp.fileupload,{options:{autoUpload:false,uploadTemplateId:"template-upload",downloadTemplateId:"template-download",filesContainer:undefined,prependFiles:false,dataType:"json",messages:{unknownError:"Unknown error"},getNumberOfFiles:function(){return this.filesContainer.children().not(".processing").length},getFilesFromResponse:function(c){if(c.result&&b.isArray(c.result.files)){return c.result.files}return[]},add:function(h,f){if(h.isDefaultPrevented()){return false}var g=b(this),d=g.data("blueimp-fileupload")||g.data("fileupload"),c=d.options;f.context=d._renderUpload(f.files).data("data",f).addClass("processing");c.filesContainer[c.prependFiles?"prepend":"append"](f.context);d._forceReflow(f.context);d._transition(f.context);f.process(function(){return g.fileupload("process",f)}).always(function(){f.context.each(function(e){b(this).find(".size").text(d._formatFileSize(f.files[e].size))}).removeClass("processing");d._renderPreviews(f)}).done(function(){f.context.find(".start").prop("disabled",false);if((d._trigger("added",h,f)!==false)&&(c.autoUpload||f.autoUpload)&&f.autoUpload!==false){f.submit()}}).fail(function(){if(f.files.error){f.context.each(function(i){var e=f.files[i].error;if(e){b(this).find(".error").text(e)}})}})},send:function(f,d){if(f.isDefaultPrevented()){return false}var c=b(this).data("blueimp-fileupload")||b(this).data("fileupload");if(d.context&&d.dataType&&d.dataType.substr(0,6)==="iframe"){d.context.find(".progress").addClass(!b.support.transition&&"progress-animated").attr("aria-valuenow",100).children().first().css("width","100%")}return c._trigger("sent",f,d)},done:function(j,i){if(j.isDefaultPrevented()){return false}var h=b(this).data("blueimp-fileupload")||b(this).data("fileupload"),d=i.getFilesFromResponse||h.options.getFilesFromResponse,g=d(i),f,c;if(i.context){i.context.each(function(e){var k=g[e]||{error:"Empty file upload result"};c=h._addFinishedDeferreds();h._transition(b(this)).done(function(){var l=b(this);f=h._renderDownload([k]).replaceAll(l);h._forceReflow(f);h._transition(f).done(function(){i.context=b(this);h._trigger("completed",j,i);h._trigger("finished",j,i);c.resolve()})})})}else{f=h._renderDownload(g)[h.options.prependFiles?"prependTo":"appendTo"](h.options.filesContainer);h._forceReflow(f);c=h._addFinishedDeferreds();h._transition(f).done(function(){i.context=b(this);h._trigger("completed",j,i);h._trigger("finished",j,i);c.resolve()})}},fail:function(h,g){if(h.isDefaultPrevented()){return false}var f=b(this).data("blueimp-fileupload")||b(this).data("fileupload"),d,c;if(g.context){g.context.each(function(e){if(g.errorThrown!=="abort"){var i=g.files[e];i.error=i.error||g.errorThrown||g.i18n("unknownError");c=f._addFinishedDeferreds();f._transition(b(this)).done(function(){var j=b(this);d=f._renderDownload([i]).replaceAll(j);f._forceReflow(d);f._transition(d).done(function(){g.context=b(this);f._trigger("failed",h,g);f._trigger("finished",h,g);c.resolve()})})}else{c=f._addFinishedDeferreds();f._transition(b(this)).done(function(){b(this).remove();f._trigger("failed",h,g);f._trigger("finished",h,g);c.resolve()})}})}else{if(g.errorThrown!=="abort"){g.context=f._renderUpload(g.files)[f.options.prependFiles?"prependTo":"appendTo"](f.options.filesContainer).data("data",g);f._forceReflow(g.context);c=f._addFinishedDeferreds();f._transition(g.context).done(function(){g.context=b(this);f._trigger("failed",h,g);f._trigger("finished",h,g);c.resolve()})}else{f._trigger("failed",h,g);f._trigger("finished",h,g);f._addFinishedDeferreds().resolve()}}},progress:function(f,d){if(f.isDefaultPrevented()){return false}var c=Math.floor(d.loaded/d.total*100);if(d.context){d.context.each(function(){b(this).find(".progress").attr("aria-valuenow",c).children().first().css("width",c+"%")})}},progressall:function(h,f){if(h.isDefaultPrevented()){return false}var g=b(this),d=Math.floor(f.loaded/f.total*100),c=g.find(".fileupload-progress"),i=c.find(".progress-extended");if(i.length){i.html((g.data("blueimp-fileupload")||g.data("fileupload"))._renderExtendedProgress(f))}c.find(".progress").attr("aria-valuenow",d).children().first().css("width",d+"%")},start:function(d){if(d.isDefaultPrevented()){return false}var c=b(this).data("blueimp-fileupload")||b(this).data("fileupload");c._resetFinishedDeferreds();c._transition(b(this).find(".fileupload-progress")).done(function(){c._trigger("started",d)})},stop:function(f){if(f.isDefaultPrevented()){return false}var d=b(this).data("blueimp-fileupload")||b(this).data("fileupload"),c=d._addFinishedDeferreds();b.when.apply(b,d._getFinishedDeferreds()).done(function(){d._trigger("stopped",f)});d._transition(b(this).find(".fileupload-progress")).done(function(){b(this).find(".progress").attr("aria-valuenow","0").children().first().css("width","0%");b(this).find(".progress-extended").html(" ");c.resolve()})},processstart:function(c){if(c.isDefaultPrevented()){return false}b(this).addClass("fileupload-processing")},processstop:function(c){if(c.isDefaultPrevented()){return false}b(this).removeClass("fileupload-processing")},destroy:function(f,d){if(f.isDefaultPrevented()){return false}var c=b(this).data("blueimp-fileupload")||b(this).data("fileupload"),g=function(){c._transition(d.context).done(function(){b(this).remove();c._trigger("destroyed",f,d)})};if(d.url){d.dataType=d.dataType||c.options.dataType;b.ajax(d).done(g).fail(function(){c._trigger("destroyfailed",f,d)})}else{g()}}},_resetFinishedDeferreds:function(){this._finishedUploads=[]},_addFinishedDeferreds:function(c){if(!c){c=b.Deferred()}this._finishedUploads.push(c);return c},_getFinishedDeferreds:function(){return this._finishedUploads},_enableDragToDesktop:function(){var f=b(this),d=f.prop("href"),c=f.prop("download"),e="application/octet-stream";f.bind("dragstart",function(g){try{g.originalEvent.dataTransfer.setData("DownloadURL",[e,c,d].join(":"))}catch(h){}})},_formatFileSize:function(c){if(typeof c!=="number"){return""}if(c>=1000000000){return(c/1000000000).toFixed(2)+" GB"}if(c>=1000000){return(c/1000000).toFixed(2)+" MB"}return(c/1000).toFixed(2)+" KB"},_formatBitrate:function(c){if(typeof c!=="number"){return""}if(c>=1000000000){return(c/1000000000).toFixed(2)+" Gbit/s"}if(c>=1000000){return(c/1000000).toFixed(2)+" Mbit/s"}if(c>=1000){return(c/1000).toFixed(2)+" kbit/s"}return c.toFixed(2)+" bit/s"},_formatTime:function(d){var c=new Date(d*1000),e=Math.floor(d/86400);e=e?e+"d ":"";return e+("0"+c.getUTCHours()).slice(-2)+":"+("0"+c.getUTCMinutes()).slice(-2)+":"+("0"+c.getUTCSeconds()).slice(-2)},_formatPercentage:function(c){return(c*100).toFixed(2)+" %"},_renderExtendedProgress:function(c){return this._formatBitrate(c.bitrate)+" | "+this._formatTime((c.total-c.loaded)*8/c.bitrate)+" | "+this._formatPercentage(c.loaded/c.total)+" | "+this._formatFileSize(c.loaded)+" / "+this._formatFileSize(c.total)},_renderTemplate:function(e,d){if(!e){return b()}var c=e({files:d,formatFileSize:this._formatFileSize,options:this.options});if(c instanceof b){return c}return b(this.options.templatesContainer).html(c).children()},_renderPreviews:function(c){c.context.find(".preview").each(function(d,e){b(e).append(c.files[d].preview)})},_renderUpload:function(c){return this._renderTemplate(this.options.uploadTemplate,c)},_renderDownload:function(c){return this._renderTemplate(this.options.downloadTemplate,c).find("a[download]").each(this._enableDragToDesktop).end()},_startHandler:function(g){g.preventDefault();var c=b(g.currentTarget),d=c.closest(".template-upload"),f=d.data("data");c.prop("disabled",true);if(f&&f.submit){f.submit()}},_cancelHandler:function(f){f.preventDefault();var c=b(f.currentTarget).closest(".template-upload,.template-download"),d=c.data("data")||{};d.context=d.context||c;if(d.abort){d.abort()}else{d.errorThrown="abort";this._trigger("fail",f,d)}},_deleteHandler:function(d){d.preventDefault();var c=b(d.currentTarget);this._trigger("destroy",d,b.extend({context:c.closest(".template-download"),type:"DELETE"},c.data()))},_forceReflow:function(c){return b.support.transition&&c.length&&c[0].offsetWidth},_transition:function(d){var c=b.Deferred();if(b.support.transition&&d.hasClass("fade")&&d.is(":visible")){d.bind(b.support.transition.end,function(f){if(f.target===d[0]){d.unbind(b.support.transition.end);c.resolveWith(d)}}).toggleClass("in")}else{d.toggleClass("in");c.resolveWith(d)}return c},_initButtonBarEventHandlers:function(){var c=this.element.find(".fileupload-buttonbar"),d=this.options.filesContainer;this._on(c.find(".start"),{click:function(f){f.preventDefault();d.find(".start").click()}});this._on(c.find(".cancel"),{click:function(f){f.preventDefault();d.find(".cancel").click()}});this._on(c.find(".delete"),{click:function(f){f.preventDefault();d.find(".toggle:checked").closest(".template-download").find(".delete").click();c.find(".toggle").prop("checked",false)}});this._on(c.find(".toggle"),{change:function(f){d.find(".toggle").prop("checked",b(f.currentTarget).is(":checked"))}})},_destroyButtonBarEventHandlers:function(){this._off(this.element.find(".fileupload-buttonbar").find(".start, .cancel, .delete"),"click");this._off(this.element.find(".fileupload-buttonbar .toggle"),"change.")},_initEventHandlers:function(){this._super();this._on(this.options.filesContainer,{"click .start":this._startHandler,"click .cancel":this._cancelHandler,"click .delete":this._deleteHandler});this._initButtonBarEventHandlers()},_destroyEventHandlers:function(){this._destroyButtonBarEventHandlers();this._off(this.options.filesContainer,"click");this._super()},_enableFileInputButton:function(){this.element.find(".fileinput-button input").prop("disabled",false).parent().removeClass("disabled")},_disableFileInputButton:function(){this.element.find(".fileinput-button input").prop("disabled",true).parent().addClass("disabled")},_initTemplates:function(){var c=this.options;c.templatesContainer=this.document[0].createElement(c.filesContainer.prop("nodeName"));if(a){if(c.uploadTemplateId){c.uploadTemplate=a(c.uploadTemplateId)}if(c.downloadTemplateId){c.downloadTemplate=a(c.downloadTemplateId)}}},_initFilesContainer:function(){var c=this.options;if(c.filesContainer===undefined){c.filesContainer=this.element.find(".files")}else{if(!(c.filesContainer instanceof b)){c.filesContainer=b(c.filesContainer)}}},_initSpecialOptions:function(){this._super();this._initFilesContainer();this._initTemplates()},_create:function(){this._super();this._resetFinishedDeferreds();if(!b.support.fileInput){this._disableFileInputButton()}},enable:function(){var c=false;if(this.options.disabled){c=true}this._super();if(c){this.element.find("input, button").prop("disabled",false);this._enableFileInputButton()}},disable:function(){if(!this.options.disabled){this.element.find("input, button").prop("disabled",true);this._disableFileInputButton()}this._super()}})}));




© 2015 - 2025 Weber Informatics LLC | Privacy Policy