Skip to content

Commit

Permalink
Merge pull request zTree#32 from yumi301/master
Browse files Browse the repository at this point in the history
扩展ztree,支持onDragMove事件
  • Loading branch information
zTree committed Nov 24, 2013
2 parents 65437b7 + ec59a07 commit adf9a16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 12 additions & 1 deletion js/jquery.ztree.excheck-3.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@
var o = setting.treeObj,
c = consts.event;
o.bind(c.CHECK, function (event, srcEvent, treeId, node) {
tools.apply(setting.callback.onCheck, [!!srcEvent?srcEvent : event, treeId, node]);
/**
* 20131121 xh
* 问题:树的oncheck事件处理函数会接收一个event参数,但是event.type是"click"而不是"ztree_check"。
* 在3.2版本中event.type是"ztree_check"。
* 原因:3.2版本触发事件的写法是:tools.apply(setting.callback.onCheck, [event, treeId, node]);
* 3.5版本将其改成了:tools.apply(setting.callback.onCheck, [!!srcEvent?srcEvent : event, treeId, node]);
* 当有srcEvent时,会将srcEvent传给事件处理函数,而srcEvent是原生的点击事件,其type为"click"
* 解决办法:既然是oncheck事件,那么event.type为"click"不合适。较好的做法是将srcEvent记录在event对象中,然后将event传给事件处理函数。
* 这样事件处理函数即可得到srcEvent,又可以得到event,并且event.type是"ztree_check"
*/
event.srcEvent = srcEvent;
tools.apply(setting.callback.onCheck, [event, treeId, node]);
});
},
_unbindEvent = function(setting) {
Expand Down
17 changes: 16 additions & 1 deletion js/jquery.ztree.exedit-3.5.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
DRAG: "ztree_drag",
DROP: "ztree_drop",
REMOVE: "ztree_remove",
RENAME: "ztree_rename"
RENAME: "ztree_rename",
DRAGMOVE:"ztree_dragmove" //20131120 xh:扩展ztree,增加onDragMove事件
},
id: {
EDIT: "_edit",
Expand Down Expand Up @@ -69,6 +70,7 @@
beforeEditName:null,
beforeRename:null,
onDrag:null,
onDragMove:null, //20131120 xh:扩展ztree,增加onDragMove事件
onDrop:null,
onRename:null
}
Expand Down Expand Up @@ -105,6 +107,12 @@
o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
tools.apply(setting.callback.onDrop, [srcEvent, treeId, treeNodes, targetNode, moveType, isCopy]);
});

//20131120 xh:扩展ztree,支持onDragMove事件
o.unbind(c.DRAGMOVE);
o.bind(c.DRAGMOVE,function(event,srcEvent){
tools.apply(setting.callback.onDragMove,[srcEvent]);
})
},
_unbindEvent = function(setting) {
var o = setting.treeObj;
Expand Down Expand Up @@ -591,6 +599,13 @@
}
preTmpTargetNodeId = tmpTargetNodeId;
preTmpMoveType = moveType;

/**
* 20131120 xh
* 拖拽的过程中需要触发dragmove事件,因为可能外部接受拖拽的地方需要做处理,一个实际的例子
* 就是从控件树上拖拽控件到设计器上,设计器上需要有光标提示。
*/
setting.treeObj.trigger(consts.event.DRAGMOVE, [event]);
}
return false;
}
Expand Down

0 comments on commit adf9a16

Please sign in to comment.