/*!
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014
* @version 2.0.0
* bootstrap-fileinput
* For more JQuery Plugins visit http://plugins.krajee.com
*/!function(e){var i='{preview}\n
',t="{preview}\n{remove}\n{upload}\n{browse}\n",n='',a='',l='\n',r='\n {content}\n
\n',o='\n',s='',p=function(i,t){return null===i||void 0===i||i==[]||""===i||t&&""===e.trim(i)},c=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},d=function(i,t,n){return p(i)||p(i[t])?n:e(i[t])},v=function(e,i){return"undefined"!=typeof e?e.match("image.*"):i.match(/\.(gif|png|jpe?g)$/i)},m=function(e,i){return"undefined"!=typeof e?e.match("text.*"):i.match(/\.(txt|md|csv|htm|html|php|ini)$/i)},f=function(){return Math.round((new Date).getTime()+100*Math.random())},u=function(i,t){this.$element=e(i),this.init(t),this.listen()};u.prototype={constructor:u,init:function(e){var n=this;n.showCaption=e.showCaption,n.showPreview=e.showPreview,n.maxFileSize=e.maxFileSize,n.msgSizeTooLarge=e.msgSizeTooLarge,n.msgErrorClass=e.msgErrorClass,n.initialDelimiter=e.initialDelimiter,n.initialPreview=e.initialPreview,n.initialCaption=e.initialCaption,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.isDisabled=n.$element.attr("disabled")||n.$element.attr("readonly"),p(n.$element.attr("id"))&&n.$element.attr("id",f()),"undefined"==typeof n.$container?n.$container=n.createContainer():n.refreshContainer(),n.$captionContainer=d(e,"elCaptionContainer",n.$container.find(".file-caption")),n.$caption=d(e,"elCaptionText",n.$container.find(".file-caption-name")),n.$previewContainer=d(e,"elPreviewContainer",n.$container.find(".file-preview")),n.$preview=d(e,"elPreviewImage",n.$container.find(".file-preview-thumbnails")),n.$previewStatus=d(e,"elPreviewStatus",n.$container.find(".file-preview-status")),n.initPreview(),n.original={preview:n.$preview.html(),caption:n.$caption.html()},this.options=e,n.$element.removeClass("file-loading")},listen:function(){var i=this;i.$element.on("change",e.proxy(i.change,i)),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=c(t)?t.length:t.length>0?t.split(e.initialDelimiter).length:0,a=e.initialCaption.length,l="preview-"+f(),r=a>0?e.initialCaption:e.msgSelected.replace("{n}",n);if(c(t)&&n>0){for(var o=0;n>o;o++)l+="-"+o,i+=e.previewGenericTemplate.replace("{previewId}",l).replace("{content}",t[o]);n>1&&0==a&&(r=e.msgSelected.replace("{n}",n))}else{if(!(n>0))return a>0?(e.$caption.html(r),e.$captionContainer.attr("title",r),void e.$captionContainer.find(".kv-caption-icon").show()):void 0;for(var s=t.split(e.initialDelimiter),o=0;n>o;o++)l+="-"+o,i+=e.previewGenericTemplate.replace("{previewId}",l).replace("{content}",s[o]);n>1&&0==a&&(r=e.msgSelected.replace("{n}",n))}e.initialNbPreview=n,e.initialPreviewContent=i,e.$preview.html(i),e.$caption.html(r),e.$captionContainer.attr("title",r),e.$container.removeClass("file-input-new")},clear:function(e){var i=this;if(e&&e.preventDefault(),i.$element.val(""),i.$previewContainer.find(".kv-fileinput-error").fadeOut("slow"),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.overwriteInitial&&i.$captionContainer.find(".kv-caption-icon").hide(),i.$element.trigger("filecleared")},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")},change:function(e){var i,t=this,n=t.$element,a=n.get(0).files,r=a?a.length+t.initialNbPreview:1,o=n.val().replace(/\\/g,"/").replace(/.*\//,""),s=t.$preview,p=t.$previewContainer,c=t.$previewStatus,d=t.msgLoading,u=t.msgProgress,w=t.msgSelected,h=t.previewFileType,g=parseInt(t.wrapTextLength),b=t.wrapIndicator,C="preview-"+f(),$=!1;if(i=void 0===e.target.files?e.target&&e.target.value?[{name:e.target.value.replace(/^.+\\/,"")}]:[]:e.target.files,0!==i.length){s.html(""),t.overwriteInitial||s.html(t.initialPreviewContent);for(var y=i.length,T=0;y>T;T++)!function(e){C+="-"+T;var i=e.name,a=v(e.type,e.name),r=m(e.type,e.name),o=(e.size?e.size:0)/1e3;if(o=o.toFixed(2),t.$previewContainer.find(".kv-fileinput-error").remove(),t.maxFileSize>0&&o>t.maxFileSize){var w=t.msgSizeTooLarge.replace("{name}",i).replace("{size}",o).replace("{maxSize}",t.maxFileSize),x=''+w+"
";t.$element.val(""),t.$previewContainer.append(x);var I=t.$previewContainer.find(".kv-fileinput-error");return I.hide(),I.fadeIn(800),t.$element.trigger("fileerror",[e,C]),void($=!0)}if(s.length>0&&("any"==h?a||r:"text"==h?r:a)&&"undefined"!=typeof FileReader){var P=new FileReader;c.html(d),p.addClass("loading"),P.onload=function(a){var o="",d="";if(r){var v=a.target.result;if(v.length>g){var m=f(),u=.75*window.innerHeight,d=l.replace("{id}",m).replace("{title}",i).replace("{body}",v).replace("{height}",u);b=b.replace("{title}",i).replace("{dialog}","$('#"+m+"').modal('show')"),v=v.substring(0,g-1)+b}o=t.previewTextTemplate.replace("{previewId}",C).replace("{caption}",i).replace("{strText}",v)+d}else o=t.previewImageTemplate.replace("{previewId}",C).replace("{content}",'
');s.append("\n"+o);var w=s.find("#"+C+" img");w.width()>s.width()&&(w.width("100%"),w.height("auto")),T>=y-1&&(p.removeClass("loading"),c.html("")),n.trigger("fileloaded",[e,C])},P.onprogress=function(i){if(i.lengthComputable){var t=parseInt(i.loaded/i.total*100,10),n=u.replace("{percent}",t).replace("{file}",e.name);c.html(n)}},r?P.readAsText(e):P.readAsDataURL(e)}else s.append("\n"+t.previewOtherTemplate.replace("{previewId}",C).replace("{caption}",i)),n.trigger("fileloaded",[e,C])}(i[T]);var x=r>1?w.replace("{n}",r):o;$&&(x=r>1?w.replace("{n}",r-1):" "),t.$caption.html(x),t.$captionContainer.attr("title",x),t.$container.removeClass("file-input-new"),n.trigger("fileselect",[r,o])}},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),t.find(".btn-file").append(i.$element),t},refreshContainer:function(){var e=this;e.$container.before(e.$element),e.$container.html(e.renderMain()),e.$container.find(".btn-file").append(e.$element)},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 u(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"),l="object"==typeof i&&i;a||n.data("fileinput",a=new u(this,e.extend({},e.fn.fileinput.defaults,l,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:"",initialNbPreview:0,initialPreviewContent:"",overwriteInitial:!0,previewTemplate:n,previewGenericTemplate:r,previewImageTemplate:r,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,msgSizeTooLarge:'File "{name}" ({size} KB) exceeds maximum allowed upload size of {maxSize} KB. Please retry your upload!',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);