2015-01-01 05:06:33 +03:00
|
|
|
/*
|
2017-03-14 17:40:45 +03:00
|
|
|
* Copyright (c) 2014-2017, b3log.org & hacpai.com
|
2015-01-01 05:06:33 +03:00
|
|
|
*
|
2014-11-12 18:13:14 +03:00
|
|
|
* 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
|
2015-01-01 05:06:33 +03:00
|
|
|
*
|
2014-11-12 18:13:14 +03:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-01-01 05:06:33 +03:00
|
|
|
*
|
2014-11-12 18:13:14 +03:00
|
|
|
* 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.
|
2014-12-18 18:04:41 +03:00
|
|
|
*/
|
2014-11-12 18:13:14 +03:00
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
/*
|
2015-12-08 18:48:16 +03:00
|
|
|
* @file windows.js
|
2015-12-05 19:27:15 +03:00
|
|
|
*
|
|
|
|
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
|
2015-12-08 18:48:16 +03:00
|
|
|
* @author <a href="http://88250.b3log.org">Liang Ding</a>
|
2016-02-16 16:24:37 +03:00
|
|
|
* @version 1.1.2.2, Feb 16, 2016
|
2015-12-05 19:27:15 +03:00
|
|
|
*/
|
2014-09-26 11:39:13 +04:00
|
|
|
var windows = {
|
2014-10-22 09:38:52 +04:00
|
|
|
isMaxEditor: false,
|
2015-12-05 19:27:15 +03:00
|
|
|
outerLayout: {},
|
|
|
|
innerLayout: {},
|
2014-09-26 11:39:13 +04:00
|
|
|
init: function () {
|
2016-02-16 16:24:37 +03:00
|
|
|
if (!config.latestSessionContent) {
|
|
|
|
config.latestSessionContent = {
|
|
|
|
"fileTree": [],
|
|
|
|
"files": [],
|
|
|
|
"currentFile": "",
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:48:16 +03:00
|
|
|
if (!config.latestSessionContent.layout) {
|
|
|
|
config.latestSessionContent.layout = {
|
2015-12-08 16:08:37 +03:00
|
|
|
"side": {
|
|
|
|
"size": 200,
|
|
|
|
"state": 'normal'
|
|
|
|
},
|
|
|
|
"sideRight": {
|
|
|
|
"size": 200,
|
|
|
|
"state": 'normal'
|
|
|
|
},
|
|
|
|
"bottom": {
|
|
|
|
"size": 100,
|
|
|
|
"state": 'normal'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-12-08 18:48:16 +03:00
|
|
|
var layout = config.latestSessionContent.layout;
|
2015-12-08 16:08:37 +03:00
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
this.outerLayout = $('body').layout({
|
|
|
|
north__paneSelector: ".menu",
|
|
|
|
center__paneSelector: ".content",
|
|
|
|
south__paneSelector: ".footer",
|
|
|
|
north__size: 22,
|
|
|
|
south__size: 19,
|
2015-12-06 17:54:30 +03:00
|
|
|
spacing_open: 2,
|
2015-12-05 19:27:15 +03:00
|
|
|
north__spacing_open: 0,
|
|
|
|
south__spacing_open: 0,
|
|
|
|
defaults: {
|
|
|
|
fxSpeed_open: 300,
|
|
|
|
fxSpeed_close: 100,
|
|
|
|
fxSettings_close: {
|
|
|
|
easing: "easeOutQuint"
|
|
|
|
},
|
|
|
|
fxSettings_open: {
|
|
|
|
easing: "easeInQuint"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
west: {
|
2015-12-08 16:08:37 +03:00
|
|
|
size: layout.side.size,
|
2015-12-05 19:27:15 +03:00
|
|
|
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,
|
2015-12-08 16:08:37 +03:00
|
|
|
resizerTip: config.label.resize,
|
|
|
|
initClosed: (layout.side.state === 'min')
|
2014-09-26 11:39:13 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
this.innerLayout = $('div.content').layout({
|
2015-12-06 17:54:30 +03:00
|
|
|
spacing_open: 2,
|
2015-12-05 19:27:15 +03:00
|
|
|
defaults: {
|
|
|
|
fxSpeed_open: 300,
|
|
|
|
fxSpeed_close: 100,
|
|
|
|
fxSettings_close: {
|
|
|
|
easing: "easeOutQuint"
|
|
|
|
},
|
|
|
|
fxSettings_open: {
|
|
|
|
easing: "easeInQuint"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
center: {
|
|
|
|
paneSelector: ".edit-panel"
|
|
|
|
},
|
|
|
|
east: {
|
2015-12-08 16:08:37 +03:00
|
|
|
size: layout.sideRight.size,
|
2015-12-05 19:27:15 +03:00
|
|
|
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,
|
2015-12-08 16:08:37 +03:00
|
|
|
resizerTip: config.label.resize,
|
|
|
|
initClosed: (layout.sideRight.state === 'min')
|
2015-12-05 19:27:15 +03:00
|
|
|
},
|
|
|
|
south: {
|
2015-12-08 16:08:37 +03:00
|
|
|
size: layout.bottom.size,
|
2015-12-05 19:27:15 +03:00
|
|
|
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,
|
2015-12-08 16:08:37 +03:00
|
|
|
initClosed: (layout.bottom.state === 'min'),
|
2015-12-05 19:27:15 +03:00
|
|
|
ondrag_end: function (type, pane) {
|
|
|
|
windows.refreshEditor(pane, 'drag');
|
|
|
|
},
|
|
|
|
onresize_end: function (type, pane) {
|
|
|
|
windows.refreshEditor(pane, 'resize');
|
|
|
|
},
|
|
|
|
onclose_end: function (type, pane) {
|
|
|
|
windows.refreshEditor(pane, 'close');
|
|
|
|
},
|
|
|
|
onopen_end: function (type, pane) {
|
|
|
|
windows.refreshEditor(pane, 'open');
|
|
|
|
},
|
|
|
|
onshow_end: function (type, pane) {
|
|
|
|
windows.refreshEditor(pane, 'show');
|
|
|
|
}
|
2014-09-26 11:39:13 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
this.outerLayout.addCloseBtn(".side .ico-min", "west");
|
|
|
|
this.innerLayout.addCloseBtn(".side-right .ico-min", "east");
|
|
|
|
this.innerLayout.addCloseBtn(".bottom-window-group .ico-min", "south");
|
2014-09-26 11:39:13 +04:00
|
|
|
|
2015-12-08 16:08:37 +03:00
|
|
|
if (layout.side.state === 'max') {
|
|
|
|
windows.maxSide();
|
|
|
|
}
|
|
|
|
if (layout.sideRight.state === 'max') {
|
|
|
|
windows.maxSideRight();
|
|
|
|
}
|
|
|
|
if (layout.bottom.state === 'max') {
|
|
|
|
windows.maxBottom();
|
|
|
|
}
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$(".toolbars .ico-max").click(function () {
|
|
|
|
windows.toggleEditor();
|
2014-09-26 11:39:13 +04:00
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$(".edit-panel .tabs").on("dblclick", function () {
|
|
|
|
windows.toggleEditor();
|
2014-09-26 11:39:13 +04:00
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$(".bottom-window-group .tabs").dblclick(function () {
|
2015-12-08 16:08:37 +03:00
|
|
|
var $it = $(".bottom-window-group");
|
|
|
|
if ($it.hasClass("bottom-window-group-max")) {
|
|
|
|
windows.restoreBottom();
|
|
|
|
} else {
|
|
|
|
windows.maxBottom($it);
|
|
|
|
}
|
2015-01-01 17:15:54 +03:00
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$(".side .tabs").dblclick(function () {
|
2015-12-08 16:08:37 +03:00
|
|
|
var $it = $(".side");
|
|
|
|
if ($it.hasClass("side-max")) {
|
|
|
|
windows.restoreSide();
|
|
|
|
} else {
|
|
|
|
windows.restoreSide($it);
|
|
|
|
}
|
2015-01-01 17:15:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
$(".side-right .tabs").dblclick(function () {
|
2015-12-08 16:08:37 +03:00
|
|
|
var $it = $(".side-right");
|
|
|
|
if ($it.hasClass("side-right-max")) {
|
|
|
|
windows.restoreSideRight();
|
|
|
|
} else {
|
|
|
|
windows.maxSideRight($it);
|
|
|
|
}
|
2015-01-01 17:15:54 +03:00
|
|
|
});
|
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$('.bottom-window-group .search').height($('.bottom-window-group .tabs-panel').height());
|
|
|
|
$(window).resize(function () {
|
|
|
|
windows.refreshEditor($('.bottom-window-group'));
|
2014-09-26 11:39:13 +04:00
|
|
|
});
|
2015-12-05 19:27:15 +03:00
|
|
|
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
2015-12-14 16:21:45 +03:00
|
|
|
maxEditor: function () {
|
|
|
|
var $it = $(".toolbars .font-ico");
|
|
|
|
windows.outerLayout.close('west');
|
|
|
|
windows.innerLayout.close('south');
|
|
|
|
windows.innerLayout.close('east');
|
|
|
|
$it.removeClass('ico-max').addClass('ico-restore').attr('title', config.label.min);
|
|
|
|
windows.isMaxEditor = true;
|
|
|
|
},
|
2015-12-08 16:08:37 +03:00
|
|
|
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());
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
2015-12-08 16:08:37 +03:00
|
|
|
maxSide: function ($it) {
|
|
|
|
$it.data('width', $it.width()).addClass("side-max").find('.ico-min').hide();
|
|
|
|
$('.content').hide();
|
|
|
|
windows.outerLayout.sizePane('west', $('body').width());
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
2015-12-08 16:08:37 +03:00
|
|
|
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());
|
2015-12-05 19:27:15 +03:00
|
|
|
},
|
|
|
|
toggleEditor: function () {
|
|
|
|
var $it = $(".toolbars .font-ico");
|
|
|
|
if ($it.hasClass('ico-restore')) {
|
|
|
|
windows.restoreEditor();
|
|
|
|
} else {
|
2015-12-14 16:21:45 +03:00
|
|
|
windows.maxEditor();
|
2015-01-01 17:15:54 +03:00
|
|
|
}
|
|
|
|
},
|
2014-09-26 11:39:13 +04:00
|
|
|
restoreBottom: function () {
|
2014-09-26 12:41:25 +04:00
|
|
|
var $it = $(".bottom-window-group");
|
2015-12-05 19:27:15 +03:00
|
|
|
$it.removeClass("bottom-window-group-max").find('.ico-min').show();
|
|
|
|
windows.outerLayout.show('west');
|
|
|
|
windows.innerLayout.show('east');
|
|
|
|
windows.innerLayout.sizePane('south', $it.data('height'));
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
|
|
|
restoreSide: function () {
|
2015-12-05 19:27:15 +03:00
|
|
|
var $it = $(".side");
|
|
|
|
$it.removeClass("side-max").find('.ico-min').show();
|
|
|
|
$('.content').show();
|
|
|
|
windows.outerLayout.sizePane('west', $it.data('width'));
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
2015-01-01 17:15:54 +03:00
|
|
|
restoreSideRight: function () {
|
2015-12-05 19:27:15 +03:00
|
|
|
var $it = $(".side-right");
|
|
|
|
$it.removeClass("side-right-max").find('.ico-min').show();
|
|
|
|
windows.outerLayout.show('west');
|
|
|
|
windows.innerLayout.show('south');
|
|
|
|
windows.innerLayout.sizePane('east', $it.data('width'));
|
|
|
|
},
|
|
|
|
restoreEditor: function () {
|
|
|
|
windows.outerLayout.open('west');
|
|
|
|
windows.innerLayout.open('south');
|
|
|
|
windows.innerLayout.open('east');
|
|
|
|
windows.isMaxEditor = false;
|
|
|
|
$(".toolbars .font-ico").addClass('ico-max').removeClass('ico-restore').attr('title', config.label.max_editor);
|
2015-01-01 17:15:54 +03:00
|
|
|
},
|
2015-12-05 19:27:15 +03:00
|
|
|
refreshEditor: function (pane, type) {
|
|
|
|
var editorDatas = editors.data,
|
|
|
|
height = $('.content').height() - pane.height() - 24;
|
|
|
|
switch (type) {
|
|
|
|
case 'close':
|
|
|
|
height = $('.content').height() - 40;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2014-09-26 11:39:13 +04:00
|
|
|
}
|
2015-12-05 19:27:15 +03:00
|
|
|
for (var i = 0, ii = editorDatas.length; i < ii; i++) {
|
|
|
|
editorDatas[i].editor.setSize("100%", height);
|
2014-09-26 11:39:13 +04:00
|
|
|
}
|
2015-01-01 17:15:54 +03:00
|
|
|
|
2015-12-05 19:27:15 +03:00
|
|
|
$('.bottom-window-group .search').height($('.bottom-window-group .tabs-panel').height());
|
2014-09-26 11:39:13 +04:00
|
|
|
},
|
2014-09-26 12:41:25 +04:00
|
|
|
flowBottom: function () {
|
2015-12-13 17:21:45 +03:00
|
|
|
if (windows.innerLayout.south.state.isClosed) {
|
|
|
|
windows.innerLayout.slideOpen('south');
|
|
|
|
}
|
2014-09-26 11:39:13 +04:00
|
|
|
}
|
|
|
|
};
|