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.
*
* Author: Wes Nolte
* http://twitter.com/wesnolte
*
* Based on the work of Mark Lee
* http://www.capricasoftware.co.uk
*
* 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
*/
* jQuery org-chart/tree plugin.
*
* Author: Wes Nolte
* http://twitter.com/wesnolte
*
* Based on the work of Mark Lee
* http://www.capricasoftware.co.uk
*
* ID implementation by Aleks Drevenšek
*
* ID implementation fixed(changed) by Adrian Hinz
*
* 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($) {
$.fn.jOrgChart = function(options) {
@ -81,8 +85,14 @@
.children("ul,li")
.remove()
.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();
}
});
var sourceLi = $('li').filter(function(){
@ -91,8 +101,14 @@
.children("ul,li")
.remove()
.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();
}
});
var sourceliClone = sourceLi.clone();
@ -104,11 +120,21 @@
sourceUl.remove();
}
var id = sourceLi.attr("id");
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>');
}
}else{
if (typeof id !== 'undefined' && id !== false) {
targetLi.append('<ul><li id="'+id+'">'+sourceliClone.html()+'</li></ul>');
}else{
targetLi.append('<ul><li>'+sourceliClone.html()+'</li></ul>');
}
}
}); // handleDropEvent
@ -146,7 +172,12 @@
.end()
.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);
}
// Expand and contract nodes
if ($childNodes.length > 0) {