From eb030fa0f929d4f2a5d62eb47ad732ca91a44196 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 3 Mar 2011 13:59:31 +1300 Subject: [PATCH] BUGFIX Don't allow dragging tree nodes outside of the root node, don't allow moving the root node, don't access drag/drops from other trees. --- javascript/LeftAndMain.Tree.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/javascript/LeftAndMain.Tree.js b/javascript/LeftAndMain.Tree.js index 473e3a8d..51a16cc6 100755 --- a/javascript/LeftAndMain.Tree.js +++ b/javascript/LeftAndMain.Tree.js @@ -25,7 +25,28 @@ "select_limit" : 1, 'initially_select': [treeContainer.find('.current').attr('id')] }, - 'plugins': ['themes', 'html_data', 'ui', 'dnd'] + "crrm": { + 'move': { + // Check if a node is allowed to be moved. + // Caution: Runs on every drag over a new node + 'check_move': function(data) { + var movedNode = $(data.o), newParent = $(data.np), + isMovedOntoContainer = data.ot.get_container()[0] == data.np[0]; + var isAllowed = ( + // Don't allow moving the root node + movedNode.data('id') != 0 + // Only allow moving node inside the root container, not before/after it + && (!isMovedOntoContainer || data.p == 'inside') + ); + return isAllowed; + } + } + }, + 'dnd': { + "drop_target" : false, + "drag_target" : false + }, + 'plugins': ['themes', 'html_data', 'ui', 'dnd', 'crrm'] }) // .bind('before.jstree', function(e, data) { // if(data.func == 'drag_start') {