!function(a){"use strict";var b={autoUpload:!0,dataType:"json",sequentialUploads:!0,dropZone:".xefu-dropzone",fileList:".xefu-list",controll:".xefu-controll",filelist:".xefu-list-files ul",filelistImages:".xefu-list-images ul",progressbar:".xefu-progressbar",progressbarGraph:".xefu-progressbar div",progressStatus:".xefu-progress-status",progressPercent:".xefu-progress-percent",actSelectedInsertContent:".xefu-act-link-selected",actSelectedDeleteFile:".xefu-act-delete-selected",actDeleteFile:".xefu-act-delete",actSetCover:".xefu-act-set-cover",tmplXeUploaderFileitem:'
  • {{source_filename}}{{disp_file_size}} 선택
  • ',tmplXeUploaderFileitemImage:'
  • {{source_filename}}{{disp_file_size}}
  • '},c=["fileList","actSelectedInsertContent","actSelectedDeleteFile","actDeleteFile","actSetCover","controll","dropZone","filelist","filelistImages","progressbar","progressbarGraph","progressPercent","progressStatus"],d=xe.createApp("XeUploader",{settings:{},init:function(){},deactivate:function(){},createInstance:function(d,e){var f=this,g=d,h=g.data();a.extend(h,{files:{},selected_files:{},settings:{},last_selected_file:null});var i=window.enforce_ssl;"https:"==location.protocol&&(window.enforce_ssl=!0);var j={url:request_uri.setQuery("module","file").setQuery("act","procFileUpload").setQuery("mid",window.current_mid),formData:{editor_sequence:h.editorSequence,upload_target_srl:h.uploadTargetSrl,mid:window.current_mid,act:"procFileUpload"},dropZone:g,add:function(b,c){var d=jQuery.Deferred();a.each(c.files,function(a,b){if(h.settings.maxFileSize<=b.size)return d.reject(),alert(window.xe.msg_exceeds_limit_size),!1;d.resolve()}),d.done(function(){c.submit()})},done:function(a,b){var c=b.response().result,d="";c&&(jQuery.isPlainObject(c)||(c=jQuery.parseJSON(c)),c&&(0==c.error?(/\.(jpe?g|png|gif)$/i.test(c.source_filename)&&(d+=''+c.source_filename+'',d+="\r\n


    \r\n"),_getCkeInstance(j.formData.editor_sequence).insertHtml(d,"unfiltered_html")):alert(c.message)))},stop:function(){f.loadFilelist(g)},start:function(){h.settings.progressbarGraph.width(0),h.settings.progressStatus.show(),h.settings.progressbar.show()},progressall:function(a,b){var c=parseInt(b.loaded/b.total*100,10);h.settings.progressbarGraph.width(c+"%"),h.settings.progressPercent.text(c+"%"),c>=100&&(h.settings.progressbar.delay(3e3).slideUp(),h.settings.progressStatus.delay(3e3).slideUp())}};window.enforce_ssl=i,h.settings=a.extend({},b,j,e||{}),g.data(h),a.each(c,function(a,b){"string"==typeof h.settings[b]&&(h.settings[b]=g.find(h.settings[b]))});g.fileupload(h.settings).prop("disabled",!a.support.fileInput).parent().addClass(a.support.fileInput?void 0:"disabled");g.data("xefu-instance",this),this.loadFilelist(g),h.settings.actSelectedInsertContent.on("click",function(){f.insertToContent(g)}),h.settings.actSelectedDeleteFile.on("click",function(){f.deleteFile(g)});var k=h.settings.fileList.finderSelect({children:"li",enableDesktopCtrlDefault:!0});h.settings.fileList.on("mousedown","img",function(a){a.preventDefault()}),k.finderSelect("addHook","highlight:after",function(a){a.find("input").prop("checked",!0);var b=h.settings.fileList.find("input:checked");h.selected_files=b}),k.finderSelect("addHook","unHighlight:after",function(a){a.find("input").prop("checked",!1);var b=h.settings.fileList.find("input:checked");h.selected_files=b}),k.on("click",":checkbox",function(a){a.preventDefault()}),k.on("click",".xefu-act-set-cover",function(a){a.preventDefault(),f.setCover(g,a.currentTarget)}),a(document).bind("dragover",function(a){var b=window.dropZoneTimeout,c=h.settings.dropZone;b?clearTimeout(b):c.addClass("in");var d=!1,e=a.target;do{if(e===c[0]){d=!0;break}e=e.parentNode}while(null!=e);d?c.addClass("hover"):c.removeClass("hover"),window.dropZoneTimeout=setTimeout(function(){window.dropZoneTimeout=null,c.removeClass("in hover")},100)}),g.data(h)},done:function(){},selectAllFiles:function(){},selectImageFiles:function(){},selectNonImageFiles:function(){},unselectAllFiles:function(){},unselectImageFiles:function(){},unselectNonImageFiles:function(){},insertToContent:function(b){var c="",d=b.data();a.each(d.selected_files,function(b,e){var f=a(e).data().fileSrl,g=d.files[f];g&&(/\.(jpe?g|png|gif)$/i.test(g.download_url)?(-1!=g.download_url.indexOf("http://")||-1!=g.download_url.indexOf("https://")?c+=''+g.source_filename+'':c+=''+g.source_filename+'',c+="\r\n


    \r\n"):c+=''+g.source_filename+"\n")}),_getCkeInstance(d.editorSequence).insertHtml(c,"unfiltered_html")},deleteFile:function(b,c){var d=this,e=[],f=b.data(),g=_getCkeInstance(f.editorSequence).document.find("img");c?e.push(c):a.each(f.selected_files,function(b,c){if(c){var d=a(c).data().fileSrl;e.push(d)}}),e=e.join(","),exec_json("file.procFileDelete",{file_srls:e,editor_sequence:f.editorSequence},function(){e=e.split(","),a.each(e,function(a,b){f.settings.fileList.find("ul").find("li[data-file-srl="+b+"]").remove();for(var c=0;c<=g.count()-1;c++){var d=g.getItem(c);if(d.getAttribute("data-file-srl")==b){var e=d.getParent();console.debug("_deleteFile",e,e.getHtml(),e.getChildCount(),e.getChildren()),1===e.getChildCount()?e.remove():d.remove()}}}),d.loadFilelist(b)})},loadFilelist:function(b){var c=b.data(),d={};d.mid=window.current_mid,d.editor_sequence=c.editorSequence,a.exec_json("file.getFileList",d,function(d){c.uploadTargetSrl=d.upload_target_srl,editorRelKeys[c.editorSequence].primary.value=d.upload_target_srl,c.uploadTargetSrl=d.uploadTargetSrl,b.find(".allowed_filetypes").text(d.allowed_filetypes),b.find(".allowed_filesize").text(d.allowed_filesize),b.find(".allowed_attach_size").text(d.allowed_attach_size),b.find(".attached_size").text(d.attached_size),b.find(".file_count").text(d.files.length);var e=c.settings.tmplXeUploaderFileitem,f=c.settings.tmplXeUploaderFileitemImage,g=Handlebars.compile(e),h=Handlebars.compile(f),i=[],j=[];if(!d.files.length)return c.settings.fileList.hide(),void c.settings.controll.hide();a.each(d.files,function(a,d){c.files[d.file_srl]||(c.files[d.file_srl]=d,b.data(c),/\.(jpe?g|png|gif)$/i.test(d.source_filename)?i.push(h(d)):j.push(g(d)))}),c.settings.filelistImages.append(i.join("")),c.settings.filelist.append(j.join("")),c.settings.controll.show(),c.settings.fileList.show()})},setCover:function(b,c){var d=b.data(),e=a(c),f=e.data().fileSrl;exec_json("file.procFileSetCoverImage",{file_srl:f,mid:window.current_mid,editor_sequence:d.editorSequence},function(a){if(0==a.error){d.settings.filelistImages.find("li").removeClass("xefu-is-cover-image");var b=e.closest("li");"N"==a.is_cover?b.removeClass("xefu-is-cover-image"):"Y"==a.is_cover&&b.addClass("xefu-is-cover-image")}})}});a.fn.xeUploader=function(a){var b=new d;return b&&(xe.registerApp(b),b.createInstance(this.eq(0),a)),b}}(jQuery);