diff --git a/js/jquery.ztree.all-3.5.js b/js/jquery.ztree.all-3.5.js index 55ea5036294c4d09e6434060fdf56f9020aedb33..88c046548d70d458f39bac3c02bc35d030a185e0 100644 --- a/js/jquery.ztree.all-3.5.js +++ b/js/jquery.ztree.all-3.5.js @@ -366,15 +366,24 @@ addInitRoot: function(initRoot) { _init.roots.push(initRoot); }, - addNodesData: function(setting, parentNode, nodes) { + addNodesData: function(setting, parentNode, nodes, isPrepend) { var childKey = setting.data.key.children; if (!parentNode[childKey]) parentNode[childKey] = []; if (parentNode[childKey].length > 0) { - parentNode[childKey][parentNode[childKey].length - 1].isLastNode = false; - view.setNodeLineIcos(setting, parentNode[childKey][parentNode[childKey].length - 1]); + if(isPrepend){ + parentNode[childKey][0].isFirstNode = false; + view.setNodeLineIcos(setting, parentNode[childKey][0]); + } else { + parentNode[childKey][parentNode[childKey].length - 1].isLastNode = false; + view.setNodeLineIcos(setting, parentNode[childKey][parentNode[childKey].length - 1]); + } } parentNode.isParent = true; - parentNode[childKey] = parentNode[childKey].concat(nodes); + if(isPrepend) { + parentNode[childKey] = nodes.concat(parentNode[childKey]); + } else { + parentNode[childKey] = parentNode[childKey].concat(nodes); + } }, addSelectedNode: function(setting, node) { var root = data.getRoot(setting); @@ -817,7 +826,7 @@ }, //method of operate ztree dom view = { - addNodes: function(setting, parentNode, newNodes, isSilent) { + addNodes: function(setting, parentNode, newNodes, isSilent, isPrepend) { if (setting.data.keep.leaf && parentNode && !parentNode.isParent) { return; } @@ -841,14 +850,14 @@ }); } - data.addNodesData(setting, parentNode, newNodes); - view.createNodes(setting, parentNode.level + 1, newNodes, parentNode); + data.addNodesData(setting, parentNode, newNodes, isPrepend); + view.createNodes(setting, parentNode.level + 1, newNodes, parentNode, isPrepend); if (!isSilent) { view.expandCollapseParentNode(setting, parentNode, true); } } else { - data.addNodesData(setting, data.getRoot(setting), newNodes); - view.createNodes(setting, 0, newNodes, null); + data.addNodesData(setting, data.getRoot(setting), newNodes, isPrepend); + view.createNodes(setting, 0, newNodes, null, isPrepend); } }, appendNodes: function(setting, level, nodes, parentNode, initFlag, openFlag) { @@ -1022,7 +1031,7 @@ } } }, - createNodes: function(setting, level, nodes, parentNode) { + createNodes: function(setting, level, nodes, parentNode, isPrepend) { if (!nodes || nodes.length == 0) return; var root = data.getRoot(setting), childKey = setting.data.key.children, @@ -1034,7 +1043,11 @@ } else { var ulObj = $$(parentNode, consts.id.UL, setting); if (ulObj.get(0)) { - ulObj.append(zTreeHtml.join('')); + if(isPrepend) { + ulObj.prepend(zTreeHtml.join('')); + } else { + ulObj.append(zTreeHtml.join('')); + } } } view.createNodeCallback(setting); @@ -3240,7 +3253,7 @@ root.noSelection = false; root.curEditNode = node; }, - moveNode: function(setting, targetNode, node, moveType, animateFlag, isSilent) { + moveNode: function(setting, targetNode, node, moveType, animateFlag, isSilent, isPrepend) { var root = data.getRoot(setting), childKey = setting.data.key.children; if (targetNode == node) return; @@ -3296,7 +3309,11 @@ nodeDom.remove(); } if (target_ulObj.get(0) && moveType == consts.move.TYPE_INNER) { - target_ulObj.append(nodeDom); + if(isPrepend) { + target_ulObj.prepend(nodeDom); + } else { + target_ulObj.append(nodeDom); + } } else if (targetObj.get(0) && moveType == consts.move.TYPE_PREV) { targetObj.before(nodeDom); } else if (targetObj.get(0) && moveType == consts.move.TYPE_NEXT) {