Neaten comment header. Copied merged changes through to example code. Updated example code to demonstrate new functionality.

master
Wes 2012-02-28 09:28:18 +00:00
parent d92c649909
commit 9763085df2
3 changed files with 249 additions and 222 deletions

View File

@ -47,7 +47,7 @@
<li> <li>
Food Food
<ul> <ul>
<li>Beer</li> <li id="beer">Beer</li>
<li>Vegetables <li>Vegetables
<ul> <ul>
<li>Pumpkin</li> <li>Pumpkin</li>
@ -57,7 +57,7 @@
</li> </li>
</ul> </ul>
</li> </li>
<li>Fruit <li class="fruit">Fruit
<ul> <ul>
<li>Apple <li>Apple
<ul> <ul>

View File

@ -1,18 +1,20 @@
/** /**
* 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 fixed by Adrian Hinz
* 3.0 License. *
* * This software is licensed under the Creative Commons Attribution-ShareAlike
* See here for license terms: * 3.0 License.
* http://creativecommons.org/licenses/by-sa/3.0 *
*/ * 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 +83,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 +99,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 +118,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 +170,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) {

View File

@ -7,9 +7,7 @@
* Based on the work of Mark Lee * Based on the work of Mark Lee
* http://www.capricasoftware.co.uk * http://www.capricasoftware.co.uk
* *
* ID implementation by Aleks Drevenšek * ID implementation fixed by Adrian Hinz
*
* ID implementation fixed(changed) by Adrian Hinz
* *
* This software is licensed under the Creative Commons Attribution-ShareAlike * This software is licensed under the Creative Commons Attribution-ShareAlike
* 3.0 License. * 3.0 License.