From fef02e8b1ead2a0d8ff542e2911a6b23bcd2f71d Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 21 Nov 2009 02:38:56 +0000 Subject: [PATCH] BUGFIX Changed TreeNodeAPI->setNodeIcon() javascript to not require the old classname to replace. All PHP classnames stored in CSS class strings now have the prefix 'class-' which makes them easy to detect without context git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92668 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/LeftAndMain_left.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/javascript/LeftAndMain_left.js b/javascript/LeftAndMain_left.js index 081ddd11..b1bbf8e1 100755 --- a/javascript/LeftAndMain_left.js +++ b/javascript/LeftAndMain_left.js @@ -133,9 +133,9 @@ TreeAPI.prototype = { }); }, - setNodeIcon: function(idx, oldClassName, newClassName) { + setNodeIcon: function(idx, newClassName) { this.performOnTreeNode(idx, function(treeNode) { - treeNode.className = treeNode.className.replace(oldClassName,newClassName); + treeNode.className = treeNode.className.replace(/(class-)[^\s]*/,'$1' + newClassName); treeNode.aSpan.className = 'a ' + treeNode.className.replace('closed','spanClosed'); var aTag = treeNode.getElementsByTagName('a')[0]; aTag.title = 'Page type: ' + newClassName; @@ -149,7 +149,11 @@ TreeAPI.prototype = { setNodeParentID: function (idx, parentID) { var treeNode = this.getTreeNodeByIdx(idx); var parentNode = this.getTreeNodeByIdx(parentID); - parentNode.appendTreeNode(treeNode); + var currentParentNode = jQuery(treeNode).parents('li')[0]; + // Only change parent node if its different than the current, + // otherwise we affect the sort order unnecessarily due to + // appendTreeNode() not looking at existing sorts + if(!currentParentNode || parentNode != currentParentNode) parentNode.appendTreeNode(treeNode); }, setCurrentByIdx : function(idx) {