This commit is contained in:
Van 2014-09-03 17:49:03 +08:00
parent 515fcd85e1
commit 1daadb6e12
1 changed files with 62 additions and 51 deletions

View File

@ -1,5 +1,5 @@
var tree = { var tree = {
fileTree: {}, fileTree: undefined,
newFile: function() { newFile: function() {
$("#dirRMenu ul").hide(); $("#dirRMenu ul").hide();
var name = prompt("Name", ""); var name = prompt("Name", "");
@ -96,62 +96,23 @@ var tree = {
wide.curNode = treeNode; wide.curNode = treeNode;
if ("f" === treeNode.type) { // 如果右击了文件 if ("f" === treeNode.type) { // 如果右击了文件
$("#fileRMenu ul").show(); $("#fileRMenu ul").show();
fileRMenu.css({"top": event.clientY - 10 + "px", "left": event.clientX + "px", "display": "block"}); fileRMenu.css({
"top": event.clientY - 10 + "px",
"left": event.clientX + "px",
"display": "block"
});
} else { // 右击了目录 } else { // 右击了目录
$("#dirRMenu ul").show(); $("#dirRMenu ul").show();
dirRMenu.css({"top": event.clientY - 10 + "px", "left": event.clientX + "px", "display": "block"}); dirRMenu.css({
"top": event.clientY - 10 + "px",
"left": event.clientX + "px",
"display": "block"
});
} }
} }
}, },
onClick: function(event, treeId, treeNode, clickFlag) { onClick: function(event, treeId, treeNode, clickFlag) {
if (wide.curNode) { tree._onClick(treeNode);
var id = wide.curNode.tId;
if (id === treeNode.tId) {
// 再次点击当前选中节点
return false;
}
for (var i = 0, ii = editors.data.length; i < ii; i++) {
// 该节点文件已经打开
if (editors.data[i].id === treeNode.tId) {
editors.tabs.setCurrent(treeNode.tId);
wide.curNode = treeNode;
wide.curEditor = editors.data[i].editor;
return false;
}
}
}
wide.curNode = treeNode;
if ("f" === treeNode.type) { // 如果单击了文件
var request = {
path: treeNode.path
};
$.ajax({
type: 'POST',
url: '/file',
data: JSON.stringify(request),
dataType: "json",
success: function(data) {
if (!data.succ) {
alert(data.msg);
return false;
}
if ("img" === data.mode) { // 是图片文件的话新建 tab 打开
// 最好是开 tab但这个最终取决于浏览器设置
var w = window.open(data.path);
return false;
}
editors.newEditor(data);
}
});
}
} }
} }
}; };
@ -159,5 +120,55 @@ var tree = {
} }
} }
}); });
},
_onClick: function(treeNode) {
if (wide.curNode) {
var id = wide.curNode.tId;
if (id === treeNode.tId) {
// 再次点击当前选中节点
return false;
}
for (var i = 0, ii = editors.data.length; i < ii; i++) {
// 该节点文件已经打开
if (editors.data[i].id === treeNode.tId) {
editors.tabs.setCurrent(treeNode.tId);
wide.curNode = treeNode;
wide.curEditor = editors.data[i].editor;
return false;
}
}
}
wide.curNode = treeNode;
if ("f" === treeNode.type) { // 如果单击了文件
var request = {
path: treeNode.path
};
$.ajax({
type: 'POST',
url: '/file',
data: JSON.stringify(request),
dataType: "json",
success: function(data) {
if (!data.succ) {
alert(data.msg);
return false;
}
if ("img" === data.mode) { // 是图片文件的话新建 tab 打开
// 最好是开 tab但这个最终取决于浏览器设置
var w = window.open(data.path);
return false;
}
editors.newEditor(data);
}
});
}
} }
}; };