diff --git a/jquery.jOrgChart.js b/jquery.jOrgChart.js
index ed2ed1f..e57404e 100644
--- a/jquery.jOrgChart.js
+++ b/jquery.jOrgChart.js
@@ -10,6 +10,9 @@
* Copyright (c) 2011 Wesley Nolte
* Dual licensed under the MIT and GPL licenses.
*
+ * Ability to accept javscript object added by David Herse
+ * http://davidherse.com
+ *
*/
(function($) {
@@ -17,8 +20,16 @@
var opts = $.extend({}, $.fn.jOrgChart.defaults, options);
var $appendTo = $(opts.chartElement);
- // build the tree
- $this = $(this);
+ if(opts.dataObject){
+ // create a list from an object
+ $this = $(createListItem('ul')).attr("id" , 'workflow_list');
+ buildList(opts.dataObject, $this);
+ $('body').append($this.hide());
+ } else {
+ // build the tree
+ $this = $(this);
+ }
+
var $container = $("
");
if($this.is("ul")) {
buildNode($this.find("li:first"), $container, 0, opts);
@@ -102,6 +113,38 @@
dragAndDrop: false
};
+ var createListItem = function(){
+ var workflow_li = '',
+ workflow_ul = '';
+ return function(type, value){
+ if(type == 'ul'){
+ return $(workflow_ul);
+ } else {
+ return $(workflow_li).addClass(value).text(value);
+ }
+ };
+ }();
+
+ var buildList = function(items, parent){
+ for(var name in items){
+ if(parent.hasClass('list')){
+ parent.append(createListItem('li', name));
+ } else {
+ var child_ul = parent.children('ul');
+ if(child_ul.length == 0){
+ parent.append($(''));
+ }
+ parent.children('ul').append(createListItem('li', name));
+ }
+ if(typeof items[name] == 'object'){
+ var new_parent = parent.find('.'+name);
+ buildList(items[name], new_parent);
+ } else {
+ parent.find('.'+name).text(parent.find('.'+name).text()+" : "+items[name]);
+ }
+ }
+ };
+
var nodeCount = 0;
// Method that recursively builds the tree
function buildNode($node, $appendTo, level, opts) {
diff --git a/readme.markdown b/readme.markdown
index 824b38a..1a8277b 100644
--- a/readme.markdown
+++ b/readme.markdown
@@ -103,6 +103,17 @@ This call will append the markup for the OrgChart to the `` element by def
----
+-----
+
+###Option to pass in javascript object
+
+Excluded the 'chartElement' parameter and add a 'dataObject' parameter. For example:
+
+ $("#chart").jOrgChart({
+ dataObject : jsObject
+ });
+
+----
##Demo
You can view a demo of this [here](http://bit.ly/u1XhTf "jQuery OrgChart").