From 43ad792460138d4ddacf52bf5248b66cf1707ff1 Mon Sep 17 00:00:00 2001 From: Vanesssa Date: Tue, 8 Dec 2015 21:08:37 +0800 Subject: [PATCH] modified: static/js/session.js modified: static/js/windows.js gulpfile.js package.json --- conf/users/admin.json | 18 ++++--- static/js/session.js | 37 ++++++++++++++- static/js/windows.js | 108 +++++++++++++++++++++++++++--------------- 3 files changed, 117 insertions(+), 46 deletions(-) diff --git a/conf/users/admin.json b/conf/users/admin.json index a715e0c..e229e07 100644 --- a/conf/users/admin.json +++ b/conf/users/admin.json @@ -9,11 +9,11 @@ "GoFormat": "gofmt", "FontFamily": "Helvetica", "FontSize": "13px", - "Theme": "default", + "Theme": "dark", "Keymap": "wide", "Created": 1414080000000000000, - "Updated": 1414080000000000000, - "Lived": 1414080000000000000, + "Updated": 1449477503396946400, + "Lived": 1449562842336881500, "Editor": { "FontFamily": "Consolas, 'Courier New', monospace", "FontSize": "13px", @@ -23,13 +23,17 @@ }, "LatestSessionContent": { "FileTree": [ + "D:/Code/GoGoGo/src", + "D:/Code/GoGoGo/src/github.com", + "D:/Code/GoGoGo/src/github.com/b3log", + "D:/Code/GoGoGo/src/github.com/b3log/wide", + "E:\\go\\src" ], - "Files": [ - ], + "Files": [], "CurrentFile": "", - "FileTreeLayout": null, + "SideLayout": null, "EditorLayout": null, - "OutlineLayout": null, + "SideRightLayout": null, "BottomLayout": null } } \ No newline at end of file diff --git a/static/js/session.js b/static/js/session.js index 4f34066..af9b4a7 100644 --- a/static/js/session.js +++ b/static/js/session.js @@ -14,10 +14,27 @@ * limitations under the License. */ +/* + * @file session. + * + * @author Liyuan Li + * @version 0.1.0.1, Dec 8, 2015 + */ var session = { init: function () { this._initWS(); + var getLayoutState = function (paneState) { + var state = 'normal'; + if (paneState.isClosed) { + state = 'min'; + } else if (paneState.size >= $('body').width()) { + state = 'max'; + } + + return state; + }; + // save session content every 30 seconds setInterval(function () { var request = newWideRequest(), @@ -39,6 +56,22 @@ var session = { request.fileTree = fileTree; // file tree expansion state request.files = filse; // editor tabs + + request.layout = { + "side": { + "size": windows.outerLayout.west.state.size, + "state": getLayoutState(windows.outerLayout.west.state) + }, + "sideRight": { + "size": windows.innerLayout.east.state.size, + "state": getLayoutState(windows.innerLayout.east.state) + }, + "bottom": { + "size": windows.innerLayout.south.state.size, + "state": getLayoutState(windows.innerLayout.south.state) + } + }; + $.ajax({ type: 'POST', url: config.context + '/session/save', @@ -118,7 +151,7 @@ var session = { wide.curEditor = editors.data[c].editor; break; } - } + } }, _initWS: function () { // Used for session retention, server will release all resources of the session if this channel closed @@ -193,7 +226,7 @@ var session = { break; case 'remove-file': case 'rename-file': - var node = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.path)); + var node = tree.fileTree.getNodeByTId(tree.getTIdByPath(data.path)); tree.fileTree.removeNode(node); var nodes = tree.fileTree.transformToArray(node); diff --git a/static/js/windows.js b/static/js/windows.js index dee1079..145b849 100644 --- a/static/js/windows.js +++ b/static/js/windows.js @@ -18,13 +18,33 @@ * @file windows. * * @author Liyuan Li - * @version 0.1.0.0, Dec 6, 2015 + * @version 0.1.1.0, Dec 8, 2015 */ var windows = { isMaxEditor: false, outerLayout: {}, innerLayout: {}, init: function () { + var layout = {}; + if (!config.latestSessionContent) { + config.latestSessionContent.Layout = { + "side": { + "size": 200, + "state": 'normal' + }, + "sideRight": { + "size": 200, + "state": 'normal' + }, + "bottom": { + "size": 100, + "state": 'normal' + } + }; + } + layout = config.latestSessionContent.Layout; + + this.outerLayout = $('body').layout({ north__paneSelector: ".menu", center__paneSelector: ".content", @@ -45,6 +65,7 @@ var windows = { } }, west: { + size: layout.side.size, paneSelector: ".side", togglerLength_open: 0, togglerLength_closed: 15, @@ -55,7 +76,8 @@ var windows = { togglerClass: "ico-restore", togglerTip_open: config.label.min, togglerTip_closed: config.label.restore_side, - resizerTip: config.label.resize + resizerTip: config.label.resize, + initClosed: (layout.side.state === 'min') } }); @@ -75,6 +97,7 @@ var windows = { paneSelector: ".edit-panel" }, east: { + size: layout.sideRight.size, paneSelector: ".side-right", togglerLength_open: 0, togglerLength_closed: 15, @@ -85,9 +108,11 @@ var windows = { togglerClass: "ico-restore", togglerTip_open: config.label.min, togglerTip_closed: config.label.restore_outline, - resizerTip: config.label.resize + resizerTip: config.label.resize, + initClosed: (layout.sideRight.state === 'min') }, south: { + size: layout.bottom.size, paneSelector: ".bottom-window-group", togglerLength_open: 0, togglerLength_closed: 15, @@ -99,6 +124,7 @@ var windows = { togglerTip_open: config.label.min, togglerTip_closed: config.label.restore_bottom, resizerTip: config.label.resize, + initClosed: (layout.bottom.state === 'min'), ondrag_end: function (type, pane) { windows.refreshEditor(pane, 'drag'); }, @@ -121,6 +147,16 @@ var windows = { this.innerLayout.addCloseBtn(".side-right .ico-min", "east"); this.innerLayout.addCloseBtn(".bottom-window-group .ico-min", "south"); + if (layout.side.state === 'max') { + windows.maxSide(); + } + if (layout.sideRight.state === 'max') { + windows.maxSideRight(); + } + if (layout.bottom.state === 'max') { + windows.maxBottom(); + } + $(".toolbars .ico-max").click(function () { windows.toggleEditor(); }); @@ -130,15 +166,30 @@ var windows = { }); $(".bottom-window-group .tabs").dblclick(function () { - windows.toggleBottom(); + var $it = $(".bottom-window-group"); + if ($it.hasClass("bottom-window-group-max")) { + windows.restoreBottom(); + } else { + windows.maxBottom($it); + } }); $(".side .tabs").dblclick(function () { - windows.toggleSide(); + var $it = $(".side"); + if ($it.hasClass("side-max")) { + windows.restoreSide(); + } else { + windows.restoreSide($it); + } }); $(".side-right .tabs").dblclick(function () { - windows.toggleSideRight(); + var $it = $(".side-right"); + if ($it.hasClass("side-right-max")) { + windows.restoreSideRight(); + } else { + windows.maxSideRight($it); + } }); $('.bottom-window-group .search').height($('.bottom-window-group .tabs-panel').height()); @@ -147,38 +198,22 @@ var windows = { }); }, - toggleBottom: function () { - var $it = $(".bottom-window-group"); - - if ($it.hasClass("bottom-window-group-max")) { - windows.restoreBottom(); - } else { - $it.data('height', $it.height()).addClass("bottom-window-group-max").find('.ico-min').hide(); - windows.outerLayout.hide('west'); - windows.innerLayout.hide('east'); - windows.innerLayout.sizePane('south', $('.content').height()); - } + maxBottom: function ($it) { + $it.data('height', $it.height()).addClass("bottom-window-group-max").find('.ico-min').hide(); + windows.outerLayout.hide('west'); + windows.innerLayout.hide('east'); + windows.innerLayout.sizePane('south', $('.content').height()); }, - toggleSide: function () { - var $it = $(".side"); - if ($it.hasClass("side-max")) { - windows.restoreSide(); - } else { - $it.data('width', $it.width()).addClass("side-max").find('.ico-min').hide(); - $('.content').hide(); - windows.outerLayout.sizePane('west', $('body').width()); - } + maxSide: function ($it) { + $it.data('width', $it.width()).addClass("side-max").find('.ico-min').hide(); + $('.content').hide(); + windows.outerLayout.sizePane('west', $('body').width()); }, - toggleSideRight: function () { - var $it = $(".side-right"); - if ($it.hasClass("side-right-max")) { - windows.restoreSideRight(); - } else { - $it.addClass("side-right-max").data('width', $it.width()).find('.ico-min').hide(); - windows.outerLayout.hide('west'); - windows.innerLayout.hide('south'); - windows.innerLayout.sizePane('east', $('body').width()); - } + maxSideRight: function ($it) { + $it.addClass("side-right-max").data('width', $it.width()).find('.ico-min').hide(); + windows.outerLayout.hide('west'); + windows.innerLayout.hide('south'); + windows.innerLayout.sizePane('east', $('body').width()); }, toggleEditor: function () { var $it = $(".toolbars .font-ico"); @@ -220,7 +255,6 @@ var windows = { $(".toolbars .font-ico").addClass('ico-max').removeClass('ico-restore').attr('title', config.label.max_editor); }, refreshEditor: function (pane, type) { - console.log(type) var editorDatas = editors.data, height = $('.content').height() - pane.height() - 24; switch (type) {