Skip to content

Commit

Permalink
add 'onDragMove' callback & change the event in 'onCheck' callback
Browse files Browse the repository at this point in the history
  • Loading branch information
ztree committed Nov 24, 2013
1 parent e4416d5 commit 1451135
Show file tree
Hide file tree
Showing 20 changed files with 252 additions and 148 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jQuery Tree Plugin ---- zTree
============
last verson : 3.5.16-beta.2
last verson : 3.5.16-beta.3


**Donate to zTree** : http://www.ztree.me/v3/donate.php
Expand Down
5 changes: 3 additions & 2 deletions api/apiCss/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var apiContent = {
onNodeCreated: this.onNodeCreated,
beforeClick: this.beforeClick
}
}
};
var setting_nodes =[
{id:1, pId:0, t:"setting", name:"var setting = {", open:true},
{id:11, pId:1, t:"treeId", name:"treeId : \"\",", iconSkin:"core", showAPI:true},
Expand Down Expand Up @@ -99,8 +99,9 @@ var apiContent = {
{id:3017, pId:30, t:"onCheck", name:"onCheck : null,", iconSkin:"check", showAPI:true},
{id:3018, pId:30, t:"onClick", name:"onClick : null,", iconSkin:"core", showAPI:true},
{id:3019, pId:30, t:"onCollapse", name:"onCollapse : null,", iconSkin:"core", showAPI:true},
{id:3019, pId:30, t:"onDblClick", name:"onDblClick : null,", iconSkin:"core", showAPI:true},
{id:3029, pId:30, t:"onDblClick", name:"onDblClick : null,", iconSkin:"core", showAPI:true},
{id:3020, pId:30, t:"onDrag", name:"onDrag : null,", iconSkin:"edit", showAPI:true},
{id:3030, pId:30, t:"onDragMove", name:"onDragMove : null,", iconSkin:"edit", showAPI:true},
{id:3021, pId:30, t:"onDrop", name:"onDrop : null,", iconSkin:"edit", showAPI:true},
{id:3022, pId:30, t:"onExpand", name:"onExpand : null,", iconSkin:"core", showAPI:true},
{id:3023, pId:30, t:"onMouseDown", name:"onMouseDown : null,", iconSkin:"core", showAPI:true},
Expand Down
2 changes: 1 addition & 1 deletion api/cn/setting.callback.onDrag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3>概述<span class="h3_info">[ 依赖 <span class="highlight_green">jquery.zt
<p></p>
<div class="longdesc">
<p>用于捕获节点被拖拽的事件回调函数</p>
<p class="highlight_red">如果设置了 setting.callback.beforeDrag 方法,且返回 false,将无法触发 onDrag 事件回调函数。</p>
<p class="highlight_red">如果设置了 setting.callback.beforeDrag 方法,且返回 false,将无法触发 onDragMove 和 onDrag 事件回调函数。</p>
<p>默认值:null</p>
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions api/cn/setting.callback.onDragMove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="apiDetail">
<div>
<h2><span>Function(event, treeId, treeNodes)</span><span class="path">setting.callback.</span>onDragMove</h2>
<h3>概述<span class="h3_info">[ 依赖 <span class="highlight_green">jquery.ztree.exedit</span> 扩展 js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>用于捕获节点被拖拽过程中移动的事件回调函数</p>
<p class="highlight_red">主要用于捕获 zTree 节点拖拽到的 DOM,从而操作对应的 DOM。</p>
<p>默认值:null</p>
</div>
</div>
<h3>Function 参数说明</h3>
<div class="desc">
<h4><b>event</b><span>js event 对象</span></h4>
<p>标准的 js event 对象</p>
<h4 class="topLine"><b>treeId</b><span>String</span></h4>
<p>被拖拽的节点 treeNodes 所在 zTree 的 <b class="highlight_red">treeId</b>,便于用户操控</p>
<h4 class="topLine"><b>treeNodes</b><span>Array(JSON)</span></h4>
<p>要被拖拽的节点 JSON 数据集合</p>
</div>
<h3>setting & function 举例</h3>
<h4>1. 拖拽节点时,随时输出 当前拖拽到的目标 DOM</h4>
<pre xmlns=""><code>function zTreeOnDragMove(event, treeId, treeNodes) {
console.log(event.target);
};
var setting = {
callback: {
onDragMove: zTreeOnDragMove
}
};
......</code></pre>
</div>
</div>
2 changes: 1 addition & 1 deletion api/en/setting.callback.onDrag.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ <h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jqu
<p></p>
<div class="longdesc">
<p>Used to capture the drag event when drag node.</p>
<p class="highlight_red">If you set 'setting.callback.beforeDrag',and return false, zTree will stop drag, and will not trigger the 'onDrag' callback.</p>
<p class="highlight_red">If you set 'setting.callback.beforeDrag',and return false, zTree will stop drag, and will not trigger the 'onDragMove' & 'onDrag' callback.</p>
<p>Default: null</p>
</div>
</div>
Expand Down
34 changes: 34 additions & 0 deletions api/en/setting.callback.onDragMove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="apiDetail">
<div>
<h2><span>Function(event, treeId, treeNodes)</span><span class="path">setting.callback.</span>onDragMove</h2>
<h3>Overview<span class="h3_info">[ depends on <span class="highlight_green">jquery.ztree.exedit</span> js ]</span></h3>
<div class="desc">
<p></p>
<div class="longdesc">
<p>Used to capture the drag-move event when drag & drop node.</p>
<p class="highlight_red">Mainly used to capture the DOM which the nodes was drag in. </p>
<p>Default: null</p>
</div>
</div>
<h3>Function Parameter Descriptions</h3>
<div class="desc">
<h4><b>event</b><span>js event Object</span></h4>
<p>event Object</p>
<h4 class="topLine"><b>treeId</b><span>String</span></h4>
<p>zTree unique identifier: <b class="highlight_red">treeId</b>, the tree is what the treeNodes are belong to, easy for users to control.</p>
<h4 class="topLine"><b>treeNodes</b><span>Array(JSON)</span></h4>
<p>A collection of the nodes which will be dragged</p>
</div>
<h3>Examples of setting & function</h3>
<h4>1. When drag nodes, output the target dom.</h4>
<pre xmlns=""><code>function zTreeOnDragMove(event, treeId, treeNodes) {
console.log(event.target);
};
var setting = {
callback: {
onDragMove: zTreeOnDragMove
}
};
......</code></pre>
</div>
</div>
20 changes: 19 additions & 1 deletion demo/cn/super/dragWithOther.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
innerTree: function(treeId, treeNodes, targetNode) {
return targetNode!=null && targetNode.isParent && targetNode.tId == treeNodes[0].parentTId;
},
dragMove: function(e, treeId, treeNodes) {
var p = null, pId = 'dom_' + treeNodes[0].pId;
if (e.target.id == pId) {
p = $(e.target);
} else {
p = $(e.target).parent('#' + pId);
if (!p.get(0)) {
p = null;
}
}

$('.domBtnDiv .active').removeClass('active');
if (p) {
p.addClass('active');
}
},
dropTree2Dom: function(e, treeId, treeNodes, targetNode, moveType) {
var domId = "dom_" + treeNodes[0].getParentNode().id;
if (moveType == null && (domId == e.target.id || $(e.target).parents("#" + domId).length > 0)) {
Expand Down Expand Up @@ -171,6 +187,7 @@
callback: {
beforeDrag: MoveTest.dragTree2Dom,
onDrop: MoveTest.dropTree2Dom,
onDragMove: MoveTest.dragMove,
onMouseUp: MoveTest.dom2Tree
},
view: {
Expand Down Expand Up @@ -201,6 +218,7 @@
.domBtn {display:inline-block;cursor:pointer;padding:2px;margin:2px 10px;border:1px gray solid;background-color:#FFE6B0}
.domBtn_Disabled {display:inline-block;cursor:default;padding:2px;margin:2px 10px;border:1px gray solid;background-color:#DFDFDF;color:#999999}
.dom_tmp {position:absolute;font-size:12px;}
.active {background-color: #93C3CF}
</style>
</HEAD>

Expand All @@ -215,7 +233,7 @@ <h6>[ 文件路径: super/dragWithOther.html ]</h6>
<ul class="info">
<li class="title"><h2>实现方法说明</h2>
<ul class="list">
<li>zTree v3.2 版本修正了 onDrag/onDrop 中的 event 对象因此可以较容易的控制将节点拖拽到其他 DOM </li>
<li>zTree v3.2 版本修正了 onDrag/onDrop 中的 event 对象; v3.5.16 版本增加了 onDragMove; 因此可以较容易的控制将节点拖拽到其他 DOM </li>
<li class="highlight_red">将其他 DOM 拖拽到 zTree 需要自己制作相关的拖拽代码</li>
<li class="highlight_red">这仅仅是一个最简单的演示,如果需要更炫的效果,需要制作更复杂的代码</li>
</ul>
Expand Down
20 changes: 19 additions & 1 deletion demo/en/super/dragWithOther.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@
innerTree: function(treeId, treeNodes, targetNode) {
return targetNode!=null && targetNode.isParent && targetNode.tId == treeNodes[0].parentTId;
},
dragMove: function(e, treeId, treeNodes) {
var p = null, pId = 'dom_' + treeNodes[0].pId;
if (e.target.id == pId) {
p = $(e.target);
} else {
p = $(e.target).parent('#' + pId);
if (!p.get(0)) {
p = null;
}
}

$('.domBtnDiv .active').removeClass('active');
if (p) {
p.addClass('active');
}
},
dropTree2Dom: function(e, treeId, treeNodes, targetNode, moveType) {
var domId = "dom_" + treeNodes[0].getParentNode().id;
if (moveType == null && (domId == e.target.id || $(e.target).parents("#" + domId).length > 0)) {
Expand Down Expand Up @@ -170,6 +186,7 @@
callback: {
beforeDrag: MoveTest.dragTree2Dom,
onDrop: MoveTest.dropTree2Dom,
onDragMove: MoveTest.dragMove,
onMouseUp: MoveTest.dom2Tree
},
view: {
Expand Down Expand Up @@ -200,6 +217,7 @@
.domBtn {display:inline-block;cursor:pointer;padding:2px;margin:2px 10px;border:1px gray solid;background-color:#FFE6B0}
.domBtn_Disabled {display:inline-block;cursor:default;padding:2px;margin:2px 10px;border:1px gray solid;background-color:#DFDFDF;color:#999999}
.dom_tmp {position:absolute;font-size:12px;}
.active {background-color: #93C3CF}
</style>
</HEAD>

Expand All @@ -214,7 +232,7 @@ <h6>[ File Path: super/dragWithOther.html ]</h6>
<ul class="info">
<li class="title"><h2>Explanation of implementation method</h2>
<ul class="list">
<li>zTree v3.2 modified the event object in onDrag/onDrop, thus the nodes can be draged to other DOMs easily.</li>
<li>zTree v3.2 modified the event object in onDrag/onDrop; v3.5.16 add the onDragMove callback, thus the nodes can be draged to other DOMs easily.</li>
<li class="highlight_red">To drag other DOMS to zTree, you need to build the drag codes by yourself.</li>
<li class="highlight_red">This is just a simple Demo. If you need more features, please build more complicated codes.</li>
</ul>
Expand Down
26 changes: 18 additions & 8 deletions js/jquery.ztree.all-3.5.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* JQuery zTree core v3.5.16-beta.2
* JQuery zTree core v3.5.16-beta.3
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
Expand All @@ -9,7 +9,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: [email protected]
* Date: 2013-11-03
* Date: 2013-11-24
*/
(function($){
var settings = {}, roots = {}, caches = {},
Expand Down Expand Up @@ -1678,7 +1678,7 @@
consts = zt.consts;
})(jQuery);
/*
* JQuery zTree excheck v3.5.16-beta.2
* JQuery zTree excheck v3.5.16-beta.3
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
Expand All @@ -1687,7 +1687,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: [email protected]
* Date: 2013-11-03
* Date: 2013-11-24
*/
(function($){
//default consts of excheck
Expand Down Expand Up @@ -1750,7 +1750,8 @@
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]);
event.srcEvent = srcEvent;
tools.apply(setting.callback.onCheck, [event, treeId, node]);
});
},
_unbindEvent = function(setting) {
Expand Down Expand Up @@ -2304,7 +2305,7 @@
}
})(jQuery);
/*
* JQuery zTree exedit v3.5.16-beta.2
* JQuery zTree exedit v3.5.16-beta.3
* http://zTree.me/
*
* Copyright (c) 2010 Hunter.z
Expand All @@ -2313,7 +2314,7 @@
* http://www.opensource.org/licenses/mit-license.php
*
* email: [email protected]
* Date: 2013-11-03
* Date: 2013-11-24
*/
(function($){
//default consts of exedit
Expand All @@ -2322,7 +2323,8 @@
DRAG: "ztree_drag",
DROP: "ztree_drop",
REMOVE: "ztree_remove",
RENAME: "ztree_rename"
RENAME: "ztree_rename",
DRAGMOVE:"ztree_dragmove"
},
id: {
EDIT: "_edit",
Expand Down Expand Up @@ -2374,6 +2376,7 @@
beforeEditName:null,
beforeRename:null,
onDrag:null,
onDragMove:null,
onDrop:null,
onRename:null
}
Expand Down Expand Up @@ -2407,6 +2410,10 @@
tools.apply(setting.callback.onDrag, [srcEvent, treeId, treeNodes]);
});

o.bind(c.DRAGMOVE,function(event, srcEvent, treeId, treeNodes){
tools.apply(setting.callback.onDragMove,[srcEvent, treeId, treeNodes]);
});

o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
tools.apply(setting.callback.onDrop, [srcEvent, treeId, treeNodes, targetNode, moveType, isCopy]);
});
Expand All @@ -2417,6 +2424,7 @@
o.unbind(c.RENAME);
o.unbind(c.REMOVE);
o.unbind(c.DRAG);
o.unbind(c.DRAGMOVE);
o.unbind(c.DROP);
},
//default event proxy of exedit
Expand Down Expand Up @@ -2896,6 +2904,8 @@
}
preTmpTargetNodeId = tmpTargetNodeId;
preTmpMoveType = moveType;

setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes]);
}
return false;
}
Expand Down
Loading

0 comments on commit 1451135

Please sign in to comment.