2019-01-02 16:43:11 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014-2019, b3log.org & hacpai.com
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2018-10-05 18:11:52 +03:00
|
|
|
var Tabs=function(e){e._$tabsPanel=$(e.id+" > .tabs-panel"),e._$tabs=$(e.id+" > .tabs"),e._stack=[],this.obj=e,this.obj.STACKSIZE=64,this._init(e);var i=this;$(e.id+" > .tabs > div").each(function(){var t=$(this).data("index");e._stack.length===i.obj.STACKSIZE&&e._stack.splice(0,1),e._stack[e._stack.length-1]!==t&&i.obj._stack.push(t)})};$.extend(Tabs.prototype,{_init:function(r){var n=this;r._$tabs.on("click","div",function(t){if($(this).hasClass("current"))return!1;var e=$(this).data("index");n.setCurrent(e),"function"==typeof r.clickAfter&&r.clickAfter(e)}),r._$tabs.on("click",".ico-close",function(t){var e=$(this).parent().data("index"),i=!0;"function"==typeof r.removeBefore&&(i=r.removeBefore(e)),i&&n.del(e),t.stopPropagation()})},_hasId:function(t){return 0!==this.obj._$tabs.find('div[data-index="'+t+'"]').length},add:function(t){if(this.getCurrentId()===t.id)return!1;if(this._hasId(t.id))return this.setCurrent(t.id),!1;var e=this.obj._$tabsPanel;this.obj._$tabs.append('<div data-index="'+t.id+'">'+t.title+' <span class="ico-close font-ico"></span></div>'),e.append('<div data-index="'+t.id+'">'+t.content+"</div>"),this.setCurrent(t.id),"function"==typeof t.after&&t.after()},del:function(t){var e,i=this.obj._$tabsPanel,r=this.obj._$tabs,n=this.obj._stack;r.children("div[data-index='"+t+"']").remove(),i.children("div[data-index='"+t+"']").remove();for(var a=0;a<n.length;a++)t===n[a]&&(n.splice(a,1),a--);e=n[n.length-1],"function"==typeof this.obj.removeAfter&&this.obj.removeAfter(t,e),this.setCurrent(e)},getCurrentId:function(){return this.obj._$tabs.children(".current").data("index")},setCurrent:function(t){if(!t)return!1;var e=this.obj._$tabsPanel,i=this.obj._$tabs;if(i.children(".current").data("index")===t)return!1;var r=this.obj._stack;r.length===this.obj.STACKSIZE&&r.splice(0,1),r[r.length-1]!==t&&this.obj._stack.push(t),i.children("div").removeClass("current"),e.children("div").hide(),i.children('div[data-index="'+t+'"]').addClass("current"),e.children('div[data-index="'+t+'"]').show(),"function"==typeof this.obj.setAfter&&this.obj.setAfter();var n=this.getCurrentId();if("startPage"!==n){var a=tree.getTIdByPath(n),s=tree.fileTree.getNodeByTId(a);tree.fileTree.selectNode(s),wide.curNode=s;for(var d=0,o=editors.data.length;d<o;d++)if(editors.data[d].id===n){wide.curEditor=editors.data[d].editor;break}if(wide.curEditor){var c=wide.curEditor.getCursor();wide.curEditor.setCursor(c),wide.curEditor.focus(),wide.refreshOutline(),$(".footer .cursor").text("| "+(c.line+1)+":"+(c.ch+1)+" |")}}}});
|
|
|
|
!function(p){p.fn.extend({dialog:{version:"0.0.1.7",author:"v@b3log.org"}});var t=(new Date).getTime(),n="dialog",e=function(){this._defaults={styleClass:{background:"dialog-background",panel:"dialog-panel",main:"dialog-main",footer:"dialog-footer",headerMiddle:"dialog-header-middle",headerBg:"dialog-header-bg",closeIcon:"dialog-close-icon",closeIconHover:"dialog-close-icon-hover",title:"dialog-title"}}};p.extend(e.prototype,{_attach:function(t,e){t.id||(this.uuid++,t.id="dp"+this.uuid);var i=this._newInst(p(t));i.settings=p.extend({},e||{}),p.data(t,n,i),this._init(t)},_newInst:function(t){return{id:t[0].id.replace(/([^A-Za-z0-9_])/g,"\\\\$1")}},_getInst:function(t){try{return p.data(t,n)}catch(t){throw"Missing instance data for this dialog"}},_destroyDialog:function(t){var e=p.dialog._getInst(t),i=e.id;p.removeData(t,n),p(t).prependTo("#"+i+"Wrap").unwrap(),p(t).removeAttr("style");var o=this._getDefaults(p.dialog._defaults,e.settings,"styleClass");p("."+o.background).remove(),p("#"+i+"Dialog").remove()},_init:function(t){var e=this._getInst(t),i=e.id,o=e.settings,n=p(window).height(),a=p(window).width(),l=this._getDefaults(p.dialog._defaults,o,"styleClass"),s=o.height?o.height:parseInt(.6*n),d=o.width?o.width:parseInt(.6*a);o.title=o.title?o.title:"",o.okText=o.okText?o.okText:"Ok",o.cancelText=o.cancelText?o.cancelText:"Cancel";var r="",c="<div class='"+l.headerBg+"'><div class='"+l.title+"'>"+o.title+"</div><a href='javascript:void(0);' class='ico-close font-ico "+l.closeIcon+"'></a></div>";o.hideFooter||(o.hiddenOk||(r="<button>"+o.okText+"</button>"),r+="<button>"+o.cancelText+"</button>");var h="<div id='"+i+"Dialog' class='"+l.panel+"' style='width: "+d+"px;' onselectstart='return false;'>"+c+"<div class='"+l.main+"'><div style='overflow: auto; height: "+s+"px;'></div><div class='"+l.footer+"'>"+r+"</div></div>",g="";o.modal&&0===p("."+l.background).length&&(g="<div style='height:"+(n<document.documentElement.scrollHeight?document.documentElement.scrollHeight:n)+"px;' class='"+l.background+"'></div>");p("#"+i).wrap("<div id='"+i+"Wrap'></div>");var u=p(t).clone(!0);p(t).remove(),p("body").append(g+h),p(p("#"+i+"Dialog ."+l.main+" div").get(0)).append(u),p(u).show(),p("#"+i+"Dialog ."+l.closeIcon).bind("click",function(){p.dialog._close(i,o)});var f=p("#"+i+"Dialog ."+l.footer+" button");p(f.get(1)).bind("click",function(){p.dialog._close(i,o)}),p(f.get(0)).bind("click",function(){(void 0===o.ok||o.ok())&&p.dialog._close(i,o)}),this._bindMove(i,l.headerBg,s,d),p(window).keyup(function(t){27===t.keyCode&&p.dialog._close(i,o)}),p(window).resize(function(){var t=p("body").height()>p(window).height()?p("body").height():p(window).height();p(".dialog-background").height(t)}),"function"==typeof o.afterInit&&o.afterInit()},_bindMove:function(i,t){p("#"+i+"Dialog ."+t).mousedown(function(t){var e=document;t||(t=window.event);var o=document.getElementById(i+"Dialog"),n=t.clientX-parseInt(o.style.left),a=t.clientY-parseInt(o.style.top);e.ondragstart="return false;",e.onselectstart="return false;",e.onselect="document.selection.empty();",this.setCapture?this.setCapture():window.captureEvents&&window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP),e.onmousemove=function(t){t||(t=window.event);var e=t.clientX-n,i=t.clientY-a;e<0&&(e=0),e>p(window).width()-p(o).width()&&(e=p(window).width()-p(o).width()),i>p(window).height()-p(o).height()&&(i=p(window).height()-p(o).height()),i<0&&(i=0),o.style.left=e+"px",o.style.top=i+"px"},e.onmouseup=function(){this.releaseCapture?this.releaseCapture():window.captureEvents&&window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP),e.onmousemove=null,e.onmouseup=null,e.ondragstart=null,e.onselectstart=null,e.onselect=null}})},_close:function(t,e){if("none"!==p("#"+t+"Dialog").css("display")&&(void 0===e.close||e.close())&&(p("#"+t+"Dialog").hide(),e.modal)){var i=this._getDefaults(p.dialog._defaults,e,"styleClass");p("."+i.background).hide()}},_closeDialog:function(t){var e=this._getInst(t),i=e.id,o=e.settings;p.dialog._close(i,o)},_openDialog:function(t,e){var i=this._getInst(t),o=i.id,n=i.settings
|
|
|
|
var editors={autocompleteMutex:!1,data:[],tabs:{},getEditorByPath:function(e){for(var t=0,o=editors.data.length;t<o;t++)if(editors.data[t].editor.options.path===e)return editors.data[t].editor},close:function(){$('.edit-panel .tabs > div[data-index="'+$(".edit-panel .frame").data("index")+"]").find(".ico-close").click()},closeOther:function(){var t=$(".edit-panel .frame").data("index"),o=[];if($(".edit-panel .tabs > div").each(function(e){t!==$(this).data("index")&&o.push($(this).data("index"))}),0===o.length)return!1;var e=o.splice(0,1);$("#dialogCloseEditor").data("removeData",o),$('.edit-panel .tabs > div[data-index="'+e+'"]').find(".ico-close").click()},_removeAllMarker:function(){var e=$("#dialogCloseEditor").data("removeData");if(e&&0<e.length){var t=e.splice(0,1);$("#dialogCloseEditor").data("removeData",e),$('.edit-panel .tabs > div[data-index="'+t+'"] .ico-close').click()}wide.curEditor&&wide.curEditor.focus()},_initClose:function(){new ZeroClipboard($("#copyFilePath")),$(".edit-panel").on("mouseup",".tabs > div",function(e){if(e.stopPropagation(),0===e.button)return $(".edit-panel .frame").hide(),!1;var t=e.screenX;return"auto"!==$(".side").css("left")&&"0px"!==$(".side").css("left")||(t=e.screenX-$(".side").width()),$(".edit-panel .frame").show().css({left:t+"px",top:"21px"}).data("index",$(this).data("index")),$("#copyFilePath").attr("data-clipboard-text",$(this).find("span:eq(0)").attr("title")),!1})},init:function(){$("#dialogCloseEditor").dialog({modal:!0,height:90,width:260,title:config.label.tip,hideFooter:!0,afterOpen:function(e){$("#dialogCloseEditor > div:eq(0)").html(config.label.file+" <b>"+e+"</b>. "+config.label.confirm_save+"?"),$("#dialogCloseEditor button:eq(0)").focus()},afterInit:function(){$("#dialogCloseEditor button.save").click(function(){var e=$("#dialogCloseEditor").data("index");wide.fmt(editors.data[e].id,editors.data[e].editor),editors.tabs.del(editors.data[e].id),$("#dialogCloseEditor").dialog("close"),editors._removeAllMarker()}),$("#dialogCloseEditor button.discard").click(function(){var e=$("#dialogCloseEditor").data("index");editors.tabs.del(editors.data[e].id),$("#dialogCloseEditor").dialog("close"),editors._removeAllMarker()}),$("#dialogCloseEditor button.cancel").click(function(e){$("#dialogCloseEditor").dialog("close"),editors._removeAllMarker()})}}),editors.tabs=new Tabs({id:".edit-panel",setAfter:function(){wide.curEditor&&wide.curEditor.focus()},clickAfter:function(e){if("startPage"===e)return wide.curEditor=void 0,$(".footer .cursor").text(""),wide.refreshOutline(),!1},removeBefore:function(e){if("startPage"===e)return editors._removeAllMarker(),!0;for(var t=0,o=editors.data.length;t<o;t++)if(editors.data[t].id===e)return editors.data[t].editor.doc.isClean()?(editors._removeAllMarker(),!0):($("#dialogCloseEditor").dialog("open",$('.edit-panel .tabs > div[data-index="'+editors.data[t].id+'"] > span:eq(0)').text()),$("#dialogCloseEditor").data("index",t),!1)},removeAfter:function(e,t){0===$(".edit-panel .tabs > div").length&&menu.disabled(["close-all"]);for(var o=0,i=editors.data.length;o<i;o++)if(editors.data[o].id===e){editors.data.splice(o,1);break}return 0===editors.data.length?(menu.disabled(["save-all","build","run","go-test","go-vet","go-get","go-install","find","find-next","find-previous","replace","replace-all","format","autocomplete","jump-to-decl","expr-info","find-usages","toggle-comment","edit"]),tree.fileTree.cancelSelectedNode(),wide.curNode=void 0,wide.curEditor=void 0,wide.refreshOutline(),$(".footer .cursor").text(""),!1):t?t!==editors.tabs.getCurrentId()&&void 0:(tree.fileTree.cancelSelectedNode(),wide.curNode=void 0,wide.curEditor=void 0,wide.refreshOutline(),$(".footer .cursor").text(""),!1)}}),this._initCodeMirrorHotKeys(),this.openStartPage(),this._initClose()},openStartPage:function(){wide.curEditor=void 0,wide.refreshOutline(),$(".footer .cursor").text("");var s=function(e,t){var o=new Date(e),i={"M+":o.getMonth()+1,"d+":o.getDate(),"h+":o.getHours(),"m+":o.getMinutes(),"s+":o.getSeconds(),"q+":Math.floor((o.getMonth()+3)/3),S:o.getMilliseconds()}
|
|
|
|
var notification={init:function(){$(".notification-count").click(function(){bottomGroup.tabs.setCurrent("notification"),$(".bottom-window-group .notification").focus(),$(this).hide()}),this._initWS()},_initWS:function(){var o=new ReconnectingWebSocket(config.channel+"/notification/ws?sid="+config.wideSessionId);o.onopen=function(){console.log("[notification onopen] connected")},o.onmessage=function(o){var n=JSON.parse(o.data),t=$(".bottom-window-group .notification > table"),i="";n.cmd&&"init-notification"===n.cmd?console.log("[notification onmessage]"+o.data):(i+='<tr><td class="severity">'+n.severity+'</td><td class="message">'+n.message+'</td><td class="type">'+n.type+"</td></tr>",t.append(i),$(".notification-count").show())},o.onclose=function(o){console.log("[notification onclose] disconnected ("+o.code+")")},o.onerror=function(o){console.log("[notification onerror]")}}};
|
|
|
|
var tree={fileTree:void 0,getCurrentNodeLastNode:function(e){var t=e.children[e.children.length-1];return t.open?tree.getCurrentNodeLastNode(t):t},getNextShowNode:function(e){return 0!==e.level?e.getParentNode().getNextNode()?e.getParentNode().getNextNode():tree.getNextShowNode(e.getParentNode()):e.getNextNode()},isBottomNode:function(e){return!e.open&&(e.getParentNode()?!!e.getParentNode().isLastNode&&tree.isBottomNode(e.getParentNode()):!!e.isLastNode)},getTIdByPath:function(e){for(var t=tree.fileTree.transformToArray(tree.fileTree.getNodes()),i=0,o=t.length;i<o;i++)if(t[i].path===e)return t[i].tId},getOpenPaths:function(){for(var e=tree.fileTree.transformToArray(tree.fileTree.getNodes()),t=[],i=0,o=e.length;i<o;i++)e[i].open&&t.push(e[i].path);return t},getAllParents:function(e,t){return t||(t=[]),e&&e.parentTId?(t.push(e.getParentNode()),tree.getAllParents(e.getParentNode(),t)):t},isParents:function(e,t){var i=tree.fileTree.getNodeByTId(e);if(i&&i.parentTId){var o=tree.fileTree.getNodeByTId(i.parentTId);return i.path===t||tree.isParents(o.tId,t)}return!1},isDir:function(){return 0===wide.curNode.iconSkin.indexOf("ico-ztree-dir")},newFile:function(e){if($(e).hasClass("disabled"))return!1;$("#dialogNewFilePrompt").dialog("open")},newDir:function(e){if($(e).hasClass("disabled"))return!1;$("#dialogNewDirPrompt").dialog("open")},removeIt:function(e){if(e){if($(e).hasClass("disabled"))return!1}else if(!wide.curNode.removable)return!1;$("#dialogRemoveConfirm").dialog("open")},rename:function(e){if(e&&$(e).hasClass("disabled"))return!1;$("#dialogRenamePrompt").dialog("open")},export:function(){var e=newWideRequest(),t=!1;e.path=wide.curNode.path,$.ajax({async:!1,type:"POST",url:config.context+"/file/zip/new",data:JSON.stringify(e),dataType:"json",success:function(e){if(!e.succ)return $("#dialogAlert").dialog("open",e.msg),!1;t=!0}}),t&&window.open(config.context+"/file/zip?path="+wide.curNode.path+".zip")},crossCompile:function(e){var t=newWideRequest();t.path=wide.curNode.path,t.platform=e,$.ajax({async:!1,type:"POST",url:config.context+"/cross",data:JSON.stringify(t),dataType:"json",success:function(e){if(!e.succ)return $("#dialogAlert").dialog("open",e.msg),!1}})},decompress:function(){var e=newWideRequest();e.path=wide.curNode.path,$.ajax({async:!1,type:"POST",url:config.context+"/file/decompress",data:JSON.stringify(e),dataType:"json",success:function(e){if(!e.succ)return $("#dialogAlert").dialog("open",e.msg),!1;var t=wide.curNode.getParentNode();tree.fileTree.reAsyncChildNodes(t,"refresh")}})},refresh:function(e){if(e&&$(e).hasClass("disabled"))return!1;tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh",!0)},gitClone:function(e){if(e&&$(e).hasClass("disabled"))return!1;$("#dialogGitClonePrompt").dialog("open")},import:function(){var e=newWideRequest();e.path=wide.curNode.path,$("#importFileupload").fileupload({url:"/file/upload?path="+e.path,dataType:"json",formData:e,done:function(e,t){tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh")},fail:function(){console.log(arguments)}})},init:function(){$("#file").click(function(){$(this).focus()});var e=newWideRequest();$.ajax({type:"POST",url:config.context+"/files",data:JSON.stringify(e),dataType:"json",success:function(e){if(e.succ){var r=$("#dirRMenu"),n=$("#fileRMenu"),t={data:{key:{title:"path"}},view:{showTitle:!0,selectedMulti:!1},async:{enable:!0,url:config.context+"/file/refresh",autoParam:["path"]},callback:{onDblClick:function(e,t,i){i&&tree.openFile(i)},onRightClick:function(e,t,i){if(i&&!i.isGOAPI){if(menu.undisabled(["import","export","git-clone"]),wide.curNode=i,tree.fileTree.selectNode(i),tree.isDir()){wide.curNode.removable?r.find(".remove").removeClass("disabled"):r.find(".remove").addClass("disabled"),wide.curNode.creatable?r.find(".create").removeClass("disabled"):r.find(".create").addClass("disabled");o=e.clientY-10;r.height()+o>$(".content").height()&&(o=o-r.height()-25),r.css({top:o+"px",left:e.clientX+"px",display:"block"}).show(),n.hide()}else{wide.curNode.removable?n.find(".remove").removeClass("disabled"):n.find(".remove").addClass("disa
|
|
|
|
var wide={curNode:void 0,curEditor:void 0,curProcessId:void 0,refreshOutline:function(){if(!wide.curEditor||wide.curEditor&&"go"!==wide.curEditor.doc.getMode().name)return $("#outline").html(""),!1;var e=newWideRequest();e.code=wide.curEditor.getValue(),$.ajax({type:"POST",async:!1,url:config.context+"/outline",data:JSON.stringify(e),dataType:"json",success:function(e){if(e.succ){for(var t=e.data,o='<ul class="list">',i=["constDecls","varDecls","funcDecls","structDecls","interfaceDecls","typeDecls"],a=0,n=i.length;a<n;a++)for(var l=i[a],r=0,c=t[l].length;r<c;r++){var s=t[l][r];o+='<li data-ch="'+s.Ch+'" data-line="'+s.Line+'"><span class="ico ico-'+l.replace("Decls","")+'"></span> '+s.Name+"</li>"}$("#outline").html(o+"</ul>"),$("#outline li").dblclick(function(){var e=$(this),t=CodeMirror.Pos(e.data("line"),e.data("ch")),o=wide.curEditor;o.setCursor(t);var i=Math.floor(o.getScrollInfo().clientHeight/o.defaultTextHeight()/2),a=o.cursorCoords({line:t.line-i,ch:0},"local");o.scrollTo(0,a.top),o.focus()})}}})},_initDialog:function(){$(".dialog-prompt > input").keyup(function(e){var t=$(this).closest(".dialog-main").find(".dialog-footer > button:eq(0)");13!==e.which||t.prop("disabled")||t.click(),""===$.trim($(this).val())?t.prop("disabled",!0):t.prop("disabled",!1)}),$("#dialogAlert").dialog({modal:!0,height:40,width:350,title:config.label.tip,hiddenOk:!0,cancelText:config.label.confirm,afterOpen:function(e){$("#dialogAlert").html(e)}}),$("#dialogRemoveConfirm").dialog({modal:!0,height:36,width:260,title:config.label.delete,okText:config.label.delete,cancelText:config.label.cancel,afterOpen:function(){$("#dialogRemoveConfirm > b").html('"'+wide.curNode.name+'"')},ok:function(){var e=newWideRequest();e.path=wide.curNode.path,$.ajax({type:"POST",url:config.context+"/file/remove",data:JSON.stringify(e),dataType:"json",success:function(e){if(!e.succ)return $("#dialogRemoveConfirm").dialog("close"),bottomGroup.tabs.setCurrent("notification"),windows.flowBottom(),$(".bottom-window-group .notification").focus(),!1;$("#dialogRemoveConfirm").dialog("close")}})}}),$("#dialogNewFilePrompt").dialog({modal:!0,height:52,width:260,title:config.label.create_file,okText:config.label.create,cancelText:config.label.cancel,afterOpen:function(){$("#dialogNewFilePrompt > input").val("").focus(),$("#dialogNewFilePrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled",!0)},ok:function(){var t=newWideRequest(),e=$("#dialogNewFilePrompt > input").val();t.path=wide.curNode.path+"/"+e,t.fileType="f",$.ajax({type:"POST",url:config.context+"/file/new",data:JSON.stringify(t),dataType:"json",success:function(e){if(!e.succ)return $("#dialogNewFilePrompt").dialog("close"),bottomGroup.tabs.setCurrent("notification"),windows.flowBottom(),$(".bottom-window-group .notification").focus(),!1;$("#dialogNewFilePrompt").dialog("close"),setTimeout(function(){var e=tree.getTIdByPath(t.path);tree.openFile(tree.fileTree.getNodeByTId(e)),tree.fileTree.selectNode(wide.curNode)},100)}})}}),$("#dialogNewDirPrompt").dialog({modal:!0,height:52,width:260,title:config.label.create_dir,okText:config.label.create,cancelText:config.label.cancel,afterOpen:function(){$("#dialogNewDirPrompt > input").val("").focus(),$("#dialogNewDirPrompt").closest(".dialog-main").find(".dialog-footer > button:eq(0)").prop("disabled",!0)},ok:function(){var e=$("#dialogNewDirPrompt > input").val(),t=newWideRequest();t.path=wide.curNode.path+"/"+e,t.fileType="d",$.ajax({type:"POST",url:config.context+"/file/new",data:JSON.stringify(t),dataType:"json",success:function(e){if(!e.succ)return $("#dialogNewDirPrompt").dialog("close"),bottomGroup.tabs.setCurrent("notification"),windows.flowBottom(),$(".bottom-window-group .notification").focus(),!1;$("#dialogNewDirPrompt").dialog("close")}})}}),$("#dialogGoFilePrompt").dialog({modal:!0,height:320,width:660,title:config.label.goto_file,okText:config.label.go,cancelText:config.label.cancel,afterInit:function(){$("#dialogGoFilePrompt").on("dblclick","li",function(){var e=tree.getTIdByPath($(this).find(".ft-small").text());tree.ope
|
|
|
|
var session={init:function(){this._initWS();var s=function(e){var t="normal";return e.isClosed?t="min":e.size>=$("body").width()&&(t="max"),t};setInterval(function(){var e,t=newWideRequest(),o=[],n=editors.getCurrentId()?editors.getCurrentPath():"";editors.tabs.obj._$tabs.find("div").each(function(){var e=$(this);e.find("span:eq(0)").attr("title")!==config.label.start_page&&o.push(e.find("span:eq(0)").attr("title"))}),e=tree.getOpenPaths(),t.currentFile=n,t.fileTree=e,t.files=o,t.layout={side:{size:windows.outerLayout.west.state.size,state:s(windows.outerLayout.west.state)},sideRight:{size:windows.innerLayout.east.state.size,state:s(windows.innerLayout.east.state)},bottom:{size:windows.innerLayout.south.state.size,state:s(windows.innerLayout.south.state)}},$.ajax({type:"POST",url:config.context+"/session/save",data:JSON.stringify(t),dataType:"json",success:function(e){}})},3e4)},restore:function(){if(config.latestSessionContent){for(var e=config.latestSessionContent.fileTree,t=config.latestSessionContent.files,o=config.latestSessionContent.currentFile,n="",s=[],i=tree.fileTree.transformToArray(tree.fileTree.getNodes()),r=0,a=i.length;r<a;r++){for(var d=0,l=e.length;d<l;d++)if(i[r].path===e[d]){for(var c=tree.getAllParents(tree.fileTree.getNodeByTId(i[r].tId)),f=!0,g=0,p=c.length;g<p;g++)!1===c[g].open&&(f=!1);f?tree.fileTree.expandNode(i[r],!0,!1,!0):i[r].open=!0;break}for(var h=0,u=t.length;h<u;h++)if(i[r].path===t[h]){s.push(i[r]);break}i[r].path===o&&(n=i[r].path,tree.fileTree.selectNode(i[r]),wide.curNode=i[r])}for(var w=0,y=t.length;w<y;w++)for(var v=0,m=s.length;v<m;v++)if(s[v].path===t[w]){tree.openFile(s[v]);break}editors.tabs.setCurrent(n);var b=0;for(p=editors.data.length;b<p;b++)if(n===editors.data[b].id){wide.curEditor=editors.data[b].editor;break}}},_initWS:function(){var e=new ReconnectingWebSocket(config.channel+"/session/ws?sid="+config.wideSessionId);e.onopen=function(){console.log("[session onopen] connected");var e="Network",t="";t+='<tr><td class="severity">'+"INFO"+'</td><td class="message">'+("Connected to server [sid="+config.wideSessionId+"], "+function(e,t){var o=new Date(e),n={"M+":o.getMonth()+1,"d+":o.getDate(),"h+":o.getHours(),"m+":o.getMinutes(),"s+":o.getSeconds(),"q+":Math.floor((o.getMonth()+3)/3),S:o.getMilliseconds()};for(var s in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(o.getFullYear()+"").substr(4-RegExp.$1.length))),n)new RegExp("("+s+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?n[s]:("00"+n[s]).substr((""+n[s]).length)));return t}((new Date).getTime(),"yyyy-MM-dd hh:mm:ss"))+'</td><td class="type">'+e+"</td></tr>",$(".bottom-window-group .notification > table").append(t)},e.onmessage=function(e){var t=JSON.parse(e.data);switch(t.cmd){case"create-file":var o=tree.fileTree.getNodeByTId(tree.getTIdByPath(t.dir)),n=t.path.replace(t.dir+"/",""),s=CodeMirror.findModeByFileName(n),i=wide.getClassBySuffix(n.split(".")[1]);t.type&&"f"===t.type?tree.fileTree.addNodes(o,[{id:t.path,name:n,iconSkin:i,path:t.path,mode:s,removable:!0,creatable:!0}]):tree.fileTree.addNodes(o,[{id:t.path,name:n,iconSkin:"ico-ztree-dir ",path:t.path,removable:!0,creatable:!0,isParent:!0}]);break;case"remove-file":case"rename-file":o=tree.fileTree.getNodeByTId(tree.getTIdByPath(t.path));tree.fileTree.removeNode(o);for(var r=tree.fileTree.transformToArray(o),a=0,d=r.length;a<d;a++)editors.tabs.del(r[a].path)}},e.onclose=function(e){console.log("[session onclose] disconnected ("+e.code+")");var t="Network",o="";o+='<tr><td class="severity">'+"ERROR"+'</td><td class="message">'+("Disconnected from server, trying to reconnect it [sid="+config.wideSessionId+"]")+'</td><td class="type">'+t+"</td></tr>",$(".bottom-window-group .notification > table").append(o),$(".notification-count").show()},e.onerror=function(e){console.log("[session onerror]")}}};
|
|
|
|
var menu={init:function(){this.subMenu(),this._initPreference(),this._initAbout(),this._initShare(),$(".menu .frame li").click(function(){$(".menu > ul > li").unbind().removeClass("selected"),menu.subMenu()})},_initShare:function(){$(".menu .ico-share").hover(function(){$(".menu .share-panel").show()}),$(".share-panel .font-ico").click(function(){var e=$(this).attr("class").split("-")[2],t="https://wide.b3log.org",a="https://wide.b3log.org/static/images/wide-logo.png",n={};n.email="mailto:?subject="+$("title").text()+"&body="+$("meta[name=description]").attr("content")+" "+t;var i=encodeURIComponent($("meta[name=description]").attr("content")+" "+t+" #golang");n.twitter="https://twitter.com/intent/tweet?status="+i,n.facebook="https://www.facebook.com/sharer/sharer.php?u="+t,n.googleplus="https://plus.google.com/share?url="+t;var o=encodeURIComponent($("title").text()+". \n"+$("meta[name=description]").attr("content")+" #golang#");n.weibo="http://v.t.sina.com.cn/share/share.php?title="+o+"&url="+t+"&pic="+a,n.qqz="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+t+"&sharesource=qzone&title="+o+"&pics="+a,window.open(n[e],"_blank","top=100,left=200,width=648,height=618")})},_initAbout:function(){$("#dialogAbout").load(config.context+"/about",function(){$("#dialogAbout").dialog({modal:!0,title:config.label.about,hideFooter:!0,afterOpen:function(){$.ajax({url:"https://rhythm.b3log.org/version/wide/latest",type:"GET",dataType:"jsonp",jsonp:"callback",success:function(e,t){$("#dialogAbout .version").text()===e.wideVersion?$(".upgrade").text(config.label.uptodate):$(".upgrade").html(config.label.new_version_available+config.label.colon+"<a href='"+e.wideDownload+"' target='_blank'>"+e.wideVersion+"</a>")}})}})})},disabled:function(e){for(var t=0,a=e.length;t<a;t++)$(".menu li."+e[t]).addClass("disabled")},undisabled:function(e){for(var t=0,a=e.length;t<a;t++)$(".menu li."+e[t]).removeClass("disabled")},subMenu:function(){$(".menu > ul > li").click(function(e){1!==$(e.target).closest(".frame").length&&($(this).find(".frame").show(),$(".menu > ul > li").removeClass("selected"),$(this).addClass("selected"),$(".menu > ul > li").unbind(),$(".menu > ul > li").mouseover(function(){1!==$(e.target).closest(".frame").length&&($(".menu .frame").hide(),$(this).find(".frame").show(),$(".menu > ul > li").removeClass("selected"),$(this).addClass("selected"))}))})},openPreference:function(){$("#dialogPreference").dialog("open")},saveAllFiles:function(){if($(".menu li.save-all").hasClass("disabled"))return!1;for(var e=0,t=editors.data.length;e<t;e++){var a=editors.data[e].id,n=editors.data[e].editor;"text/x-go"===n.getOption("mode")?wide.fmt(a,n):wide._save(a,n)}},closeAllFiles:function(){if($(".menu li.close-all").hasClass("disabled"))return!1;var t=[];$(".edit-panel .tabs > div").each(function(e){0!==e&&t.push($(this).data("index"))}),$("#dialogCloseEditor").data("removeData",t),$(".edit-panel .tabs .ico-close:eq(0)").click()},exit:function(){var e=newWideRequest();$.ajax({type:"POST",url:config.context+"/logout",data:JSON.stringify(e),dataType:"json",success:function(e){e.succ&&(window.location.href=config.context+"/login")}})},openAbout:function(){$("#dialogAbout").dialog("open")},goget:function(){menu.saveAllFiles();var e=editors.getCurrentPath();if(!e)return!1;if($(".menu li.go-get").hasClass("disabled"))return!1;var t=newWideRequest();t.file=e,$.ajax({type:"POST",url:config.context+"/go/get",data:JSON.stringify(t),dataType:"json",beforeSend:function(){bottomGroup.resetOutput()},success:function(e){}})},goinstall:function(){menu.saveAllFiles();var e=editors.getCurrentPath();if(!e)return!1;if($(".menu li.go-install").hasClass("disabled"))return!1;var t=newWideRequest();t.file=e,$.ajax({type:"POST",url:config.context+"/go/install",data:JSON.stringify(t),dataType:"json",beforeSend:function(){bottomGroup.resetOutput()},success:function(e){}})},test:function(){menu.saveAllFiles();var e=editors.getCurrentPath();if(!e)return!1;if($(".menu li.go-test").hasClass("disabled"))return!1;var t=newWideRequest();t.file=e,$.ajax({type:"P
|
|
|
|
var windows={isMaxEditor:!1,outerLayout:{},innerLayout:{},init:function(){config.latestSessionContent||(config.latestSessionContent={fileTree:[],files:[],currentFile:""}),config.latestSessionContent.layout||(config.latestSessionContent.layout={side:{size:200,state:"normal"},sideRight:{size:200,state:"normal"},bottom:{size:100,state:"normal"}});var o=config.latestSessionContent.layout;this.outerLayout=$("body").layout({north__paneSelector:".menu",center__paneSelector:".content",south__paneSelector:".footer",north__size:22,south__size:19,spacing_open:2,north__spacing_open:0,south__spacing_open:0,defaults:{fxSpeed_open:300,fxSpeed_close:100,fxSettings_close:{easing:"easeOutQuint"},fxSettings_open:{easing:"easeInQuint"}},west:{size:o.side.size,paneSelector:".side",togglerLength_open:0,togglerLength_closed:15,togglerAlign_closed:"top",slideTrigger_open:"mouseover",spacing_closed:15,minSize:100,togglerClass:"ico-restore",togglerTip_open:config.label.min,togglerTip_closed:config.label.restore_side,resizerTip:config.label.resize,initClosed:"min"===o.side.state}}),this.innerLayout=$("div.content").layout({spacing_open:2,defaults:{fxSpeed_open:300,fxSpeed_close:100,fxSettings_close:{easing:"easeOutQuint"},fxSettings_open:{easing:"easeInQuint"}},center:{paneSelector:".edit-panel"},east:{size:o.sideRight.size,paneSelector:".side-right",togglerLength_open:0,togglerLength_closed:15,togglerAlign_closed:"top",slideTrigger_open:"mouseover",spacing_closed:15,minSize:100,togglerClass:"ico-restore",togglerTip_open:config.label.min,togglerTip_closed:config.label.restore_outline,resizerTip:config.label.resize,initClosed:"min"===o.sideRight.state},south:{size:o.bottom.size,paneSelector:".bottom-window-group",togglerLength_open:0,togglerLength_closed:15,togglerAlign_closed:"top",slideTrigger_open:"mouseover",spacing_closed:16,minSize:100,togglerClass:"ico-restore",togglerTip_open:config.label.min,togglerTip_closed:config.label.restore_bottom,resizerTip:config.label.resize,initClosed:"min"===o.bottom.state,ondrag_end:function(o,e){windows.refreshEditor(e,"drag")},onresize_end:function(o,e){windows.refreshEditor(e,"resize")},onclose_end:function(o,e){windows.refreshEditor(e,"close")},onopen_end:function(o,e){windows.refreshEditor(e,"open")},onshow_end:function(o,e){windows.refreshEditor(e,"show")}}}),this.outerLayout.addCloseBtn(".side .ico-min","west"),this.innerLayout.addCloseBtn(".side-right .ico-min","east"),this.innerLayout.addCloseBtn(".bottom-window-group .ico-min","south"),"max"===o.side.state&&windows.maxSide(),"max"===o.sideRight.state&&windows.maxSideRight(),"max"===o.bottom.state&&windows.maxBottom(),$(".toolbars .ico-max").click(function(){windows.toggleEditor()}),$(".edit-panel .tabs").on("dblclick",function(){windows.toggleEditor()}),$(".bottom-window-group .tabs").dblclick(function(){var o=$(".bottom-window-group");o.hasClass("bottom-window-group-max")?windows.restoreBottom():windows.maxBottom(o)}),$(".side .tabs").dblclick(function(){var o=$(".side");o.hasClass("side-max")?windows.restoreSide():windows.restoreSide(o)}),$(".side-right .tabs").dblclick(function(){var o=$(".side-right");o.hasClass("side-right-max")?windows.restoreSideRight():windows.maxSideRight(o)}),$(".bottom-window-group .search").height($(".bottom-window-group .tabs-panel").height()),$(window).resize(function(){windows.refreshEditor($(".bottom-window-group"))})},maxEditor:function(){var o=$(".toolbars .font-ico");windows.outerLayout.close("west"),windows.innerLayout.close("south"),windows.innerLayout.close("east"),o.removeClass("ico-max").addClass("ico-restore").attr("title",config.label.min),windows.isMaxEditor=!0},maxBottom:function(o){o.data("height",o.height()).addClass("bottom-window-group-max").find(".ico-min").hide(),windows.outerLayout.hide("west"),windows.innerLayout.hide("east"),windows.innerLayout.sizePane("south",$(".content").height())},maxSide:function(o){o.data("width",o.width()).addClass("side-max").find(".ico-min").hide(),$(".content").hide(),windows.outerLayout.sizePane("west",$("body").width())},maxSideRight:function(o){o.addClass("side-right
|
|
|
|
var hotkeys={defaultKeyMap:{goEditor:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:48,fun:function(){wide.curEditor&&wide.curEditor.focus()}},goFileTree:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:49,fun:function(){windows.outerLayout.west.state.isClosed&&windows.outerLayout.slideOpen("west"),$("#files").focus()}},goOutline:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:50,fun:function(){windows.innerLayout.east.state.isClosed&&windows.innerLayout.slideOpen("east"),$("#outline").focus()}},goOutput:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:52,fun:function(){bottomGroup.tabs.setCurrent("output"),windows.flowBottom(),$(".bottom-window-group .output").focus()}},goSearch:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:53,fun:function(){bottomGroup.tabs.setCurrent("search"),windows.flowBottom(),$(".bottom-window-group .search").focus()}},goNotification:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:54,fun:function(){bottomGroup.tabs.setCurrent("notification"),windows.flowBottom(),$(".bottom-window-group .notification").focus()}},clearWindow:{ctrlKey:!1,altKey:!0,shiftKey:!1,which:67},changeEditor:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:68},search:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:70},closeCurEditor:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:81},rename:{ctrlKey:!0,altKey:!1,shiftKey:!1,which:82},goFile:{ctrlKey:!1,altKey:!0,shiftKey:!0,which:79},build:{ctrlKey:!1,altKey:!1,shiftKey:!1,which:116},buildRun:{ctrlKey:!1,altKey:!1,shiftKey:!1,which:117}},bindList:function(e,o,d){o.data("index",0),e.keydown(function(e){var t=o.data("index"),i=o.find("li").length;if(0===i)return!0;38===e.which&&--t<0&&(t=i-1),40===e.which&&i-1<++t&&(t=0);var r=o.find("li:eq("+t+")");return 13===e.which&&d(r),o.find("li").removeClass("selected"),o.data("index",t),r.addClass("selected"),0===t?o.scrollTop(0):r[0].offsetTop+o.scrollTop()>o.height()?40===e.which?o.scrollTop(o.scrollTop()+r.height()):o.scrollTop(r[0].offsetTop):o.scrollTop(0),38!==e.which&&40!==e.which&&13!==e.which&&void 0})},_bindOutput:function(){$(".bottom-window-group .output").keydown(function(e){var t=hotkeys.defaultKeyMap;if(e.altKey===t.clearWindow.altKey&&e.which===t.clearWindow.which)return bottomGroup.clear("output"),void e.preventDefault()})},_bindFileTree:function(){$("#files").keydown(function(e){e.preventDefault();var t=hotkeys.defaultKeyMap;if(e.ctrlKey!==t.search.ctrlKey||e.which!==t.search.which)if(e.ctrlKey!==t.rename.ctrlKey||e.which!==t.rename.which)switch(e.which){case 46:tree.removeIt();break;case 13:if(!wide.curNode)return!1;if(tree.isDir()){if(wide.curNode.open)return!1;tree.fileTree.expandNode(wide.curNode,!0,!1,!0),$("#files").focus();break}tree.openFile(wide.curNode);break;case 38:var i={};if(wide.curNode){if(wide.curNode&&wide.curNode.isFirstNode&&0===wide.curNode.level)return!1;i=wide.curNode.getPreNode(),wide.curNode.isFirstNode&&wide.curNode.getParentNode()&&(i=wide.curNode.getParentNode());var r=wide.curNode.getPreNode();r&&tree.isDir()&&r.open&&(i=tree.getCurrentNodeLastNode(r))}else i=tree.fileTree.getNodeByTId("files_1");wide.curNode=i,tree.fileTree.selectNode(i),$("#files").focus();break;case 40:i={};if(wide.curNode){if(wide.curNode&&tree.isBottomNode(wide.curNode))return!1;i=wide.curNode.getNextNode(),tree.isDir()&&wide.curNode.open&&(i=wide.curNode.children[0]);var o=tree.getNextShowNode(wide.curNode);wide.curNode.isLastNode&&0!==wide.curNode.level&&!wide.curNode.open&&o&&(i=o)}else i=tree.fileTree.getNodeByTId("files_1");i&&(wide.curNode=i,tree.fileTree.selectNode(i)),$("#files").focus();break;case 37:if(!wide.curNode)return wide.curNode=tree.fileTree.getNodeByTId("files_1"),tree.fileTree.selectNode(wide.curNode),$("#files").focus(),!1;if(!tree.isDir()||!wide.curNode.open)return!1;tree.fileTree.expandNode(wide.curNode,!1,!1,!0),$("#files").focus();break;case 39:if(!wide.curNode)return wide.curNode=tree.fileTree.getNodeByTId("files_1"),tree.fileTree.selectNode(wide.curNode),$("#files").focus(),!1;if(!tree.isDir()||wide.curNode.open)return!1;tree.fileTree.expandNode(wide.curNode,!0,!1,!0),$("#files").focus();break;case 116:if(!wide.curNode||!tree.isDir())return!1;tree.refresh(wide.
|
|
|
|
var bottomGroup={tabs:void 0,searchTab:void 0,init:function(){this._initTabs(),this._initFrame(),$(".bottom-window-group .output").click(function(){$(this).focus()}),$(".bottom-window-group .output").on("click",".path",function(t){var o=$(this),i=tree.getTIdByPath(o.data("path"));return tree.openFile(tree.fileTree.getNodeByTId(i),CodeMirror.Pos(o.data("line")-1,o.data("column")-1)),t.preventDefault(),!1})},_initFrame:function(){$(".bottom-window-group .output").parent().mouseup(function(t){if(t.stopPropagation(),0!==t.button){var o=t.screenX,i=$(this);"auto"!==$(".side").css("left")&&"0px"!==$(".side").css("left")||(o=t.screenX-$(".side").width()),$(".bottom-window-group .frame").show().css({left:o+"px",top:t.offsetY+t.target.offsetTop-i.scrollTop()-10+"px"})}else $(".bottom-window-group .frame").hide()})},clear:function(t){$(".bottom-window-group ."+t+" > div").text("")},resetOutput:function(){this.clear("output"),bottomGroup.tabs.setCurrent("output"),windows.flowBottom()},_initTabs:function(){this.tabs=new Tabs({id:".bottom-window-group",clickAfter:function(t){this._$tabsPanel.find("."+t).focus()}})},fillOutput:function(t){var o=$(".bottom-window-group .output");-1!==(t=(t=t.replace(/\r/g,"")).replace(/\n/g,"<br/>")).indexOf("<br/>")&&(t=Autolinker.link(t)),o.find("div").html(t),o.parent().scrollTop(o[0].scrollHeight)}};
|
2015-12-15 18:12:54 +03:00
|
|
|
//# sourceMappingURL=wide.min.js.map
|