diff --git a/README.md b/README.md index 520beed..079173d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -* [Wide 用户指南](https://hacpai.com/article/1538873544275) -* [Wide 开发指南](https://hacpai.com/article/1538876422995) +* [Wide 用户指南](https://ld246.com/article/1538873544275) +* [Wide 开发指南](https://ld246.com/article/1538876422995) ![Overview](https://cloud.githubusercontent.com/assets/873584/5450620/1d51831e-8543-11e4-930b-670871902425.png) diff --git a/conf/wide.go b/conf/wide.go index 8aed7c3..6746374 100644 --- a/conf/wide.go +++ b/conf/wide.go @@ -49,7 +49,7 @@ const ( import "fmt" func main() { - fmt.Println("欢迎通过《边看边练 Go 系列》来学习 Go 语言 https://hacpai.com/article/1437497122181") + fmt.Println("欢迎通过《边看边练 Go 系列》来学习 Go 语言 https://ld246.com/article/1437497122181") } ` ) diff --git a/session/oauth.go b/session/oauth.go index 6175a1a..796c50d 100644 --- a/session/oauth.go +++ b/session/oauth.go @@ -34,7 +34,7 @@ var states = map[string]string{} // LoginRedirectHandler redirects to HacPai auth page. func LoginRedirectHandler(w http.ResponseWriter, r *http.Request) { - loginAuthURL := "https://hacpai.com/login?goto=" + conf.Wide.Server + "/login/callback" + loginAuthURL := "https://ld246.com/login?goto=" + conf.Wide.Server + "/login/callback" state := gulu.Rand.String(16) states[state] = state diff --git a/static/js/editors.js b/static/js/editors.js index bb9e635..f6edb17 100644 --- a/static/js/editors.js +++ b/static/js/editors.js @@ -248,7 +248,7 @@ var editors = { after: function () { $("#startPage").load('/start?sid=' + config.wideSessionId); $.ajax({ - url: "https://hacpai.com/apis/articles?tags=wide,golang&p=1&size=20", + url: "https://ld246.com/apis/articles?tags=wide,golang&p=1&size=20", type: "GET", dataType: "jsonp", jsonp: "callback", @@ -265,7 +265,7 @@ var editors = { } var listHTML = "
"+t.output+""),wide.curProcessId=t.pid;break;case"run-done":bottomGroup.fillOutput($(".bottom-window-group .output > div").html().replace(/<\/pre>$/g,t.output+"")),wide.curProcessId=void 0,$("#buildRun").removeClass("ico-stop").addClass("ico-buildrun").attr("title",config.label.build_n_run);break;case"start-build":case"start-test":case"start-vet":case"start-install":bottomGroup.fillOutput(t.output);break;case"go test":case"go vet":case"go install":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output);break;case"git clone":bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),tree.fileTree.reAsyncChildNodes(wide.curNode,"refresh",!1);break;case"build":case"cross-build":if(bottomGroup.fillOutput($(".bottom-window-group .output > div").html()+t.output),t.lints){for(var i={},a=0;a
' + data.output + '');\n } else {\n bottomGroup.fillOutput(content.replace(/<\\/pre>$/g, data.output + ''));\n }\n\n wide.curProcessId = data.pid;\n\n break;\n case 'run-done':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html().replace(/<\\/pre>$/g, data.output + ''));\n\n wide.curProcessId = undefined;\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n\n break;\n case 'start-build':\n case 'start-test':\n case 'start-vet':\n case 'start-install':\n bottomGroup.fillOutput(data.output);\n\n break;\n case 'go test':\n case 'go vet':\n case 'go install':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n\n break;\n case 'git clone':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n tree.fileTree.reAsyncChildNodes(wide.curNode, \"refresh\", false);\n\n break;\n case 'build':\n case 'cross-build':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n\n if (data.lints) { // has build error\n var files = {};\n\n for (var i = 0; i < data.lints.length; i++) {\n var lint = data.lints[i];\n\n goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),\n to: CodeMirror.Pos(lint.lineNo, 0),\n message: lint.msg, severity: lint.severity});\n\n files[lint.file] = lint.file;\n }\n\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n\n // trigger gutter lint\n for (var path in files) {\n var editor = editors.getEditorByPath(path);\n CodeMirror.signal(editor, \"change\", editor);\n }\n } else {\n if ('cross-build' === data.cmd) {\n var request = newWideRequest(),\n path = null;\n request.path = data.executable;\n request.name = data.name;\n\n $.ajax({\n async: false,\n type: 'POST',\n url: '/file/zip/new',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 != result.code) {\n $(\"#dialogAlert\").dialog(\"open\", result.msg);\n\n return false;\n }\n\n path = result.data;\n }\n });\n\n if (path) {\n window.open('/file/zip?path=' + path + \".zip\");\n }\n }\n }\n\n break;\n }\n };\n outputWS.onclose = function (e) {\n // console.log('[output onclose] disconnected (' + e.code + ')');\n };\n outputWS.onerror = function (e) {\n console.log('[output onerror]',e);\n };\n },\n _initFooter: function () {\n $(\".footer .cursor\").dblclick(function () {\n $(\"#dialogGoLinePrompt\").dialog(\"open\");\n });\n },\n init: function () {\n this._initFooter();\n\n this._initWS();\n\n // 点击隐藏弹出层\n $(\"body\").bind(\"mouseup\", function (event) {\n // MAC 右键文件树失效\n if (event.which === 3) {\n return false;\n }\n\n $(\".frame\").hide();\n\n if (!($(event.target).closest(\".frame\").length === 1 || event.target.className === \"frame\")) {\n $(\".menu > ul > li\").unbind().removeClass(\"selected\");\n menu.subMenu();\n }\n });\n\n // 刷新提示\n window.onbeforeunload = function () {\n if (editors.data.length > 0) {\n return config.label.confirm_save;\n }\n };\n\n // 禁止鼠标右键菜单\n document.oncontextmenu = function () {\n return false;\n };\n\n this._initDialog();\n },\n _save: function (path, editor) {\n if (!path) {\n return false;\n }\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n\n $.ajax({\n type: 'POST',\n url: '/file/save',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n // reset the save state\n editor.doc.markClean();\n $(\".edit-panel .tabs > div\").each(function () {\n var $span = $(this).find(\"span:eq(0)\");\n if ($span.attr(\"title\") === path) {\n $span.removeClass(\"changed\");\n }\n });\n }\n });\n },\n saveFile: function () {\n var path = editors.getCurrentPath();\n if (!path) {\n return false;\n }\n\n var editor = wide.curEditor;\n if (editor.doc.isClean()) { // no modification\n return false;\n }\n\n if (\"text/x-go\" === editor.getOption(\"mode\")) {\n wide.gofmt(path, wide.curEditor); // go fmt will save\n\n // build the file at once\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.nextCmd = \"\"; // build only, no following operation\n $.ajax({\n type: 'POST',\n url: '/build',\n data: JSON.stringify(request),\n dataType: \"json\",\n beforeSend: function () {\n bottomGroup.resetOutput();\n },\n success: function (result) {\n }\n });\n\n // refresh outline\n wide.refreshOutline();\n\n return;\n }\n\n wide._save(path, wide.curEditor);\n },\n stop: function () {\n if ($(\"#buildRun\").hasClass(\"ico-buildrun\")) {\n menu.run();\n return false;\n }\n\n if (!wide.curProcessId) {\n return false;\n }\n\n var request = newWideRequest();\n request.pid = wide.curProcessId;\n\n $.ajax({\n type: 'POST',\n url: '/stop',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n }\n });\n },\n gofmt: function (path, editor) {\n var cursor = editor.getCursor();\n var scrollInfo = editor.getScrollInfo();\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.cursorLine = cursor.line;\n request.cursorCh = cursor.ch;\n\n $.ajax({\n async: false, // sync\n type: 'POST',\n url: '/go/fmt',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 == result.code) {\n editor.setValue(result.data.code);\n editor.setCursor(cursor);\n editor.scrollTo(null, scrollInfo.top);\n\n wide._save(path, editor);\n }\n }\n });\n },\n fmt: function (path, editor) {\n var mode = editor.getOption(\"mode\");\n\n var cursor = editor.getCursor();\n var scrollInfo = editor.getScrollInfo();\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.cursorLine = cursor.line;\n request.cursorCh = cursor.ch;\n\n var formatted = null;\n\n switch (mode) {\n case \"text/x-go\":\n $.ajax({\n async: false, // sync\n type: 'POST',\n url: '/go/fmt',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 == result.code) {\n formatted = result.data.code;\n }\n }\n });\n\n break;\n case \"text/html\":\n formatted = html_beautify(editor.getValue());\n break;\n case \"text/javascript\":\n case \"application/json\":\n formatted = js_beautify(editor.getValue());\n break;\n case \"text/css\":\n formatted = css_beautify(editor.getValue());\n break;\n default :\n break;\n }\n\n if (formatted) {\n editor.setValue(formatted);\n editor.setCursor(cursor);\n editor.scrollTo(null, scrollInfo.top);\n\n wide._save(path, editor);\n }\n },\n getClassBySuffix: function (suffix) {\n var iconSkin = \"ico-ztree-other \";\n switch (suffix) {\n case \"html\":\n case \"htm\":\n iconSkin = \"ico-ztree-html \";\n break;\n case \"go\":\n iconSkin = \"ico-ztree-go \";\n break;\n case \"css\":\n iconSkin = \"ico-ztree-css \";\n break;\n case \"txt\":\n iconSkin = \"ico-ztree-text \";\n break;\n case \"sql\":\n iconSkin = \"ico-ztree-sql \";\n break;\n case \"properties\":\n iconSkin = \"ico-ztree-pro \";\n break;\n case \"md\":\n iconSkin = \"ico-ztree-md \";\n break;\n case \"js\", \"json\":\n iconSkin = \"ico-ztree-js \";\n break;\n case \"xml\":\n iconSkin = \"ico-ztree-xml \";\n break;\n case \"jpg\":\n case \"jpeg\":\n case \"bmp\":\n case \"gif\":\n case \"png\":\n case \"svg\":\n case \"ico\":\n iconSkin = \"ico-ztree-img \";\n break;\n }\n\n return iconSkin;\n }\n};\n\n$(document).ready(function () {\n wide.init();\n tree.init();\n menu.init();\n hotkeys.init();\n session.init();\n notification.init();\n editors.init();\n windows.init();\n bottomGroup.init();\n});\n","/*\n * Copyright (c) 2014-present, b3log.org\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * @file session.js\n *\n * @author Liyuan Li\n * @version 1.1.0.2, Jun 23, 2019\n */\nvar session = {\n init: function () {\n this._initWS();\n\n var getLayoutState = function (paneState) {\n var state = 'normal';\n if (paneState.isClosed) {\n state = 'min';\n } else if (paneState.size >= $('body').width()) {\n state = 'max';\n }\n\n return state;\n };\n\n // save session content every 30 seconds\n setInterval(function () {\n var request = newWideRequest(),\n filse = [],\n fileTree = [],\n currentId = editors.getCurrentId(),\n currentFile = currentId ? editors.getCurrentPath() : \"\";\n\n editors.tabs.obj._$tabs.find(\"div\").each(function () {\n var $it = $(this);\n if ($it.find(\"span:eq(0)\").attr(\"title\") !== config.label.start_page) {\n filse.push($it.find(\"span:eq(0)\").attr(\"title\"));\n }\n });\n\n fileTree = tree.getOpenPaths();\n\n request.currentFile = currentFile; // current editor file\n request.fileTree = fileTree; // file tree expansion state\n request.files = filse; // editor tabs\n\n\n request.layout = {\n \"side\": {\n \"size\": windows.outerLayout.west.state.size,\n \"state\": getLayoutState(windows.outerLayout.west.state)\n },\n \"sideRight\": {\n \"size\": windows.innerLayout.east.state.size,\n \"state\": getLayoutState(windows.innerLayout.east.state)\n },\n \"bottom\": {\n \"size\": windows.innerLayout.south.state.size,\n \"state\": getLayoutState(windows.innerLayout.south.state)\n }\n };\n\n $.ajax({\n type: 'POST',\n url: '/session/save',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n }\n });\n }, 30000);\n },\n restore: function () {\n if (!config.latestSessionContent) {\n return;\n }\n\n var fileTree = config.latestSessionContent.fileTree,\n files = config.latestSessionContent.files,\n currentFile = config.latestSessionContent.currentFile,\n id = \"\",\n nodesToOpen = [];\n\n var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());\n\n for (var i = 0, ii = nodes.length; i < ii; i++) {\n // expand tree\n for (var j = 0, jj = fileTree.length; j < jj; j++) {\n if (nodes[i].path === fileTree[j]) {\n // expand this node only if its parents are open\n var parents = tree.getAllParents(tree.fileTree.getNodeByTId(nodes[i].tId)),\n isOpen = true;\n for (var l = 0, max = parents.length; l < max; l++) {\n if (parents[l].open === false) {\n isOpen = false;\n }\n }\n if (isOpen) {\n tree.fileTree.expandNode(nodes[i], true, false, true);\n } else {\n // flag it is open\n nodes[i].open = true;\n }\n break;\n }\n }\n\n // open editors\n for (var k = 0, kk = files.length; k < kk; k++) {\n if (nodes[i].path === files[k]) {\n nodesToOpen.push(nodes[i]);\n break;\n }\n }\n\n if (nodes[i].path === currentFile) {\n id = nodes[i].path;\n\n // FIXME: 上面的展开是异步进行的,所以执行到这里的时候可能还没有展开完,导致定位不了可视区域\n tree.fileTree.selectNode(nodes[i]);\n wide.curNode = nodes[i];\n }\n }\n\n // handle the open sequence of editors\n for (var m = 0, mm = files.length; m < mm; m++) {\n for (var n = 0, nn = nodesToOpen.length; n < nn; n++) {\n if (nodesToOpen[n].path === files[m]) {\n tree.openFile(nodesToOpen[n]);\n break;\n }\n }\n }\n\n // set the current editor\n editors.tabs.setCurrent(id);\n for (var c = 0, max = editors.data.length; c < max; c++) {\n if (id === editors.data[c].id) {\n wide.curEditor = editors.data[c].editor;\n break;\n }\n } \n },\n _initWS: function () {\n // Used for session retention, server will release all resources of the session if this channel closed\n var sessionWS = new ReconnectingWebSocket(config.channel + '/session/ws?sid=' + config.wideSessionId);\n\n sessionWS.onopen = function () {\n var dateFormat = function (time, fmt) {\n var date = new Date(time);\n var dateObj = {\n \"M+\": date.getMonth() + 1,\n \"d+\": date.getDate(),\n \"h+\": date.getHours(),\n \"m+\": date.getMinutes(),\n \"s+\": date.getSeconds(),\n \"q+\": Math.floor((date.getMonth() + 3) / 3),\n \"S\": date.getMilliseconds()\n };\n if (/(y+)/.test(fmt))\n fmt = fmt.replace(RegExp.$1, (date.getFullYear() + \"\").substr(4 - RegExp.$1.length));\n for (var k in dateObj)\n if (new RegExp(\"(\" + k + \")\").test(fmt)) {\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1)\n ? (dateObj[k]) : ((\"00\" + dateObj[k]).substr((\"\" + dateObj[k]).length)));\n }\n return fmt;\n };\n\n var data = {type: \"Network\", severity: \"INFO\",\n message: \"Connected to server [sid=\" + config.wideSessionId + \"], \" + dateFormat(new Date().getTime(), 'yyyy-MM-dd hh:mm:ss')},\n $notification = $('.bottom-window-group .notification > table'),\n notificationHTML = '';\n\n notificationHTML += '
' + data.output + '');\n } else {\n bottomGroup.fillOutput(content.replace(/<\\/pre>$/g, data.output + ''));\n }\n\n wide.curProcessId = data.pid;\n\n break;\n case 'run-done':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html().replace(/<\\/pre>$/g, data.output + ''));\n\n wide.curProcessId = undefined;\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n\n break;\n case 'start-build':\n case 'start-test':\n case 'start-vet':\n case 'start-install':\n bottomGroup.fillOutput(data.output);\n\n break;\n case 'go test':\n case 'go vet':\n case 'go install':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n\n break;\n case 'git clone':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n tree.fileTree.reAsyncChildNodes(wide.curNode, \"refresh\", false);\n\n break;\n case 'build':\n case 'cross-build':\n bottomGroup.fillOutput($('.bottom-window-group .output > div').html() + data.output);\n\n if (data.lints) { // has build error\n var files = {};\n\n for (var i = 0; i < data.lints.length; i++) {\n var lint = data.lints[i];\n\n goLintFound.push({from: CodeMirror.Pos(lint.lineNo, 0),\n to: CodeMirror.Pos(lint.lineNo, 0),\n message: lint.msg, severity: lint.severity});\n\n files[lint.file] = lint.file;\n }\n\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n\n // trigger gutter lint\n for (var path in files) {\n var editor = editors.getEditorByPath(path);\n CodeMirror.signal(editor, \"change\", editor);\n }\n } else {\n if ('cross-build' === data.cmd) {\n var request = newWideRequest(),\n path = null;\n request.path = data.executable;\n request.name = data.name;\n\n $.ajax({\n async: false,\n type: 'POST',\n url: '/file/zip/new',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 != result.code) {\n $(\"#dialogAlert\").dialog(\"open\", result.msg);\n\n return false;\n }\n\n path = result.data;\n }\n });\n\n if (path) {\n window.open('/file/zip?path=' + path + \".zip\");\n }\n }\n }\n\n break;\n }\n };\n outputWS.onclose = function (e) {\n // console.log('[output onclose] disconnected (' + e.code + ')');\n };\n outputWS.onerror = function (e) {\n console.log('[output onerror]',e);\n };\n },\n _initFooter: function () {\n $(\".footer .cursor\").dblclick(function () {\n $(\"#dialogGoLinePrompt\").dialog(\"open\");\n });\n },\n init: function () {\n this._initFooter();\n\n this._initWS();\n\n // 点击隐藏弹出层\n $(\"body\").bind(\"mouseup\", function (event) {\n // MAC 右键文件树失效\n if (event.which === 3) {\n return false;\n }\n\n $(\".frame\").hide();\n\n if (!($(event.target).closest(\".frame\").length === 1 || event.target.className === \"frame\")) {\n $(\".menu > ul > li\").unbind().removeClass(\"selected\");\n menu.subMenu();\n }\n });\n\n // 刷新提示\n window.onbeforeunload = function () {\n if (editors.data.length > 0) {\n return config.label.confirm_save;\n }\n };\n\n // 禁止鼠标右键菜单\n document.oncontextmenu = function () {\n return false;\n };\n\n this._initDialog();\n },\n _save: function (path, editor) {\n if (!path) {\n return false;\n }\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n\n $.ajax({\n type: 'POST',\n url: '/file/save',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n // reset the save state\n editor.doc.markClean();\n $(\".edit-panel .tabs > div\").each(function () {\n var $span = $(this).find(\"span:eq(0)\");\n if ($span.attr(\"title\") === path) {\n $span.removeClass(\"changed\");\n }\n });\n }\n });\n },\n saveFile: function () {\n var path = editors.getCurrentPath();\n if (!path) {\n return false;\n }\n\n var editor = wide.curEditor;\n if (editor.doc.isClean()) { // no modification\n return false;\n }\n\n if (\"text/x-go\" === editor.getOption(\"mode\")) {\n wide.gofmt(path, wide.curEditor); // go fmt will save\n\n // build the file at once\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.nextCmd = \"\"; // build only, no following operation\n $.ajax({\n type: 'POST',\n url: '/build',\n data: JSON.stringify(request),\n dataType: \"json\",\n beforeSend: function () {\n bottomGroup.resetOutput();\n },\n success: function (result) {\n }\n });\n\n // refresh outline\n wide.refreshOutline();\n\n return;\n }\n\n wide._save(path, wide.curEditor);\n },\n stop: function () {\n if ($(\"#buildRun\").hasClass(\"ico-buildrun\")) {\n menu.run();\n return false;\n }\n\n if (!wide.curProcessId) {\n return false;\n }\n\n var request = newWideRequest();\n request.pid = wide.curProcessId;\n\n $.ajax({\n type: 'POST',\n url: '/stop',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n $(\"#buildRun\").removeClass(\"ico-stop\")\n .addClass(\"ico-buildrun\").attr(\"title\", config.label.build_n_run);\n }\n });\n },\n gofmt: function (path, editor) {\n var cursor = editor.getCursor();\n var scrollInfo = editor.getScrollInfo();\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.cursorLine = cursor.line;\n request.cursorCh = cursor.ch;\n\n $.ajax({\n async: false, // sync\n type: 'POST',\n url: '/go/fmt',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 == result.code) {\n editor.setValue(result.data.code);\n editor.setCursor(cursor);\n editor.scrollTo(null, scrollInfo.top);\n\n wide._save(path, editor);\n }\n }\n });\n },\n fmt: function (path, editor) {\n var mode = editor.getOption(\"mode\");\n\n var cursor = editor.getCursor();\n var scrollInfo = editor.getScrollInfo();\n\n var request = newWideRequest();\n request.file = path;\n request.code = editor.getValue();\n request.cursorLine = cursor.line;\n request.cursorCh = cursor.ch;\n\n var formatted = null;\n\n switch (mode) {\n case \"text/x-go\":\n $.ajax({\n async: false, // sync\n type: 'POST',\n url: '/go/fmt',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n if (0 == result.code) {\n formatted = result.data.code;\n }\n }\n });\n\n break;\n case \"text/html\":\n formatted = html_beautify(editor.getValue());\n break;\n case \"text/javascript\":\n case \"application/json\":\n formatted = js_beautify(editor.getValue());\n break;\n case \"text/css\":\n formatted = css_beautify(editor.getValue());\n break;\n default :\n break;\n }\n\n if (formatted) {\n editor.setValue(formatted);\n editor.setCursor(cursor);\n editor.scrollTo(null, scrollInfo.top);\n\n wide._save(path, editor);\n }\n },\n getClassBySuffix: function (suffix) {\n var iconSkin = \"ico-ztree-other \";\n switch (suffix) {\n case \"html\":\n case \"htm\":\n iconSkin = \"ico-ztree-html \";\n break;\n case \"go\":\n iconSkin = \"ico-ztree-go \";\n break;\n case \"css\":\n iconSkin = \"ico-ztree-css \";\n break;\n case \"txt\":\n iconSkin = \"ico-ztree-text \";\n break;\n case \"sql\":\n iconSkin = \"ico-ztree-sql \";\n break;\n case \"properties\":\n iconSkin = \"ico-ztree-pro \";\n break;\n case \"md\":\n iconSkin = \"ico-ztree-md \";\n break;\n case \"js\", \"json\":\n iconSkin = \"ico-ztree-js \";\n break;\n case \"xml\":\n iconSkin = \"ico-ztree-xml \";\n break;\n case \"jpg\":\n case \"jpeg\":\n case \"bmp\":\n case \"gif\":\n case \"png\":\n case \"svg\":\n case \"ico\":\n iconSkin = \"ico-ztree-img \";\n break;\n }\n\n return iconSkin;\n }\n};\n\n$(document).ready(function () {\n wide.init();\n tree.init();\n menu.init();\n hotkeys.init();\n session.init();\n notification.init();\n editors.init();\n windows.init();\n bottomGroup.init();\n});\n","/*\n * Copyright (c) 2014-present, b3log.org\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * @file session.js\n *\n * @author Liyuan Li\n * @version 1.1.0.2, Jun 23, 2019\n */\nvar session = {\n init: function () {\n this._initWS();\n\n var getLayoutState = function (paneState) {\n var state = 'normal';\n if (paneState.isClosed) {\n state = 'min';\n } else if (paneState.size >= $('body').width()) {\n state = 'max';\n }\n\n return state;\n };\n\n // save session content every 30 seconds\n setInterval(function () {\n var request = newWideRequest(),\n filse = [],\n fileTree = [],\n currentId = editors.getCurrentId(),\n currentFile = currentId ? editors.getCurrentPath() : \"\";\n\n editors.tabs.obj._$tabs.find(\"div\").each(function () {\n var $it = $(this);\n if ($it.find(\"span:eq(0)\").attr(\"title\") !== config.label.start_page) {\n filse.push($it.find(\"span:eq(0)\").attr(\"title\"));\n }\n });\n\n fileTree = tree.getOpenPaths();\n\n request.currentFile = currentFile; // current editor file\n request.fileTree = fileTree; // file tree expansion state\n request.files = filse; // editor tabs\n\n\n request.layout = {\n \"side\": {\n \"size\": windows.outerLayout.west.state.size,\n \"state\": getLayoutState(windows.outerLayout.west.state)\n },\n \"sideRight\": {\n \"size\": windows.innerLayout.east.state.size,\n \"state\": getLayoutState(windows.innerLayout.east.state)\n },\n \"bottom\": {\n \"size\": windows.innerLayout.south.state.size,\n \"state\": getLayoutState(windows.innerLayout.south.state)\n }\n };\n\n $.ajax({\n type: 'POST',\n url: '/session/save',\n data: JSON.stringify(request),\n dataType: \"json\",\n success: function (result) {\n }\n });\n }, 30000);\n },\n restore: function () {\n if (!config.latestSessionContent) {\n return;\n }\n\n var fileTree = config.latestSessionContent.fileTree,\n files = config.latestSessionContent.files,\n currentFile = config.latestSessionContent.currentFile,\n id = \"\",\n nodesToOpen = [];\n\n var nodes = tree.fileTree.transformToArray(tree.fileTree.getNodes());\n\n for (var i = 0, ii = nodes.length; i < ii; i++) {\n // expand tree\n for (var j = 0, jj = fileTree.length; j < jj; j++) {\n if (nodes[i].path === fileTree[j]) {\n // expand this node only if its parents are open\n var parents = tree.getAllParents(tree.fileTree.getNodeByTId(nodes[i].tId)),\n isOpen = true;\n for (var l = 0, max = parents.length; l < max; l++) {\n if (parents[l].open === false) {\n isOpen = false;\n }\n }\n if (isOpen) {\n tree.fileTree.expandNode(nodes[i], true, false, true);\n } else {\n // flag it is open\n nodes[i].open = true;\n }\n break;\n }\n }\n\n // open editors\n for (var k = 0, kk = files.length; k < kk; k++) {\n if (nodes[i].path === files[k]) {\n nodesToOpen.push(nodes[i]);\n break;\n }\n }\n\n if (nodes[i].path === currentFile) {\n id = nodes[i].path;\n\n // FIXME: 上面的展开是异步进行的,所以执行到这里的时候可能还没有展开完,导致定位不了可视区域\n tree.fileTree.selectNode(nodes[i]);\n wide.curNode = nodes[i];\n }\n }\n\n // handle the open sequence of editors\n for (var m = 0, mm = files.length; m < mm; m++) {\n for (var n = 0, nn = nodesToOpen.length; n < nn; n++) {\n if (nodesToOpen[n].path === files[m]) {\n tree.openFile(nodesToOpen[n]);\n break;\n }\n }\n }\n\n // set the current editor\n editors.tabs.setCurrent(id);\n for (var c = 0, max = editors.data.length; c < max; c++) {\n if (id === editors.data[c].id) {\n wide.curEditor = editors.data[c].editor;\n break;\n }\n } \n },\n _initWS: function () {\n // Used for session retention, server will release all resources of the session if this channel closed\n var sessionWS = new ReconnectingWebSocket(config.channel + '/session/ws?sid=' + config.wideSessionId);\n\n sessionWS.onopen = function () {\n var dateFormat = function (time, fmt) {\n var date = new Date(time);\n var dateObj = {\n \"M+\": date.getMonth() + 1,\n \"d+\": date.getDate(),\n \"h+\": date.getHours(),\n \"m+\": date.getMinutes(),\n \"s+\": date.getSeconds(),\n \"q+\": Math.floor((date.getMonth() + 3) / 3),\n \"S\": date.getMilliseconds()\n };\n if (/(y+)/.test(fmt))\n fmt = fmt.replace(RegExp.$1, (date.getFullYear() + \"\").substr(4 - RegExp.$1.length));\n for (var k in dateObj)\n if (new RegExp(\"(\" + k + \")\").test(fmt)) {\n fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1)\n ? (dateObj[k]) : ((\"00\" + dateObj[k]).substr((\"\" + dateObj[k]).length)));\n }\n return fmt;\n };\n\n var data = {type: \"Network\", severity: \"INFO\",\n message: \"Connected to server [sid=\" + config.wideSessionId + \"], \" + dateFormat(new Date().getTime(), 'yyyy-MM-dd hh:mm:ss')},\n $notification = $('.bottom-window-group .notification > table'),\n notificationHTML = '';\n\n notificationHTML += '