contexmenu dynamic

This commit is contained in:
iiuazz
2014-09-13 00:20:18 +08:00
parent d1f18b9476
commit 27dbd6552c
12 changed files with 118 additions and 142 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1152,6 +1152,7 @@ Note.copyNote = function(target, data, isShared) {
});
}
// 这里速度不慢, 很快
Note.getContextNotebooks = function(notebooks) {
var moves = [];
var copys = [];
@ -1166,9 +1167,12 @@ Note.getContextNotebooks = function(notebooks) {
move.items = mc[0];
copy.items = mc[1];
copy2.items = mc[2];
$.extend(move, {type: "group", width: 150});
$.extend(copy, {type: "group", width: 150});
$.extend(copy2, {type: "group", width: 150});
move.type = "group";
move.width = 150;
copy.type = "group";
copy.width = 150;
copy2.type = "group";
copy2.width = 150;
}
moves.push(move);
copys.push(copy);
@ -1187,6 +1191,7 @@ Note.initContextmenu = function() {
// 得到可移动的notebook
var notebooks = Notebook.everNotebooks;
var mc = self.getContextNotebooks(notebooks);
var notebooksMove = mc[0];
var notebooksCopy = mc[1];
self.notebooksCopy = mc[2];
@ -1269,6 +1274,7 @@ Note.initContextmenu = function() {
return this.id != "target3";
}
// 这里很慢!!
Note.contextmenu = $("#noteItemList .item-my").contextmenu(noteListMenu);
}

File diff suppressed because one or more lines are too long

View File

@ -95,14 +95,14 @@ Notebook.getTreeSetting = function(isSearch, isShare){
// 成为子节点, 那么只需要得到targetNode下所有的子结点即可
if(moveType == "inner") {
parentNode = targetNode;
// 在targetNode之前或之后,
// 那么: 1) 需要将该parentNode下所有的node重新排序即可; 2) treeNodes[0]为parentNode的子
} else {
parentNode = targetNode.getParentNode();
}
// 在targetNode之前或之后,
// 那么: 1) 需要将该parentNode下所有的node重新排序即可; 2) treeNodes[0]为parentNode的子
if(!parentNode) {
var nodes = treeObj.getNodes();
var nodes = treeObj.getNodes(); // 得到所有nodes
} else {
ajaxData.parentNotebookId = parentNode.NotebookId;
var nextLevel = parentNode.level+1;
@ -119,9 +119,13 @@ Notebook.getTreeSetting = function(isSearch, isShare){
ajaxData.siblings.push(notebookId);
}
}
ajaxPost("/notebook/dragNotebooks", {data: JSON.stringify(ajaxData)});
Notebook.changeNav();
// 这里慢!
setTimeout(function() {
Notebook.changeNav();
}, 100);
}
if(!isShare) {
@ -303,6 +307,7 @@ Notebook.searchNotebookForList = function(key) {
$notebookList.hide();
var notebooks = self.tree.getNodesByParamFuzzy("Title", key);
log('search');
log(notebooks);
if(isEmpty(notebooks)) {
$search.html("");
@ -353,7 +358,6 @@ Notebook.everNavForNewNote = "";
Notebook.everNotebooks = [];
Notebook.changeNav = function() {
var self = Notebook;
var notebooks = Notebook.tree.getNodes();
var pureNotebooks = notebooks.slice(1, -1); // 不含新和垃圾
var html = self.getChangedNotebooks(pureNotebooks);
@ -364,8 +368,12 @@ Notebook.changeNav = function() {
$("#notebookNavForNewNote").html(html);
// 移动, 复制重新来, 因为nav变了, 移动至-----的notebook导航也变了
// 这里速度很慢
var t1 = (new Date()).getTime();
Note.initContextmenu();
Share.initContextmenu(Note.notebooksCopy);
var t2 = (new Date()).getTime();
log(t2-t1);
}
/**

View File

@ -10,6 +10,7 @@
-webkit-box-shadow: 0 6px 12px rgba(0,0,0,.175);
box-shadow: 0 6px 12px rgba(0,0,0,.175);
background-clip: padding-box;
overflow: scroll;
}
.b-m-split {
height: 6px;

File diff suppressed because one or more lines are too long

View File

@ -12,8 +12,12 @@ LEA.cmroot = 1;
var gTemplet = $("<div/>").addClass("b-m-mpanel").attr("unselectable", "on").css("display", "none");
var iTemplet = $("<div/>").addClass("b-m-item").attr("unselectable", "on");
var sTemplet = $("<div/>").addClass("b-m-split");
var $body = $("body");
var itemsCache = {}; // idx => items
//build group item, which has sub items
var buildGroup = function(obj) {
var buildGroup = function(obj) { // this = $("")对象, obj=item
groups[obj.alias] = this;
this.gidx = obj.alias;
this.id = obj.alias;
@ -21,7 +25,7 @@ LEA.cmroot = 1;
this.disable = obj.disable;
this.className = "b-m-idisable";
}
$(this).width(obj.width).click(function(){}).mousedown(returnfalse).appendTo($("body"));
$(this).width(obj.width).click(function(){}).mousedown(returnfalse).appendTo($body);
obj = null;
return this;
@ -59,42 +63,47 @@ LEA.cmroot = 1;
//add new items
var addItems = function(gidx, items, parentAlias) {
var tmp = null;
for (var i = 0; i < items.length; i++) {
if (items[i].type == "splitLine") {
//split line
var len = items.length;
for (var i = 0; i < len; i++) {
var item = items[i];
if (item.type == "splitLine") {
tmp = sTemplet.clone()[0];
} else {
// life, alias可以不需要, 从text取, 但必须唯一
if(!items[i].alias) {
if(!item.alias) {
if(parentAlias) {
items[i].alias = parentAlias + "." + items[i].text; // 移动.Hadoop
item.alias = parentAlias + "." + item.text; // 移动.Hadoop
} else {
items[i].alias = items[i].text;
item.alias = item.text;
}
// log(items[i].alias);
// log(item.alias);
}
items[i].gidx = gidx;
if (items[i].type == "group" && !items[i].action) {
item.gidx = gidx;
if (item.type == "group" && !item.action) {
//group
buildGroup.apply(gTemplet.clone()[0], [items[i]]);
arguments.callee(items[i].alias, items[i].items, items[i].alias); // life 传上级的alias, 避免重复
items[i].type = "arrow";
tmp = buildItem.apply(iTemplet.clone()[0], [items[i]]);
buildGroup.apply(gTemplet.clone()[0], [item]);
itemsCache[item.alias] = item.items;
// 递归调用, 可以动态生成?
// arguments.callee(item.alias, item.items, item.alias); // life 传上级的alias, 避免重复
item.type = "arrow";
tmp = buildItem.apply(iTemplet.clone()[0], [item]);
} else {
// 如果group有action还是可以点击的 life
if(items[i].type == "group") {
if(item.type == "group") {
//group
buildGroup.apply(gTemplet.clone()[0], [items[i]]);
arguments.callee(items[i].alias, items[i].items, items[i].alias); // life 传上级的alias, 避免重复
items[i].type = "arrow";
tmp = buildItem.apply(iTemplet.clone()[0], [items[i]]);
buildGroup.apply(gTemplet.clone()[0], [item]);
itemsCache[item.alias] = item.items;
// 递归调用
// arguments.callee(item.alias, item.items, item.alias); // life 传上级的alias, 避免重复
item.type = "arrow";
tmp = buildItem.apply(iTemplet.clone()[0], [item]);
} else {
//normal item
items[i].type = "ibody";
tmp = buildItem.apply(iTemplet.clone()[0], [items[i]]);
item.type = "ibody";
tmp = buildItem.apply(iTemplet.clone()[0], [item]);
}
//
var thisItem = items[i];
var thisItem = item;
// 点击item
// 用闭包来存储变量
@ -115,16 +124,16 @@ LEA.cmroot = 1;
});
}(thisItem, tmp));
} //end if
$(tmp).bind("contextmenu", returnfalse).hover(overItem, outItem);
}
groups[gidx].appendChild(tmp);
tmp = items[i] = items[i].items = null;
tmp = item = item.items = null;
} //end for
gidx = items = null;
};
// hover
var overItem = function(e) {
//menu item is disabled
if (this.disable)
@ -134,11 +143,12 @@ LEA.cmroot = 1;
if (this.group) {
var pos = $(this).offset();
var width = $(this).outerWidth();
showMenuGroup.apply(groups[this.idx], [pos, width]);
showMenuGroup.apply(groups[this.idx], [pos, width, this]);
}
this.className = "b-m-ifocus";
return false;
};
// hover out
//menu loses focus
var outItem = function(e) {
//disabled item
@ -150,15 +160,26 @@ LEA.cmroot = 1;
} //Endif
return false;
};
//show menu group at specified position
var showMenuGroup = function(pos, width) {
var bwidth = $("body").width();
var bheight = document.documentElement.clientHeight;
// 显示group, 这里可以动态生成
// show menu group at specified position
var showMenuGroup = function(pos, width, t) {
var $this = $(this); // dom 对象
// 没有东西, 那么生成之, 动态生成 life [ok]
if($this.html() == "") {
addItems(t.idx, itemsCache[t.idx], t.idx);
}
var bwidth = $body.width();
// var bheight = $body.height();
var bheight = document.documentElement.clientHeight-10;
bheight = bheight < 0 ? 100 : bheight;
var mwidth = $(this).outerWidth();
var mheight = $(this).outerHeight()-10;
mheight = mheight < 0 ? 100 : mheight;
var mwidth = $(this).outerWidth();
var mheight = $(this).outerHeight();
pos.left = (pos.left + width + mwidth > bwidth) ? (pos.left - mwidth < 0 ? 0 : pos.left - mwidth) : pos.left + width;
pos.top = (pos.top + mheight > bheight) ? (pos.top - mheight + (width > 0 ? 25 : 0) < 0 ? 0 : pos.top - mheight + (width > 0 ? 25 : 0)) : pos.top;
$(this).css(pos).show();
$(this).css(pos).show().css("max-height", bheight);
showGroups.push(this.gidx);
};
//to hide menu
@ -217,27 +238,13 @@ LEA.cmroot = 1;
root = buildGroup.apply(gTemplet.clone()[0], [option]);
root.applyrule = applyRule;
root.showMenu = showMenu;
// 这里很费时
addItems(option.alias, option.items);
}
else {
root = $root[0];
}
/*
var me = $(this).each(function() {
return $(this).bind('contextmenu', function(e) {
var bShowContext = (option.onContextMenu && $.isFunction(option.onContextMenu)) ? option.onContextMenu.call(this, e) : true;
if (bShowContext) {
if (option.onShow && $.isFunction(option.onShow)) {
option.onShow.call(this, root);
}
root.showMenu(e, this);
}
return false;
});
});
*/
function onShowMenu(e) {
var bShowContext = (option.onContextMenu && $.isFunction(option.onContextMenu)) ? option.onContextMenu.call(this, e) : true;
if (bShowContext) {
@ -261,8 +268,10 @@ LEA.cmroot = 1;
if (option.rule) {
applyRule(option.rule);
}
/*
gTemplet = iTemplet = sTemplet = itemTpl = buildGroup = buildItem = null;
addItems = overItem = outItem = null;
*/
//CollectGarbage();
var out = {
@ -270,8 +279,6 @@ LEA.cmroot = 1;
me.unbind("contextmenu");
},
showMenu: function(e, target) {
log(e);
log(target);
onShowMenu.call(target, e);
}
}

View File

@ -2555,6 +2555,7 @@
if (node.parentTId) view.expandCollapseParentNode(this.setting, node.getParentNode(), true);
view.editNode(this.setting, node)
}
zTreeTools.moveNode = function(targetNode, node, moveType, isSilent) {
if (!node) return node;
if (targetNode && !targetNode.isParent && this.setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) {
@ -2661,6 +2662,7 @@
if (tools.uCanDo(setting)) {
doc.bind("mousemove", _docMouseMove);
}
// 拖动
function _docMouseMove(event) {
//avoid start drag after click node
if (root.dragFlag == 0 && Math.abs(mouseDownX - event.clientX) < setting.edit.drag.minMoveSize
@ -2994,6 +2996,7 @@
}
var newNodes = isCopy ? tools.clone(nodes) : nodes;
// 这里速度慢
function dropCallback() {
if (isOtherTree) {
if (!isCopy) {
@ -3019,6 +3022,7 @@
if (isCopy && moveType == consts.move.TYPE_INNER) {
view.addNodes(targetSetting, dragTargetNode, newNodes);
} else {
// 这里
if (isCopy) {
view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
}
@ -3036,6 +3040,7 @@
view.selectNodes(targetSetting, newNodes);
$$(newNodes[0], setting).focus().blur();
// 这里非常耗时!!! 原因是ajax自定义方法
setting.treeObj.trigger(consts.event.DROP, [event, targetSetting.treeId, newNodes, dragTargetNode, moveType, isCopy]);
}
@ -3240,6 +3245,7 @@
root.noSelection = false;
root.curEditNode = node;
},
// 这里, 速度慢
moveNode: function(setting, targetNode, node, moveType, animateFlag, isSilent) {
var root = data.getRoot(setting),
childKey = setting.data.key.children;
@ -3302,7 +3308,6 @@
} else if (targetObj.get(0) && moveType == consts.move.TYPE_NEXT) {
targetObj.after(nodeDom);
}
//repair the data after move
var i,l,
tmpSrcIndex = -1,
@ -3412,6 +3417,10 @@
if (!isSilent) {
view.expandCollapseParentNode(setting, node.getParentNode(), true, animateFlag);
}
// 这里打印一直就好了
setTimeout(function() {
}, 10);
},
removeEditBtn: function(setting, node) {
$$(node, consts.id.EDIT, setting).unbind().remove();