wide/static/js/windows.js

325 lines
11 KiB
JavaScript
Raw Normal View History

2015-01-01 05:06:33 +03:00
/*
2015-01-18 08:59:10 +03:00
* Copyright (c) 2014-2015, b3log.org
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
2014-09-26 11:39:13 +04:00
var windows = {
2014-10-22 09:38:52 +04:00
isMaxEditor: false,
2014-09-26 11:39:13 +04:00
init: function () {
2015-01-01 17:15:54 +03:00
// bottom windows
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(1)").click(function () {
windows.restoreBottom();
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(0)").css("display") === "none"
&& $(".footer .ico-restore:eq(2)").css("display") === "none") {
2014-09-26 11:39:13 +04:00
$(".toolbars .ico-restore").removeClass("ico-restore").addClass("ico-max")
.attr({
"title": config.label.max_editor,
"onclick": "windows.maxEditor()"
});
}
});
$(".bottom-window-group .ico-min").click(function () {
windows.minBottom();
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(0)").css("display") === "inline"
&& $(".footer .ico-restore:eq(2)").css("display") === "inline") {
2014-09-26 11:39:13 +04:00
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
}
});
$(".bottom-window-group .tabs").dblclick(function () {
windows.maxBottom();
});
2015-01-01 17:15:54 +03:00
// side
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(0)").click(function () {
windows.restoreSide();
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(1)").css("display") === "none"
&& $(".footer .ico-restore:eq(2)").css("display") === "none") {
2014-09-26 11:39:13 +04:00
$(".toolbars .ico-restore").removeClass("ico-restore").addClass("ico-max")
.attr({
"title": config.label.max_editor,
"onclick": "windows.maxEditor()"
});
}
});
$(".side .ico-min").click(function () {
windows.minSide();
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(1)").css("display") === "inline"
&& $(".footer .ico-restore:eq(2)").css("display") === "inline") {
2014-09-26 11:39:13 +04:00
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
}
});
$(".side .tabs").dblclick(function () {
windows.maxSide();
});
2015-01-01 17:15:54 +03:00
// side right
$(".footer .ico-restore:eq(2)").click(function () {
windows.restoreSideRight();
if ($(".footer .ico-restore:eq(1)").css("display") === "none"
&& $(".footer .ico-restore:eq(0)").css("display") === "none") {
$(".toolbars .ico-restore").removeClass("ico-restore").addClass("ico-max")
.attr({
"title": config.label.max_editor,
"onclick": "windows.maxEditor()"
});
}
});
$(".side-right .ico-min").click(function () {
windows.minSideRight();
if ($(".footer .ico-restore:eq(1)").css("display") === "inline"
&& $(".footer .ico-restore:eq(0)").css("display") === "inline") {
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
}
});
$(".side-right .tabs").dblclick(function () {
windows.maxSideRight();
});
2014-09-26 11:39:13 +04:00
$(window).click(function (event) {
if ($(event.target).closest(".footer").length === 1
2014-09-26 12:41:25 +04:00
|| $(event.target).closest(".bottom-window-group").length === 1
2014-10-23 07:50:28 +04:00
|| $(event.target).closest(".toolbars").length === 1
2015-01-01 17:15:54 +03:00
|| $(event.target).closest(".side").length === 1
|| $(event.target).closest(".side-right").length === 1) {
2014-12-18 18:04:41 +03:00
} else {
windows.clearFloat();
2014-09-26 11:39:13 +04:00
}
});
},
maxBottom: function () {
var $it = $(".bottom-window-group");
if ($it.hasClass("bottom-window-group-max")) {
windows.restoreBottom();
2014-09-26 12:41:25 +04:00
if ($(".side").css("left") !== "0px" && $(".side").css("left") !== "auto") {
$it.css({
"left": "0px",
"width": "100%"
});
2014-09-26 11:39:13 +04:00
}
} else {
$it.attr("style", "");
var bottomH = $(".content").height();
2014-12-01 12:15:54 +03:00
$(".bottom-window-group > .tabs-panel > div > div").height(bottomH - $it.children(".tabs").height());
2014-09-26 11:39:13 +04:00
$it.addClass("bottom-window-group-max");
}
},
maxSide: function () {
var $it = $(".side");
if ($it.hasClass("side-max")) {
windows.restoreSide();
} else {
$it.addClass("side-max");
}
},
2015-01-01 17:15:54 +03:00
maxSideRight: function () {
var $it = $(".side-right");
if ($it.hasClass("side-right-max")) {
windows.restoreSideRight();
} else {
$it.addClass("side-right-max");
2015-01-02 13:14:58 +03:00
$(".side-right > .tabs-panel > div").height($(".content").height() - $it.children(".tabs").height());
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");
$it.removeClass("bottom-window-group-max").attr("style", "");
var bottomH = $it.height();
2014-09-26 11:39:13 +04:00
2014-12-01 12:15:54 +03:00
$(".bottom-window-group > .tabs-panel > div > div").height(bottomH - $it.children(".tabs").height());
2014-09-26 11:39:13 +04:00
2014-09-26 12:41:25 +04:00
$it.animate({
2014-09-26 11:39:13 +04:00
"top": "70%"
}, function () {
2015-01-01 17:15:54 +03:00
$(".edit-panel, .side-right").css("height", "70%");
2014-09-26 11:39:13 +04:00
2014-11-07 05:51:55 +03:00
var editorDatas = editors.data,
height = $(".edit-panel").height() - $(".edit-panel .tabs").height();
2014-09-26 11:39:13 +04:00
for (var i = 0, ii = editorDatas.length; i < ii; i++) {
2014-11-07 05:51:55 +03:00
editorDatas[i].editor.setSize("100%", height);
2014-09-26 11:39:13 +04:00
}
2015-01-28 11:21:35 +03:00
$("#startPage").height(height - 100);
$it.show();
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(1)").hide();
});
if ($(".footer .ico-restore:eq(0)").css("display") === "inline") {
// 当文件树最小化时
$it.css({
"width": "100%",
"left": "0"
});
}
2014-09-26 11:39:13 +04:00
},
restoreSide: function () {
$(".side").animate({
"left": "0"
}, function () {
$(".edit-panel, .bottom-window-group").css({
"left": "20%",
"width": "80%"
});
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(2)").css("display") === "inline") {
// 当outline最小化时
$(".edit-panel").css("width", "80%");
} else {
$(".edit-panel").css("width", "60%");
}
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(0)").hide();
}).removeClass("side-max");
},
2015-01-01 17:15:54 +03:00
restoreSideRight: function () {
$(".side-right").animate({
"right": "0"
}, function () {
if ($(".footer .ico-restore:eq(0)").css("display") === "inline") {
// 当文件树最小化时
$(".edit-panel").css("width", "80%");
} else {
$(".edit-panel").css("width", "60%");
}
$(".footer .ico-restore:eq(2)").hide();
2015-01-02 13:14:58 +03:00
$(".side-right > .tabs-panel > div").height($('.side-right').height()
- $(this).children(".tabs").height());
2015-01-01 17:15:54 +03:00
}).removeClass("side-right-max");
},
2014-09-26 11:39:13 +04:00
minBottom: function () {
2015-01-01 17:15:54 +03:00
$(".edit-panel, .side-right").css("height", "100%");
2014-09-26 11:39:13 +04:00
2014-11-07 05:51:55 +03:00
var editorDatas = editors.data,
height = $(".content").height() - $(".edit-panel .tabs").height();
2014-09-26 11:39:13 +04:00
for (var i = 0, ii = editorDatas.length; i < ii; i++) {
2014-11-07 05:51:55 +03:00
editorDatas[i].editor.setSize("100%", height);
2014-09-26 11:39:13 +04:00
}
2015-01-28 11:21:35 +03:00
$("#startPage").height(height - 100);
$(".bottom-window-group").css("top", "100%").hide();
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(1)").show();
},
minSide: function () {
$(".side").css("left", "-20%").removeClass("side-max");
2015-01-01 17:15:54 +03:00
var width = '80%';
if ($(".footer .ico-restore:eq(2)").css("display") === "inline") {
// 当 outline 最小化时
width = '100%';
}
2014-09-26 11:39:13 +04:00
$(".edit-panel, .bottom-window-group").css({
"left": "0",
2015-01-01 17:15:54 +03:00
"width": width
});
$(".bottom-window-group").css({
"left": "0",
"width": '100%'
2014-09-26 11:39:13 +04:00
});
2015-01-01 17:15:54 +03:00
2014-09-26 11:39:13 +04:00
$(".footer .ico-restore:eq(0)").show();
},
2015-01-01 17:15:54 +03:00
minSideRight: function () {
$(".side-right").css("right", "-20%");
$(".footer .ico-restore:eq(2)").show();
if ($(".footer .ico-restore:eq(0)").css("display") === "inline") {
// 当文件树最小化时
$(".edit-panel").css("width", "100%");
} else {
$(".edit-panel").css("width", "80%");
}
},
2014-09-26 11:39:13 +04:00
maxEditor: function () {
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
windows.minBottom();
windows.minSide();
2015-01-01 17:15:54 +03:00
windows.minSideRight();
if (wide.curEditor) {
wide.curEditor.focus();
}
2014-10-22 09:38:52 +04:00
windows.isMaxEditor = true;
2014-09-26 11:39:13 +04:00
},
restoreEditor: function () {
$(".toolbars .ico-restore").removeClass("ico-restore").addClass("ico-max")
.attr({
"title": config.label.max_editor,
"onclick": "windows.maxEditor()"
});
windows.restoreBottom();
windows.restoreSide();
2015-01-01 17:15:54 +03:00
windows.restoreSideRight();
if (wide.curEditor) {
wide.curEditor.focus();
}
2014-10-22 09:38:52 +04:00
windows.isMaxEditor = false;
2014-09-26 11:39:13 +04:00
},
2014-09-26 12:41:25 +04:00
clearFloat: function () {
if ($(".footer .ico-restore:eq(0)").css("display") === "inline") {
// 当文件树最小化时
windows.minSide();
2014-09-26 11:39:13 +04:00
}
2014-09-26 12:41:25 +04:00
if ($(".footer .ico-restore:eq(1)").css("display") === "inline") {
// 当底部最小化时
windows.minBottom();
2014-09-26 11:39:13 +04:00
}
2015-01-01 17:15:54 +03:00
if ($(".footer .ico-restore:eq(2)").css("display") === "inline") {
// 当 outline 最小化时
windows.minSideRight();
}
2014-09-26 11:39:13 +04:00
},
2014-09-26 12:41:25 +04:00
flowBottom: function () {
if ($(".footer .ico-restore:eq(1)").css("display") === "inline") {
// 当底部树最小化时
$(".bottom-window-group").css({
"top": "70%",
"left": "0px",
"width": "100%",
"z-index": "8"
}).show();
2014-09-26 12:41:25 +04:00
}
2014-09-26 11:39:13 +04:00
}
};