modified: static/js/session.js

modified:   static/js/windows.js
	gulpfile.js
	package.json
This commit is contained in:
Vanesssa 2015-12-08 21:08:37 +08:00
parent 6ed1c99b53
commit 43ad792460
3 changed files with 117 additions and 46 deletions

View File

@ -9,11 +9,11 @@
"GoFormat": "gofmt", "GoFormat": "gofmt",
"FontFamily": "Helvetica", "FontFamily": "Helvetica",
"FontSize": "13px", "FontSize": "13px",
"Theme": "default", "Theme": "dark",
"Keymap": "wide", "Keymap": "wide",
"Created": 1414080000000000000, "Created": 1414080000000000000,
"Updated": 1414080000000000000, "Updated": 1449477503396946400,
"Lived": 1414080000000000000, "Lived": 1449562842336881500,
"Editor": { "Editor": {
"FontFamily": "Consolas, 'Courier New', monospace", "FontFamily": "Consolas, 'Courier New', monospace",
"FontSize": "13px", "FontSize": "13px",
@ -23,13 +23,17 @@
}, },
"LatestSessionContent": { "LatestSessionContent": {
"FileTree": [ "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": "", "CurrentFile": "",
"FileTreeLayout": null, "SideLayout": null,
"EditorLayout": null, "EditorLayout": null,
"OutlineLayout": null, "SideRightLayout": null,
"BottomLayout": null "BottomLayout": null
} }
} }

View File

@ -14,10 +14,27 @@
* limitations under the License. * limitations under the License.
*/ */
/*
* @file session.
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 0.1.0.1, Dec 8, 2015
*/
var session = { var session = {
init: function () { init: function () {
this._initWS(); 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 // save session content every 30 seconds
setInterval(function () { setInterval(function () {
var request = newWideRequest(), var request = newWideRequest(),
@ -39,6 +56,22 @@ var session = {
request.fileTree = fileTree; // file tree expansion state request.fileTree = fileTree; // file tree expansion state
request.files = filse; // editor tabs 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({ $.ajax({
type: 'POST', type: 'POST',
url: config.context + '/session/save', url: config.context + '/session/save',
@ -118,7 +151,7 @@ var session = {
wide.curEditor = editors.data[c].editor; wide.curEditor = editors.data[c].editor;
break; break;
} }
} }
}, },
_initWS: function () { _initWS: function () {
// Used for session retention, server will release all resources of the session if this channel closed // Used for session retention, server will release all resources of the session if this channel closed
@ -193,7 +226,7 @@ var session = {
break; break;
case 'remove-file': case 'remove-file':
case 'rename-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); tree.fileTree.removeNode(node);
var nodes = tree.fileTree.transformToArray(node); var nodes = tree.fileTree.transformToArray(node);

View File

@ -18,13 +18,33 @@
* @file windows. * @file windows.
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 0.1.0.0, Dec 6, 2015 * @version 0.1.1.0, Dec 8, 2015
*/ */
var windows = { var windows = {
isMaxEditor: false, isMaxEditor: false,
outerLayout: {}, outerLayout: {},
innerLayout: {}, innerLayout: {},
init: function () { 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({ this.outerLayout = $('body').layout({
north__paneSelector: ".menu", north__paneSelector: ".menu",
center__paneSelector: ".content", center__paneSelector: ".content",
@ -45,6 +65,7 @@ var windows = {
} }
}, },
west: { west: {
size: layout.side.size,
paneSelector: ".side", paneSelector: ".side",
togglerLength_open: 0, togglerLength_open: 0,
togglerLength_closed: 15, togglerLength_closed: 15,
@ -55,7 +76,8 @@ var windows = {
togglerClass: "ico-restore", togglerClass: "ico-restore",
togglerTip_open: config.label.min, togglerTip_open: config.label.min,
togglerTip_closed: config.label.restore_side, 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" paneSelector: ".edit-panel"
}, },
east: { east: {
size: layout.sideRight.size,
paneSelector: ".side-right", paneSelector: ".side-right",
togglerLength_open: 0, togglerLength_open: 0,
togglerLength_closed: 15, togglerLength_closed: 15,
@ -85,9 +108,11 @@ var windows = {
togglerClass: "ico-restore", togglerClass: "ico-restore",
togglerTip_open: config.label.min, togglerTip_open: config.label.min,
togglerTip_closed: config.label.restore_outline, togglerTip_closed: config.label.restore_outline,
resizerTip: config.label.resize resizerTip: config.label.resize,
initClosed: (layout.sideRight.state === 'min')
}, },
south: { south: {
size: layout.bottom.size,
paneSelector: ".bottom-window-group", paneSelector: ".bottom-window-group",
togglerLength_open: 0, togglerLength_open: 0,
togglerLength_closed: 15, togglerLength_closed: 15,
@ -99,6 +124,7 @@ var windows = {
togglerTip_open: config.label.min, togglerTip_open: config.label.min,
togglerTip_closed: config.label.restore_bottom, togglerTip_closed: config.label.restore_bottom,
resizerTip: config.label.resize, resizerTip: config.label.resize,
initClosed: (layout.bottom.state === 'min'),
ondrag_end: function (type, pane) { ondrag_end: function (type, pane) {
windows.refreshEditor(pane, 'drag'); windows.refreshEditor(pane, 'drag');
}, },
@ -121,6 +147,16 @@ var windows = {
this.innerLayout.addCloseBtn(".side-right .ico-min", "east"); this.innerLayout.addCloseBtn(".side-right .ico-min", "east");
this.innerLayout.addCloseBtn(".bottom-window-group .ico-min", "south"); 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 () { $(".toolbars .ico-max").click(function () {
windows.toggleEditor(); windows.toggleEditor();
}); });
@ -130,15 +166,30 @@ var windows = {
}); });
$(".bottom-window-group .tabs").dblclick(function () { $(".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 () { $(".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 () { $(".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()); $('.bottom-window-group .search').height($('.bottom-window-group .tabs-panel').height());
@ -147,38 +198,22 @@ var windows = {
}); });
}, },
toggleBottom: function () { maxBottom: function ($it) {
var $it = $(".bottom-window-group"); $it.data('height', $it.height()).addClass("bottom-window-group-max").find('.ico-min').hide();
windows.outerLayout.hide('west');
if ($it.hasClass("bottom-window-group-max")) { windows.innerLayout.hide('east');
windows.restoreBottom(); windows.innerLayout.sizePane('south', $('.content').height());
} 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());
}
}, },
toggleSide: function () { maxSide: function ($it) {
var $it = $(".side"); $it.data('width', $it.width()).addClass("side-max").find('.ico-min').hide();
if ($it.hasClass("side-max")) { $('.content').hide();
windows.restoreSide(); windows.outerLayout.sizePane('west', $('body').width());
} else {
$it.data('width', $it.width()).addClass("side-max").find('.ico-min').hide();
$('.content').hide();
windows.outerLayout.sizePane('west', $('body').width());
}
}, },
toggleSideRight: function () { maxSideRight: function ($it) {
var $it = $(".side-right"); $it.addClass("side-right-max").data('width', $it.width()).find('.ico-min').hide();
if ($it.hasClass("side-right-max")) { windows.outerLayout.hide('west');
windows.restoreSideRight(); windows.innerLayout.hide('south');
} else { windows.innerLayout.sizePane('east', $('body').width());
$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 () { toggleEditor: function () {
var $it = $(".toolbars .font-ico"); 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); $(".toolbars .font-ico").addClass('ico-max').removeClass('ico-restore').attr('title', config.label.max_editor);
}, },
refreshEditor: function (pane, type) { refreshEditor: function (pane, type) {
console.log(type)
var editorDatas = editors.data, var editorDatas = editors.data,
height = $('.content').height() - pane.height() - 24; height = $('.content').height() - pane.height() - 24;
switch (type) { switch (type) {