Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

交互优化:拖动方法新增回调参数,方便用户获取移动至目标节点的相对位置 #525

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions demo/cn/exedit/drag_move.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<title>ZTREE DEMO - drag move</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../../../css/demo.css" type="text/css" />
<link
rel="stylesheet"
href="../../../css/zTreeStyle/zTreeStyle.css"
type="text/css"
/>
<script
type="text/javascript"
src="../../../js/jquery-1.4.4.min.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.core.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.excheck.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.exedit.js"
></script>
<script type="text/javascript">
var setting = {
edit: {
enable: true,
showRemoveBtn: false,
showRenameBtn: false,
drag: {
isMove: true,
prev: true,
inner: true,
next: true,
}
},
data: {
simpleData: {
enable: true,
},
},
callback: {
onDragMove: onDragMove,
beforeDrop: beforeDrop,
},
}

var zNodes = [
{ id: 1, pId: 0, name: '随意拖拽 1', open: true },
{ id: 11, pId: 1, name: '随意拖拽 1-1' },
{ id: 12, pId: 1, name: '随意拖拽 1-2', open: true },
{ id: 121, pId: 12, name: '随意拖拽 1-2-1' },
{ id: 122, pId: 12, name: '随意拖拽 1-2-2' },
{ id: 123, pId: 12, name: '随意拖拽 1-2-3' },
{ id: 13, pId: 1, name: '禁止拖拽 1-3', open: true, drag: false },
{ id: 131, pId: 13, name: '禁止拖拽 1-3-1', drag: false },
{ id: 132, pId: 13, name: '禁止拖拽 1-3-2', drag: false },
{ id: 133, pId: 13, name: '随意拖拽 1-3-3' },
{ id: 2, pId: 0, name: '随意拖拽 2', open: true },
{ id: 21, pId: 2, name: '随意拖拽 2-1' },
{
id: 22,
pId: 2,
name: '禁止拖拽到我身上 2-2',
open: true,
drop: false,
},
{ id: 221, pId: 22, name: '随意拖拽 2-2-1' },
{ id: 222, pId: 22, name: '随意拖拽 2-2-2' },
{ id: 223, pId: 22, name: '随意拖拽 2-2-3' },
{ id: 23, pId: 2, name: '随意拖拽 2-3' },
]
function onDragMove(e, treeId, treeNodes, targetNode, moveType) {
if (targetNode) {
var moveTypeTextMap = {
inner: '内部',
prev: '前面',
next: '后面',
}
var hintHtml = [
'<span style="font-size: 22px;color: #999;font-weight: 200;">',
'<span>移动至【</span>',
'<span style="color: #4591f7;font-weight: 400;">',
targetNode.name,
'</span>',
'<span>】' + moveTypeTextMap[moveType] + '</span>',
'</span>'
].join('')
$('#hint').html(hintHtml)
}
}
function beforeDrop() {
$('#hint').html('')
}

$(document).ready(function() {
$.fn.zTree.init($('#treeDemo'), setting, zNodes)
})
</script>
</head>

<body>
<h1>拖拽节点基本控制</h1>
<h6>[ 文件路径: exedit/drag_move.html ]</h6>
<div class="content_wrap">
<div class="zTreeDemoBackground left">
<ul id="treeDemo" class="ztree"></ul>
</div>
<div class="right drag-move">
<h3>当前目标节点和拖动类型:</h3>
<div id="hint"></div>
</div>
</div>
</body>
</html>
119 changes: 119 additions & 0 deletions demo/en/exedit/drag_move.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!DOCTYPE html>
<html>
<head>
<title>ZTREE DEMO - drag move</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../../../css/demo.css" type="text/css" />
<link
rel="stylesheet"
href="../../../css/zTreeStyle/zTreeStyle.css"
type="text/css"
/>
<script
type="text/javascript"
src="../../../js/jquery-1.4.4.min.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.core.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.excheck.js"
></script>
<script
type="text/javascript"
src="../../../js/jquery.ztree.exedit.js"
></script>
<script type="text/javascript">
var setting = {
edit: {
enable: true,
showRemoveBtn: false,
showRenameBtn: false,
drag: {
isMove: true,
prev: true,
inner: true,
next: true,
}
},
data: {
simpleData: {
enable: true,
},
},
callback: {
onDragMove: onDragMove,
beforeDrop: beforeDrop,
},
}

var zNodes = [
{ id: 1, pId: 0, name: 'can drag 1', open: true },
{ id: 11, pId: 1, name: 'can drag 1-1' },
{ id: 12, pId: 1, name: 'can drag 1-2', open: true },
{ id: 121, pId: 12, name: 'can drag 1-2-1' },
{ id: 122, pId: 12, name: 'can drag 1-2-2' },
{ id: 123, pId: 12, name: 'can drag 1-2-3' },
{ id: 13, pId: 1, name: "can't drag 1-3", open: true, drag: false },
{ id: 131, pId: 13, name: "can't drag 1-3-1", drag: false },
{ id: 132, pId: 13, name: "can't drag 1-3-2", drag: false },
{ id: 133, pId: 13, name: 'can drag 1-3-3' },
{ id: 2, pId: 0, name: 'can drag 2', open: true },
{ id: 21, pId: 2, name: 'can drag 2-1' },
{
id: 22,
pId: 2,
name: "can't drag onto me 2-2",
open: true,
drop: false,
},
{ id: 221, pId: 22, name: 'can drag 2-2-1' },
{ id: 222, pId: 22, name: 'can drag 2-2-2' },
{ id: 223, pId: 22, name: 'can drag 2-2-3' },
{ id: 23, pId: 2, name: 'can drag 2-3' },
]
function onDragMove(e, treeId, treeNodes, targetNode, moveType) {
if (targetNode) {
var moveTypeTextMap = {
inner: 'inside',
prev: 'before',
next: 'behind',
}
var hintHtml = [
'<span style="font-size: 22px;color: #999;font-weight: 200;">',
'<span>move to【</span>',
'<span>】' + moveTypeTextMap[moveType] + '</span>',
'<span style="color: #4591f7;font-weight: 400;">',
targetNode.name,
'</span>',
'</span>'
].join('')
$('#hint').html(hintHtml)
}
}
function beforeDrop() {
$('#hint').html('')
}

$(document).ready(function() {
$.fn.zTree.init($('#treeDemo'), setting, zNodes)
})
</script>
</head>

<body>
<h1>Basic control of dragging nodes</h1>
<h6>[ File path: exedit/drag_move.html ]</h6>
<div class="content_wrap">
<div class="zTreeDemoBackground left">
<ul id="treeDemo" class="ztree"></ul>
</div>
<div class="right drag-move">
<h3>targetNode and moveType:</h3>
<div id="hint"></div>
</div>
</div>
</body>
</html>
8 changes: 4 additions & 4 deletions js/jquery.ztree.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2772,8 +2772,8 @@
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.DRAGMOVE, function (event, srcEvent, treeId, treeNodes, targetNode, moveType) {
tools.apply(setting.callback.onDragMove, [srcEvent, treeId, treeNodes, targetNode, moveType]);
});

o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
Expand Down Expand Up @@ -3286,8 +3286,8 @@
}
preTmpTargetNodeId = tmpTargetNodeId;
preTmpMoveType = moveType;

setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes]);
var dragTargetNode = tmpTargetNodeId == null ? null : data.getNodeCache(targetSetting,tmpTargetNodeId);
setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes, dragTargetNode, moveType]);
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions js/jquery.ztree.exedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@
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.DRAGMOVE, function (event, srcEvent, treeId, treeNodes, targetNode, moveType) {
tools.apply(setting.callback.onDragMove, [srcEvent, treeId, treeNodes, targetNode, moveType]);
});

o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
Expand Down Expand Up @@ -615,8 +615,8 @@
}
preTmpTargetNodeId = tmpTargetNodeId;
preTmpMoveType = moveType;

setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes]);
var dragTargetNode = tmpTargetNodeId == null ? null : data.getNodeCache(targetSetting,tmpTargetNodeId);
setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes, dragTargetNode, moveType]);
}
return false;
}
Expand Down