wide/static/js/windows.js

231 lines
7.7 KiB
JavaScript
Raw Normal View History

2014-11-12 18:13:14 +03:00
/*
* Copyright (c) 2014, B3log
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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-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 () {
$(".footer .ico-restore:eq(1)").click(function () {
windows.restoreBottom();
if ($(".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()"
});
}
});
$(".bottom-window-group .ico-min").click(function () {
windows.minBottom();
if ($(".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()"
});
}
});
$(".bottom-window-group .tabs").dblclick(function () {
windows.maxBottom();
});
$(".footer .ico-restore:eq(0)").click(function () {
windows.restoreSide();
if ($(".footer .ico-restore:eq(1)").css("display") === "none") {
$(".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();
if ($(".footer .ico-restore:eq(1)").css("display") === "inline") {
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
}
});
$(".side .tabs").dblclick(function () {
windows.maxSide();
});
$(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
2014-09-26 12:41:25 +04:00
|| $(event.target).closest(".side").length === 1) {
2014-09-26 11:39:13 +04:00
return false;
}
2014-09-26 12:41:25 +04:00
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-10-12 08:15:51 +04:00
$(".bottom-window-group > .tabs-panel > div > div").height(bottomH - 20);
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");
}
},
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-10-12 08:15:51 +04:00
$(".bottom-window-group > .tabs-panel > div > div").height(bottomH - 20);
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 () {
$(".edit-panel").css("height", "70%");
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
}
$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%"
});
$(".footer .ico-restore:eq(0)").hide();
}).removeClass("side-max");
},
minBottom: function () {
$(".edit-panel").css("height", "100%");
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
}
$(".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");
$(".edit-panel, .bottom-window-group").css({
"left": "0",
"width": "100%"
});
$(".footer .ico-restore:eq(0)").show();
},
maxEditor: function () {
$(".toolbars .ico-max").removeClass("ico-max").addClass("ico-restore")
.attr({
"title": config.label.restore_editor,
"onclick": "windows.restoreEditor()"
});
windows.minBottom();
windows.minSide();
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();
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
}
},
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 11:39:13 +04:00
2014-09-26 12:41:25 +04:00
if ($(".footer .ico-restore:eq(0)").css("display") === "inline") {
// 当文件最小化时
$(".side").css("left", "-20%");
}
}
2014-09-26 11:39:13 +04:00
}
};