/*! * @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 * @version 2.1.0 * bootstrap-fileinput * For more JQuery Plugins visit http://plugins.krajee.com */!function(e){var i='{preview}\n
\n {caption}\n
\n {remove}\n {upload}\n {browse}\n
\n
',t="{preview}\n{remove}\n{upload}\n{browse}\n",n='
\n
\n
×
\n
\n
',a='
\n
\n
',r='\n',l='
\n {content}\n
\n',o='
\n
\n {strText}\n
\n
\n',s='
\n
\n

\n {caption}\n
\n
',p=function(i,t){return null===i||void 0===i||i==[]||""===i||t&&""===e.trim(i)},d=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},c=function(i,t,n){return p(i)||p(i[t])?n:e(i[t])},m=function(e,i){return"undefined"!=typeof e?e.match("image.*"):i.match(/\.(gif|png|jpe?g)$/i)},v=function(e,i){return"undefined"!=typeof e?e.match("text.*"):i.match(/\.(txt|md|csv|htm|html|php|ini)$/i)},u=function(){return Math.round((new Date).getTime()+100*Math.random())},w=function(){return window.File&&window.FileReader&&window.FileList&&window.Blob},f=window.URL||window.webkitURL,g=function(i,t){this.$element=e(i),w?(this.init(t),this.listen()):this.$element.removeClass("file-loading")};g.prototype={constructor:g,init:function(e){var n=this;n.reader=null,n.showCaption=e.showCaption,n.showPreview=e.showPreview,n.maxFileSize=e.maxFileSize,n.maxFilesCount=e.maxFilesCount,n.msgSizeTooLarge=e.msgSizeTooLarge,n.msgFilesTooMany=e.msgFilesTooMany,n.msgFileNotFound=e.msgFileNotFound,n.msgFileNotReadable=e.msgFileNotReadable,n.msgFilePreviewAborted=e.msgFilePreviewAborted,n.msgFilePreviewError=e.msgFilePreviewError,n.msgErrorClass=e.msgErrorClass,n.initialDelimiter=e.initialDelimiter,n.initialPreview=e.initialPreview,n.initialCaption=e.initialCaption,n.initialPreviewCount=e.initialPreviewCount,n.initialPreviewContent=e.initialPreviewContent,n.overwriteInitial=e.overwriteInitial,n.showRemove=e.showRemove,n.showUpload=e.showUpload,n.captionClass=e.captionClass,n.previewClass=e.previewClass,n.mainClass=e.mainClass,n.mainTemplate=p(e.mainTemplate)?n.showCaption?i:t:e.mainTemplate,n.previewTemplate=n.showPreview?e.previewTemplate:"",n.previewGenericTemplate=e.previewGenericTemplate,n.previewImageTemplate=e.previewImageTemplate,n.previewTextTemplate=e.previewTextTemplate,n.previewOtherTemplate=e.previewOtherTemplate,n.captionTemplate=e.captionTemplate,n.browseLabel=e.browseLabel,n.browseIcon=e.browseIcon,n.browseClass=e.browseClass,n.removeLabel=e.removeLabel,n.removeIcon=e.removeIcon,n.removeClass=e.removeClass,n.uploadLabel=e.uploadLabel,n.uploadIcon=e.uploadIcon,n.uploadClass=e.uploadClass,n.uploadUrl=e.uploadUrl,n.msgLoading=e.msgLoading,n.msgProgress=e.msgProgress,n.msgSelected=e.msgSelected,n.previewFileType=e.previewFileType,n.wrapTextLength=e.wrapTextLength,n.wrapIndicator=e.wrapIndicator,n.isError=!1,n.isDisabled=n.$element.attr("disabled")||n.$element.attr("readonly"),p(n.$element.attr("id"))&&n.$element.attr("id",u()),"undefined"==typeof n.$container?n.$container=n.createContainer():n.refreshContainer(),n.$captionContainer=c(e,"elCaptionContainer",n.$container.find(".file-caption")),n.$caption=c(e,"elCaptionText",n.$container.find(".file-caption-name")),n.$previewContainer=c(e,"elPreviewContainer",n.$container.find(".file-preview")),n.$preview=c(e,"elPreviewImage",n.$container.find(".file-preview-thumbnails")),n.$previewStatus=c(e,"elPreviewStatus",n.$container.find(".file-preview-status")),n.initPreview(),n.original={preview:n.$preview.html(),caption:n.$caption.html()},n.options=e,n.$element.removeClass("file-loading")},listen:function(){var i=this;i.$element.on("change",e.proxy(i.change,i)),i.$element.on("focus",function(e){e.preventDefault(),i.$captionContainer.focus()}),e(i.$element[0].form).on("reset",e.proxy(i.reset,i)),i.$container.on("click",".fileinput-remove:not([disabled])",e.proxy(i.clear,i))},refresh:function(i){var t=this,n=arguments.length?e.extend(t.options,i):t.options;t.init(n)},initPreview:function(){var e=this,i="",t=e.initialPreview,n=d(t)?t.length:t.length>0?t.split(e.initialDelimiter).length:0,a=e.initialCaption.length,r="preview-"+u(),l=a>0?e.initialCaption:e.msgSelected.replace("{n}",n);if(d(t)&&n>0){for(var o=0;n>o;o++)r+="-"+o,i+=e.previewGenericTemplate.replace("{previewId}",r).replace("{content}",t[o]);n>1&&0==a&&(l=e.msgSelected.replace("{n}",n))}else{if(!(n>0))return a>0?(e.$caption.html(l),void e.$captionContainer.attr("title",l)):void 0;for(var s=t.split(e.initialDelimiter),o=0;n>o;o++)r+="-"+o,i+=e.previewGenericTemplate.replace("{previewId}",r).replace("{content}",s[o]);n>1&&0==a&&(l=e.msgSelected.replace("{n}",n))}e.initialPreviewCount=n,e.initialPreviewContent=i,e.$preview.html(i),e.$caption.html(l),e.$captionContainer.attr("title",l),e.$container.removeClass("file-input-new")},clear:function(e){var i=this;if(e&&e.preventDefault(),i.reader instanceof FileReader&&i.reader.abort(),i.$element.val(""),i.resetErrors(!0),e!==!1&&(i.$element.trigger("change"),i.$element.trigger("fileclear")),i.overwriteInitial||p(i.initialPreviewContent)){i.$preview.html("");var t=!i.overwriteInitial&&i.initialCaption.length>0?i.original.caption:"";i.$caption.html(t),i.$captionContainer.attr("title",""),i.$container.removeClass("file-input-new").addClass("file-input-new")}else i.$preview.html(i.original.preview),i.$caption.html(i.original.caption),i.$container.removeClass("file-input-new");i.hideFileIcon(),i.$element.trigger("filecleared"),i.$captionContainer.focus()},reset:function(){var e=this;e.clear(!1),e.$preview.html(e.original.preview),e.$caption.html(e.original.caption),e.$container.find(".fileinput-filename").text(""),e.$element.trigger("filereset"),e.initialPreview.length>0&&e.$container.removeClass("file-input-new")},disable:function(){var e=this;e.isDisabled=!0,e.$element.attr("disabled","disabled"),e.$container.find(".kv-fileinput-caption").addClass("file-caption-disabled"),e.$container.find(".btn-file, .fileinput-remove, .kv-fileinput-upload").attr("disabled",!0)},enable:function(){var e=this;e.isDisabled=!1,e.$element.removeAttr("disabled"),e.$container.find(".kv-fileinput-caption").removeClass("file-caption-disabled"),e.$container.find(".btn-file, .fileinput-remove, .kv-fileinput-upload").removeAttr("disabled")},hideFileIcon:function(){this.overwriteInitial&&this.$captionContainer.find(".kv-caption-icon").hide()},showFileIcon:function(){this.$captionContainer.find(".kv-caption-icon").show()},resetErrors:function(e){var i=this,t=i.$previewContainer.find(".kv-fileinput-error");e?t.fadeOut("slow"):t.remove()},showError:function(e,i,t){var n=this,a=n.$previewContainer.find(".kv-fileinput-error");return p(a.attr("class"))?n.$previewContainer.append('
'+e+"
"):a.html(e),a.hide(),a.fadeIn(800),n.$element.trigger("fileerror",[i,t]),n.$element.val(""),!0},errorHandler:function(e,i){var t=this;switch(e.target.error.code){case e.target.error.NOT_FOUND_ERR:t.addError(t.msgFileNotFound.replace("{name}",i));break;case e.target.error.NOT_READABLE_ERR:t.addError(t.msgFileNotReadable.replace("{name}",i));break;case e.target.error.ABORT_ERR:t.addError(t.msgFilePreviewAborted.replace("{name}",i));break;default:t.addError(t.msgFilePreviewError.replace("{name}",i))}},loadImage:function(i,t){var n=this,a=e(document.createElement("img"));a.attr({src:f.createObjectURL(i),"class":"file-preview-image",title:t,alt:t,onload:function(){f.revokeObjectURL(a.src)}}),a.width()>=n.$preview.width()&&a.attr({width:"100%",height:"auto"});var r=e(document.createElement("div")).append(a);return r.html()},readFiles:function(e){function i(h){if(h>=e.length)return o.removeClass("loading"),void s.html("");g+="-"+h;var b=e[h],C=b.name,$=m(b.type,b.name),F=v(b.type,b.name),T=(b.size?b.size:0)/1e3;if(T=T.toFixed(2),t.maxFileSize>0&&T>t.maxFileSize){var y=t.msgSizeTooLarge.replace("{name}",C).replace("{size}",T).replace("{maxSize}",t.maxFileSize);return void(t.isError=t.showError(y,b,g))}a.length>0&&("any"==c?$||F:"text"==c?F:$)&&"undefined"!=typeof FileReader?(s.html(p),o.addClass("loading"),l.onerror=function(e){t.errorHandler(e,C)},l.onload=function(e){var i="",n="";if(F){var l=e.target.result;if(l.length>w){var o=u(),s=.75*window.innerHeight,n=r.replace("{id}",o).replace("{title}",C).replace("{body}",l).replace("{height}",s);f=f.replace("{title}",C).replace("{dialog}","$('#"+o+"').modal('show')"),l=l.substring(0,w-1)+f}i=t.previewTextTemplate.replace("{previewId}",g).replace("{caption}",C).replace("{strText}",l)+n}else i=t.previewImageTemplate.replace("{previewId}",g).replace("{content}",t.loadImage(b,C));a.append("\n"+i)},l.onloadend=function(){setTimeout(i(h+1),1e3),n.trigger("fileloaded",[b,g])},l.onprogress=function(e){if(e.lengthComputable){var i=parseInt(e.loaded/e.total*100,10),t=d.replace("{percent}",i).replace("{file}",b.name);s.html(t)}},F?l.readAsText(b):l.readAsBinaryString(b)):(a.append("\n"+t.previewOtherTemplate.replace("{previewId}",g).replace("{caption}",C)),n.trigger("fileloaded",[b,g]),setTimeout(i(h+1),1e3))}this.reader=new FileReader;var t=this,n=t.$element,a=t.$preview,l=t.reader,o=t.$previewContainer,s=t.$previewStatus,p=t.msgLoading,d=t.msgProgress,c=(t.msgSelected,t.previewFileType),w=parseInt(t.wrapTextLength),f=t.wrapIndicator,g="preview-"+u();i(0)},change:function(e){var i,t=this,n=t.$element,a=n.val().replace(/\\/g,"/").replace(/.*\//,""),r=0,l=t.$preview,o=n.get(0).files,s=t.msgSelected,d=p(o)?1:o.length+t.initialPreviewCount;if(t.hideFileIcon(),i=void 0===e.target.files?e.target&&e.target.value?[{name:e.target.value.replace(/^.+\\/,"")}]:[]:e.target.files,0!==i.length){t.resetErrors(),l.html(""),t.overwriteInitial||l.html(t.initialPreviewContent);var r=i.length;if(t.maxFilesCount>0&&r>t.maxFilesCount){var c=t.msgFilesTooMany.replace("{m}",t.maxFilesCount).replace("{n}",r);return t.isError=t.showError(c,null,null),void t.$container.removeClass("file-input-new")}t.showFileIcon(),t.readFiles(o),t.reader=null;var m=d>1?s.replace("{n}",d):a;t.isError&&(m=d>1?s.replace("{n}",d-1):" "),t.$caption.html(m),t.$captionContainer.attr("title",m),t.$container.removeClass("file-input-new"),n.trigger("fileselect",[d,a])}},initBrowse:function(e){var i=this;i.$btnFile=e.find(".btn-file"),i.$btnFile.append(i.$element)},createContainer:function(){var i=this,t=e(document.createElement("div")).attr({"class":"file-input file-input-new"}).html(i.renderMain());return i.$element.before(t),i.initBrowse(t),t},refreshContainer:function(){var e=this,i=e.$container;i.before(e.$element),i.html(e.renderMain()),e.initBrowse(i)},renderMain:function(){var e=this,i=e.previewTemplate.replace("{class}",e.previewClass),t=e.isDisabled?e.captionClass+" file-caption-disabled":e.captionClass,n=e.captionTemplate.replace("{class}",t+" kv-fileinput-caption");return e.mainTemplate.replace("{class}",e.mainClass).replace("{preview}",i).replace("{caption}",n).replace("{upload}",e.renderUpload()).replace("{remove}",e.renderRemove()).replace("{browse}",e.renderBrowse())},renderBrowse:function(){var e=this,i=e.browseClass+" btn-file",t="";return e.isDisabled&&(t=" disabled "),'
"+e.browseIcon+e.browseLabel+"
"},renderRemove:function(){var e=this,i=e.removeClass+" fileinput-remove fileinput-remove-button",t="";return e.showRemove?(e.isDisabled&&(t=" disabled "),'"):""},renderUpload:function(){var e=this,i=e.uploadClass+" kv-fileinput-upload",t="",n="";return e.showUpload?(e.isDisabled&&(n=" disabled "),t=p(e.uploadUrl)?'":'"+e.uploadIcon+e.uploadLabel+""):""}},e.fn.fileinput=function(i){return this.each(function(){var t=e(this),n=t.data("fileinput");n||t.data("fileinput",n=new g(this,i)),"string"==typeof i&&n[i]()})},e.fn.fileinput=function(i){var t=Array.apply(null,arguments);return t.shift(),this.each(function(){var n=e(this),a=n.data("fileinput"),r="object"==typeof i&&i;a||n.data("fileinput",a=new g(this,e.extend({},e.fn.fileinput.defaults,r,e(this).data()))),"string"==typeof i&&a[i].apply(a,t)})},e.fn.fileinput.defaults={showCaption:!0,showPreview:!0,showRemove:!0,showUpload:!0,captionClass:"",previewClass:"",mainClass:"",mainTemplate:null,initialDelimiter:"*$$*",initialPreview:"",initialCaption:"",initialPreviewCount:0,initialPreviewContent:"",overwriteInitial:!0,previewTemplate:n,previewGenericTemplate:l,previewImageTemplate:l,previewTextTemplate:o,previewOtherTemplate:s,captionTemplate:a,browseLabel:"Browse …",browseIcon:'  ',browseClass:"btn btn-primary",removeLabel:"Remove",removeIcon:' ',removeClass:"btn btn-default",uploadLabel:"Upload",uploadIcon:' ',uploadClass:"btn btn-default",uploadUrl:null,maxFileSize:0,maxFilesCount:0,msgSizeTooLarge:'File "{name}" ({size} KB) exceeds maximum allowed upload size of {maxSize} KB. Please retry your upload!',msgFilesTooMany:"Number of files selected for upload ({n}) exceeds maximum allowed limit of {m}. Please retry your upload!",msgFileNotFound:'File "{name}" not found!',msgFileNotReadable:'File "{name}" is not readable.',msgFilePreviewAborted:'File preview aborted for "{name}".',msgFilePreviewError:'An error occurred while reading the file "{name}".',msgErrorClass:"file-error-message",msgLoading:"Loading …",msgProgress:"Loaded {percent}% of {file}",msgSelected:"{n} files selected",previewFileType:"image",wrapTextLength:250,wrapIndicator:' […]',elCaptionContainer:null,elCaptionText:null,elPreviewContainer:null,elPreviewImage:null,elPreviewStatus:null},e(document).ready(function(){var i=e("input.file[type=file]"),t=Object.keys(i).length;t>0&&i.fileinput()})}(window.jQuery);