wide/static/js/wide.min.js

13 lines
68 KiB
JavaScript
Raw Normal View History

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)+" |")}}}});
2019-06-23 09:14:37 +03:00
!function(p){p.fn.extend({dialog:{version:"0.0.1.7",author:"v@b3log.org"}});function t(){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"}}}var e=(new Date).getTime(),n="dialog";p.extend(t.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,a
2021-04-11 17:42:50 +03:00
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-mod","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("");function d(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()};for
2019-06-23 09:14:37 +03:00
var notification={init:function(){$(".notification-count").click(function(){bottomGroup.tabs.setCurrent("notification"),$(".bottom-window-group .notification").focus(),$(this).hide()}),this._initWS()},_initWS:function(){var n=new ReconnectingWebSocket(config.channel+"/notification/ws?sid="+config.wideSessionId);n.onopen=function(){},n.onmessage=function(n){var t=JSON.parse(n.data),o=$(".bottom-window-group .notification > table"),i="";t.cmd&&"init-notification"===t.cmd||(i+='<tr><td class="severity">'+t.severity+'</td><td class="message">'+t.message+'</td><td class="type">'+t.type+"</td></tr>",o.append(i),$(".notification-count").show())},n.onclose=function(n){},n.onerror=function(n){console.log("[notification onerror]",n)}}};
2019-05-24 16:52:17 +03:00
var tree={fileTree:void 0,getCurrentNodeLastNode:function(e){var i=e.children[e.children.length-1];return i.open?tree.getCurrentNodeLastNode(i):i},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 i=tree.fileTree.transformToArray(tree.fileTree.getNodes()),t=0,o=i.length;t<o;t++)if(i[t].path===e)return i[t].tId},getOpenPaths:function(){for(var e=tree.fileTree.transformToArray(tree.fileTree.getNodes()),i=[],t=0,o=e.length;t<o;t++)e[t].open&&i.push(e[t].path);return i},getAllParents:function(e,i){return i||(i=[]),e&&e.parentTId?(i.push(e.getParentNode()),tree.getAllParents(e.getParentNode(),i)):i},isParents:function(e,i){var t=tree.fileTree.getNodeByTId(e);if(t&&t.parentTId){var o=tree.fileTree.getNodeByTId(t.parentTId);return t.path===i||tree.isParents(o.tId,i)}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(),i=!1;e.path=wide.curNode.path,$.ajax({async:!1,type:"POST",url:"/file/zip/new",data:JSON.stringify(e),dataType:"json",success:function(e){if(0!=e.code)return $("#dialogAlert").dialog("open",e.msg),!1;i=!0}}),i&&window.open("/file/zip?path="+wide.curNode.path+".zip")},crossCompile:function(e){var i=newWideRequest();i.path=wide.curNode.path,i.platform=e,$.ajax({async:!1,type:"POST",url:"/cross",data:JSON.stringify(i),dataType:"json",success:function(e){if(0!=e.code)return $("#dialogAlert").dialog("open",e.msg),!1}})},refresh:function(e){if(e&&$(e).hasClass("disabled"))return!1;tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh",!0)},init:function(){$("#file").click(function(){$(this).focus()});var e=newWideRequest();$.ajax({type:"POST",url:"/files",data:JSON.stringify(e),dataType:"json",success:function(e){if(0==e.code){var r=$("#dirRMenu"),a=$("#fileRMenu"),i={data:{key:{title:"path"}},view:{showTitle:!0,selectedMulti:!1},async:{enable:!0,url:"/file/refresh",autoParam:["path"]},callback:{onDblClick:function(e,i,t){t&&tree.openFile(t)},onRightClick:function(e,i,t){if(t&&!t.isGOAPI){if(menu.undisabled(["import","export","git-clone"]),wide.curNode=t,tree.fileTree.selectNode(t),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(),a.hide()}else{wide.curNode.removable?a.find(".remove").removeClass("disabled"):a.find(".remove").addClass("disabled"),-1===wide.curNode.path.indexOf("zip",wide.curNode.path.length-"zip".length)?a.find(".decompress").hide():a.find(".decompress").show(),-1===wide.curNode.path.indexOf("go",wide.curNode.path.length-"go".length)?a.find(".linux64").hide():a.find(".linux64").show();var o=e.clientY-10;a.height()+o>$(".content").height()&&(o=o-a.height()-25),a.css({top:o+"px",left:e.clientX+"px",display:"block"}).show(),r.hide(),menu.disabled(["import","git-clone"])}$("#files").focus()}},onClick:function(e,i,t,o){t&&(wide.curNode=t,tree.fileTree.selectNode(t),menu.undisabled(["import","export","git-clone"]),tree.isDir()||menu.disabled(["import","git-clone"]),$("#files").focus())}}};tree.fileTree=$.fn.zTree.init($("#files"),i,e.data.children),session.restore()}}}),this._initSearch(),this._initRename(
2019-06-23 09:14:37 +03:00
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:"/outline",data:JSON.stringify(e),dataType:"json",success:function(e){if(0==e.code){for(var t=e.data,o='<ul class="list">',i=["constDecls","varDecls","funcDecls","structDecls","interfaceDecls","typeDecls"],a=0,l=i.length;a<l;a++)for(var n=i[a],r=0,s=t[n].length;r<s;r++){var c=t[n][r];o+='<li data-ch="'+c.Ch+'" data-line="'+c.Line+'"><span class="ico ico-'+n.replace("Decls","")+'"></span> '+c.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:"/file/remove",data:JSON.stringify(e),dataType:"json",success:function(e){if(0!=e.code)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:"/file/new",data:JSON.stringify(t),dataType:"json",success:function(e){if(0!=e.code)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:"/file/new",data:JSON.stringify(t),dataType:"json",success:function(e){if(0!=e.code)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.openFile(tree.fileTree.getNodeByTId(e)),tree.fileTree.
var session={init:function(){this._initWS();function n(e){var t="normal";return e.isClosed?t="min":e.size>=$("body").width()&&(t="max"),t}setInterval(function(){var e,t=newWideRequest(),r=[],i=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&&r.push(e.find("span:eq(0)").attr("title"))}),e=tree.getOpenPaths(),t.currentFile=i,t.fileTree=e,t.files=r,t.layout={side:{size:windows.outerLayout.west.state.size,state:n(windows.outerLayout.west.state)},sideRight:{size:windows.innerLayout.east.state.size,state:n(windows.innerLayout.east.state)},bottom:{size:windows.innerLayout.south.state.size,state:n(windows.innerLayout.south.state)}},$.ajax({type:"POST",url:"/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,r=config.latestSessionContent.currentFile,i="",n=[],s=tree.fileTree.transformToArray(tree.fileTree.getNodes()),o=0,a=s.length;o<a;o++){for(var d=0,l=e.length;d<l;d++)if(s[o].path===e[d]){for(var f=tree.getAllParents(tree.fileTree.getNodeByTId(s[o].tId)),c=!0,g=0,h=f.length;g<h;g++)!1===f[g].open&&(c=!1);c?tree.fileTree.expandNode(s[o],!0,!1,!0):s[o].open=!0;break}for(var p=0,u=t.length;p<u;p++)if(s[o].path===t[p]){n.push(s[o]);break}s[o].path===r&&(i=s[o].path,tree.fileTree.selectNode(s[o]),wide.curNode=s[o])}for(var w=0,y=t.length;w<y;w++)for(var v=0,m=n.length;v<m;v++)if(n[v].path===t[w]){tree.openFile(n[v]);break}editors.tabs.setCurrent(i);var b=0;for(h=editors.data.length;b<h;b++)if(i===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(){var e="Network",t="";t+='<tr><td class="severity">'+"INFO"+'</td><td class="message">'+("Connected to server [sid="+config.wideSessionId+"], "+function(e,t){var r=new Date(e),i={"M+":r.getMonth()+1,"d+":r.getDate(),"h+":r.getHours(),"m+":r.getMinutes(),"s+":r.getSeconds(),"q+":Math.floor((r.getMonth()+3)/3),S:r.getMilliseconds()};for(var n in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(r.getFullYear()+"").substr(4-RegExp.$1.length))),i)new RegExp("("+n+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?i[n]:("00"+i[n]).substr((""+i[n]).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 r=tree.fileTree.getNodeByTId(tree.getTIdByPath(t.dir)),i=t.path.replace(t.dir+"/",""),n=CodeMirror.findModeByFileName(i),s=wide.getClassBySuffix(i.split(".")[1]);t.type&&"f"===t.type?tree.fileTree.addNodes(r,[{id:t.path,name:i,iconSkin:s,path:t.path,mode:n,removable:!0,creatable:!0}]):tree.fileTree.addNodes(r,[{id:t.path,name:i,iconSkin:"ico-ztree-dir ",path:t.path,removable:!0,creatable:!0,isParent:!0}]);break;case"remove-file":case"rename-file":r=tree.fileTree.getNodeByTId(tree.getTIdByPath(t.path));tree.fileTree.removeNode(r);for(var o=tree.fileTree.transformToArray(r),a=0,d=o.length;a<d;a++)editors.tabs.del(o[a].path)}},e.onclose=function(e){var t="Network",r="";r+='<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(r),$(".notification-count").show()},e.onerror=function(e){console.log("[session onerror]",e)}}};
2019-05-24 16:52:17 +03:00
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",i={};i.email="mailto:?subject="+$("title").text()+"&body="+$("meta[name=description]").attr("content")+" "+t;var n=encodeURIComponent($("meta[name=description]").attr("content")+" "+t+" #golang");i.twitter="https://twitter.com/intent/tweet?status="+n,i.facebook="https://www.facebook.com/sharer/sharer.php?u="+t,i.googleplus="https://plus.google.com/share?url="+t;var o=encodeURIComponent($("title").text()+". \n"+$("meta[name=description]").attr("content")+" #golang#");i.weibo="http://v.t.sina.com.cn/share/share.php?title="+o+"&url="+t+"&pic="+a,i.qqz="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+t+"&sharesource=qzone&title="+o+"&pics="+a,window.open(i[e],"_blank","top=100,left=200,width=648,height=618")})},_initAbout:function(){$("#dialogAbout").load("/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,i=editors.data[e].editor;"text/x-go"===i.getOption("mode")?wide.fmt(a,i):wide._save(a,i)}},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:"/logout",data:JSON.stringify(e),dataType:"json",success:function(e){0==e.code&&(window.location.href="/login")}})},openAbout:function(){$("#dialogAbout").dialog("open")},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:"/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:"POST",url:"/go/test",data:JSON.stringify(t),dataType:"json",beforeSend:function(){bottomGroup.resetOutput()},success:function(e){}})},govet:function(){menu.saveAllFiles();var e=editors.getCurrentPath();if(!e)return!1;if($(".menu li.go-vet").hasClass("disabled"))return!1;var t=newWideRequest();t.file=e,$.ajax({type:"POST",url:"/go/vet",data:JSON.stringify(t),dataType:"json",beforeSend:fu
2018-10-05 18:11:52 +03:00
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
2019-06-23 09:14:37 +03:00
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.
2018-10-05 18:11:52 +03:00
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