Change to work with IDs and non-id trees

master
ahzgdn 2012-02-22 08:49:10 +01:00
parent 2ba68bd3bb
commit 1242eff76e
1 changed files with 248 additions and 217 deletions

View File

@ -1,18 +1,22 @@
/** /**
* jQuery org-chart/tree plugin. * jQuery org-chart/tree plugin.
* *
* Author: Wes Nolte * Author: Wes Nolte
* http://twitter.com/wesnolte * http://twitter.com/wesnolte
* *
* Based on the work of Mark Lee * Based on the work of Mark Lee
* http://www.capricasoftware.co.uk * http://www.capricasoftware.co.uk
* *
* This software is licensed under the Creative Commons Attribution-ShareAlike * ID implementation by Aleks Drevenšek
* 3.0 License. *
* * ID implementation fixed(changed) by Adrian Hinz
* See here for license terms: *
* http://creativecommons.org/licenses/by-sa/3.0 * This software is licensed under the Creative Commons Attribution-ShareAlike
*/ * 3.0 License.
*
* See here for license terms:
* http://creativecommons.org/licenses/by-sa/3.0
*/
(function($) { (function($) {
$.fn.jOrgChart = function(options) { $.fn.jOrgChart = function(options) {
@ -81,8 +85,14 @@
.children("ul,li") .children("ul,li")
.remove() .remove()
.end(); .end();
var attr = li.attr('id');
if (typeof attr !== 'undefined' && attr !== false) {
return li.attr("id") == targetNode.attr("id");
}
else {
return li.html() == targetNode.html(); return li.html() == targetNode.html();
}
}); });
var sourceLi = $('li').filter(function(){ var sourceLi = $('li').filter(function(){
@ -91,8 +101,14 @@
.children("ul,li") .children("ul,li")
.remove() .remove()
.end(); .end();
var attr = li.attr('id');
if (typeof attr !== 'undefined' && attr !== false) {
return li.attr("id") == sourceNode.attr("id");
}
else {
return li.html() == sourceNode.html(); return li.html() == sourceNode.html();
}
}); });
var sourceliClone = sourceLi.clone(); var sourceliClone = sourceLi.clone();
@ -104,11 +120,21 @@
sourceUl.remove(); sourceUl.remove();
} }
var id = sourceLi.attr("id");
if(targetLi.children('ul').size() >0){ if(targetLi.children('ul').size() >0){
if (typeof id !== 'undefined' && id !== false) {
targetLi.children('ul').append('<li id="'+id+'">'+sourceliClone.html()+'</li>');
}else{
targetLi.children('ul').append('<li>'+sourceliClone.html()+'</li>'); targetLi.children('ul').append('<li>'+sourceliClone.html()+'</li>');
}
}else{
if (typeof id !== 'undefined' && id !== false) {
targetLi.append('<ul><li id="'+id+'">'+sourceliClone.html()+'</li></ul>');
}else{ }else{
targetLi.append('<ul><li>'+sourceliClone.html()+'</li></ul>'); targetLi.append('<ul><li>'+sourceliClone.html()+'</li></ul>');
} }
}
}); // handleDropEvent }); // handleDropEvent
@ -146,7 +172,12 @@
.end() .end()
.html(); .html();
var new_node_id = $node.attr("id")
if (typeof new_node_id !== 'undefined' && new_node_id !== false) {
$nodeDiv = $("<div>").addClass("node").attr("id", $node.attr("id")).append($nodeContent);
}else{
$nodeDiv = $("<div>").addClass("node").append($nodeContent); $nodeDiv = $("<div>").addClass("node").append($nodeContent);
}
// Expand and contract nodes // Expand and contract nodes
if ($childNodes.length > 0) { if ($childNodes.length > 0) {