diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js index 07dba19..2080922 100644 --- a/jquery.jOrgChart.js +++ b/jquery.jOrgChart.js @@ -1,238 +1,269 @@ /** - * 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) { - var opts = $.extend({}, $.fn.jOrgChart.defaults, options); - var $appendTo = $(opts.chartElement); + $.fn.jOrgChart = function(options) { + var opts = $.extend({}, $.fn.jOrgChart.defaults, options); + var $appendTo = $(opts.chartElement); - // build the tree - $this = $(this); - var $container = $("
"); - if($this.is("ul")) { - buildNode($this.find("li:first"), $container, 0, opts); - } - else if($this.is("li")) { - buildNode($this, $container, 0, opts); - } - $appendTo.append($container); + // build the tree + $this = $(this); + var $container = $(""); + if($this.is("ul")) { + buildNode($this.find("li:first"), $container, 0, opts); + } + else if($this.is("li")) { + buildNode($this, $container, 0, opts); + } + $appendTo.append($container); - // add drag and drop if enabled - if(opts.dragAndDrop){ - $('div.node').draggable({ - cursor : 'move', - distance : 40, - helper : 'clone', - opacity : 0.8, - revert : true, - revertDuration : 100, - snap : 'div.node.expanded', - snapMode : 'inner', - stack : 'div.node' - }); - - $('div.node').droppable({ - accept : '.node', - activeClass : 'drag-active', - hoverClass : 'drop-hover' - }); - - // Drag start event handler for nodes - $('div.node').bind("dragstart", function handleDragStart( event, ui ){ - - var sourceNode = $(this); - sourceNode.parentsUntil('.node-container') - .find('*') - .filter('.node') - .droppable('disable'); - }); + // add drag and drop if enabled + if(opts.dragAndDrop){ + $('div.node').draggable({ + cursor : 'move', + distance : 40, + helper : 'clone', + opacity : 0.8, + revert : true, + revertDuration : 100, + snap : 'div.node.expanded', + snapMode : 'inner', + stack : 'div.node' + }); - // Drag stop event handler for nodes - $('div.node').bind("dragstop", function handleDragStop( event, ui ){ + $('div.node').droppable({ + accept : '.node', + activeClass : 'drag-active', + hoverClass : 'drop-hover' + }); - /* reload the plugin */ - $(opts.chartElement).children().remove(); - $this.jOrgChart(opts); - }); - - // Drop event handler for nodes - $('div.node').bind("drop", function handleDropEvent( event, ui ) { - var sourceNode = ui.draggable; - var targetNode = $(this); - - // finding nodes based on plaintext and html - // content is hard! - var targetLi = $('li').filter(function(){ - - li = $(this).clone() - .children("ul,li") - .remove() - .end(); - - return li.html() == targetNode.html(); - }); - - var sourceLi = $('li').filter(function(){ - - li = $(this).clone() - .children("ul,li") - .remove() - .end(); - - return li.html() == sourceNode.html(); - }); - - var sourceliClone = sourceLi.clone(); - var sourceUl = sourceLi.parent('ul'); - - if(sourceUl.children('li').size() > 1){ - sourceLi.remove(); - }else{ - sourceUl.remove(); - } - - if(targetLi.children('ul').size() >0){ - targetLi.children('ul').append('