var editor,creator;function resetCheckedbox(){$("#checkedAll:checked").prop("checked",false);$('#tbody-content input[type=checkbox][name="path[]"]:checked').prop("checked",false)}function refreshList(){if($("#tbody-content").length<1){window.location.reload();return}App.loading("show");$.get(window.location.href,{_pjax:"tbody-content"},function(e){var t=$(e);$("#tbody-content").html(t.find("#tbody-content").html());App.float("#tbody-content img.previewable");App.loading("hide");$("#tbody-content").trigger("refresh");resetCheckedbox()},"html")}function initCodeMirrorEditor(){var o={lineNumbers:true,lineWrapping:true,foldGutter:true,gutters:["CodeMirror-linenumbers","CodeMirror-foldgutter"],autoCloseTags:true,autoCloseBrackets:true,showTrailingSpace:true,indentWithTabs:true,matchBrackets:true,styleActiveLine:true,styleSelectedText:true,highlightSelectionMatches:true,smartIndent:true,theme:"ambiance",extraKeys:{F11:function(e){e.setOption("fullScreen",!e.getOption("fullScreen"))},Esc:function(e){if(e.getOption("fullScreen"))e.setOption("fullScreen",false)}},hintOptions:{completeSingle:false}},e=function(e){var t=CodeMirror.fromTextArea(e,o);t.setSize("auto","100%");t.on("keypress",function(){if(typeof t.showHint=="function")t.showHint()});return t};editor=e($("#file-edit-content")[0]);$("#file-edit-modal .modal-footer .btn-success").on("click",function(){var e=$(this).data("url");var t=$("#use-encoding-open").val();if(!t)t="";$.post(e,{content:editor.getValue(),encoding:t},function(e){if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);return App.message({title:App.i18n.SYS_INFO,text:App.i18n.SAVE_SUCCEED},false)},"json")});if($("#file-create-content").length>0){creator=e($("#file-create-content")[0]);$("#file-create-name").on("change",function(){var e=$(this).val();codeMirrorChangeMode(creator,e);creator.refresh()})}$("#file-create-modal .modal-footer .btn-primary:last").on("click",function(e){var t=$(this).data("url"),o=$("#use-encoding-save").val(),i=$.trim($("#file-create-name").val());if(!i){App.message({text:App.t("请输入文件名"),type:"error"});$("#file-create-name").focus();return}if(!o)o="";$.post(t,{content:creator.getValue(),encoding:o,name:i},function(e){if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);App.message({title:App.i18n.SYS_INFO,text:App.i18n.SAVE_SUCCEED},false);$("#file-create-modal").niftyModal("hide");refreshList()},"json")});$("#file-edit-modal .modal-body").css("padding",0);$("#use-encoding-open").on("change",function(){var e=$(this).val();fileReopen(e)});$("#file-edit-modal .modal-footer .btn-reload").on("click",function(){$("#use-encoding-open").trigger("change")})}function fileReopen(e,t){App.loading("show");if(t==null)t=$("#file-edit-modal .modal-footer .btn-success").data("url");$.get(t,{encoding:e},function(e){App.loading("hide");if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);editor.setValue(e.Data)},"json")}function fileEdit(e,o){var t=$(e).data("url");$("#file-edit-modal .modal-footer .btn-success").data("url",t);App.loading("show");$.get(t,{},function(t){App.loading("hide");if(t.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:t.Info},false);$("#file-edit-modal .modal-header h3").html(App.i18n.EDIT_FILE+": "+o);$("#file-edit-modal").niftyModal("show",{afterOpen:function(e){editor.setValue(t.Data);codeMirrorChangeMode(editor,o);editor.refresh()},afterClose:function(e){$("#use-encoding-open").find("option:selected").prop("selected",false)}})},"json")}function fileCreate(e){var t=$(e).data("url");$("#file-create-modal .modal-footer .btn-primary:last").data("url",t);$("#file-create-modal .modal-header h3").html(App.i18n.CREATE_FILE);$("#file-create-modal").niftyModal("show",{afterOpen:function(e){$("#file-create-name").val("");creator.setValue("");creator.refresh();setTimeout(function(){$("#file-create-name").focus()},500)},afterClose:function(e){$("#use-encoding-save").find("option:selected").prop("selected",false)}})}function fileRename(e,t,o){var i=$(e).data("url");$("#file-rename-modal .modal-footer .btn-primary:last").data("url",i);$("#file-rename-modal .modal-header h3").html((o?App.i18n.MODIFY_DIRNAME:App.i18n.MODIFY_FILENAME)+": "+t);$("#file-rename-modal").niftyModal("show",{afterOpen:function(e){$("#file-rename-input").val(t);setTimeout(function(){$("#file-rename-input").focus()},500)}})}function fileChmod(e,t,n){var o=$(e).data("url");$("#file-chmod-modal .modal-footer .btn-primary:last").data("url",o);$("#file-chmod-modal .modal-header h3").html(App.i18n.MODIFY_PERM+": "+t);$("#file-chmod-modal").niftyModal("show",{afterOpen:function(e){var t=$("#file-chmod-form");for(var o in n){for(var i in n[o]){t.find('input[name="'+o+"["+i+']"]').prop("checked",n[o][i])}}}})}function fileMkdir(e){var t=$(e).data("url");$("#file-mkdir-modal .modal-footer .btn-primary:last").data("url",t);$("#file-mkdir-modal .modal-header h3").html(App.i18n.CREATE_DIR);$("#file-mkdir-modal").niftyModal("show",{afterOpen:function(e){$("#file-mkdir-input").val("");setTimeout(function(){$("#file-mkdir-input").focus()},500)}})}function filePlay(e,t){if(t==null)t="a[playable]";var o=$(e).data("url"),i=$(t).index($(e)),n=$(e).data("name"),r=$(e).data("mime"),a,l="file-play-video",d=$("#file-play-modal .modal-header h3");d.html(App.i18n.PLAY+": "+n);var f=$("#file-play-modal .modal-body");f.css({padding:"0","text-align":"center"});$(e).css({color:"yellow"});$("#file-play-modal").niftyModal("show",{afterOpen:function(e){$("#file-play-video source").attr("src",o).attr("type",r);$(window).trigger("resize");a=videojs(l,null,function(){this.on("ended",function(){i++;if(i>=$(t).length)i=0;var e=$(t).eq(i);e.css({color:"yellow"});this.src({type:e.data("mime"),src:e.data("url")});this.play();d.html(App.i18n.PLAY+": "+e.data("name"))})});a.play()},afterClose:function(){if(!a)return;var e=$('<video-js id="file-play-video" class="vjs-default-skin" width=500 height=500 controls><source src="" type=""></video-js>');a.dispose();a=null;f.html(e)}})}function codeMirrorChangeMode(e,t){var o,i,n;if(o=/.+\.([^.]+)$/.exec(t)){var r=CodeMirror.findModeByExtension(o[1]);if(r){i=r.mode;n=r.mime}}else if(/\//.test(t)){var r=CodeMirror.findModeByMIME(t);if(r){i=r.mode;n=t}}else{i=n=t}if(i){e.setOption("mode",n)}else{console.log("Could not find a mode corresponding to "+t)}}Dropzone.autoDiscover=false;CodeMirror.modeURL=ASSETS_URL+"/js/editor/markdown/lib/codemirror/mode/%N/%N.js";$(function(){var o={timeout:216e5,chunking:true,parallelChunkUploads:typeof PARALLEL_CHUNK_UPLOADS!="undefined"&&PARALLEL_CHUNK_UPLOADS?true:false,parallelUploads:typeof PARALLEL_UPLOADS_LIMIT=="number"&&PARALLEL_UPLOADS_LIMIT>0?PARALLEL_UPLOADS_LIMIT:1,retryChunksLimit:3,retryChunks:true,chunkSize:typeof MAX_REQUEST_BYTES=="number"&&MAX_REQUEST_BYTES>0?MAX_REQUEST_BYTES:2e6,maxFilesize:typeof UPLOAD_FILE_MAX_BYTES=="number"&&UPLOAD_FILE_MAX_BYTES>0?UPLOAD_FILE_MAX_BYTES*1024*1024:1024};var n=function(e){e=$.extend({},o,e||{});var t=o.chunkSize/1024/1024;if(t>e.maxFilesize)e.maxFilesize=t;return e};if(typeof initDropzone=="function")initDropzone(n(window.dropzoneOptions));$("#uploadBtn").attr("dropzone-container","#multi-upload-dropzone").attr("dropzone-modal","#multi-upload-modal");if($("#uploadZipBtn").length>0){$("#uploadZipBtn").attr("dropzone-container","#multi-upload-zip-dropzone").attr("dropzone-modal","#multi-upload-zip-modal")}var r=[];$("[dropzone-container]").each(function(){var e=$(this).attr("dropzone-container");if(!e)return;if($(e).length<1)return;var t=$(e).get(0).dropzone;if(!t){var o=$(this).attr("dropzone-options");if(o&&typeof o=="string")o=JSON.parse(o);App.editor.dropzone(e,n(o));t=$(e).get(0).dropzone}var i=$(this).attr("dropzone-modal");if(!i)return;$(this).on("click",function(e){$(i).niftyModal("show",{closeOnClickOverlay:false,afterClose:function(e){t.removeAllFiles();refreshList()}})});r.push(i)});initCodeMirrorEditor();$(window).off().on("resize",function(){$("#file-edit-form,#file-play-video").css({height:$(window).height()-150,width:"100%","max-width":"100%",overflow:"auto"});$("#file-create-form").css({height:$(window).height()-180,width:"100%","max-width":"100%",overflow:"auto"});$("#file-play-video > video").css({height:"100%"})});$(window).trigger("resize");$("#file-rename-modal .modal-footer .btn-primary:last").off().on("click",function(){var e=$(this).data("url");App.loading("show");$.post(e,{name:$("#file-rename-input").val()},function(e){App.loading("hide");if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);App.message({title:App.i18n.SYS_INFO,text:App.i18n.SAVE_SUCCEED},false);refreshList()},"json")});$("#file-chmod-modal .modal-footer .btn-primary:last").off().on("click",function(){var e=$(this).data("url");App.loading("show");var t=$("#file-chmod-form").serializeArray();$.post(e,t,function(e){App.loading("hide");if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);App.message({title:App.i18n.SYS_INFO,text:App.i18n.SAVE_SUCCEED},false);refreshList()},"json")});$("#file-mkdir-modal .modal-footer .btn-primary:last").off().on("click",function(){var e=$(this).data("url");App.loading("show");$.post(e,{name:$("#file-mkdir-input").val()},function(e){App.loading("hide");if(e.Code!=1)return App.message({title:App.i18n.SYS_INFO,text:e.Info},false);App.message({title:App.i18n.SYS_INFO,text:App.i18n.CREATE_SUCCEED},false);refreshList()},"json")});$("#query-current-path").on("keyup",function(e){var t=$(this).val();if(t==""){$("#tbody-content").children("tr:not(:visible)").show();var o=$('#tbody-content input[type=checkbox][name="path[]"]:disabled');if(o.length>0)$("#checkedAll").prop("checked",false);o.prop("disabled",false);return}$("#tbody-content").children('tr:not([item*="'+t+'"])').hide().find('input[type=checkbox][name="path[]"]').prop("disabled",true);$("#tbody-content").children('tr[item*="'+t+'"]:not(:visible)').show().find('input[type=checkbox][name="path[]"]:disabled').prop("disabled",false);$('#tbody-content input[type=checkbox][name="path[]"]:disabled:checked').prop("checked",false);$("#checkedAll").prop("checked",$('#tbody-content tr[item]:visible input[type=checkbox][name="path[]"]:checked').length==$('#tbody-content tr[item]:visible input[type=checkbox][name="path[]"]'));if(e.keyCode==13){var i=$("#tbody-content").children("tr:visible");if(i.length==1){var n=i.children("td:first").children("a:first");var r=n.attr("href");window.location=r;return}}}).focus();$("#btn-query-current-path").on("click",function(){$("#query-current-path").trigger("keyup")});App.float("#tbody-content img.previewable");resetCheckedbox();App.attachCheckedAll("#checkedAll",'#tbody-content input[type=checkbox][name="path[]"]')});