Skip to content

Commit

Permalink
add data property nodeData for every node
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Aug 11, 2018
1 parent 6f2c910 commit e7bca4f
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 202 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orgchart",
"version": "2.1.1",
"version": "2.1.2",
"homepage": "https://github.com/dabeng/OrgChart",
"authors": [
"dabeng <[email protected]>"
Expand Down
6 changes: 2 additions & 4 deletions demo/js/jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion demo/js/jquery.mockjax.min.js

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions demo/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@
'name': $li.contents().eq(0).text().trim(),
'relationship': ($li.parent().parent().is('li') ? '1': '0') + ($li.siblings('li').length ? 1: 0) + ($li.children('ul').length ? 1 : 0)
};
if ($li.attr('data-id')) {
subObj.id = $li.attr('data-id');
}
$.each($li.data(), function(key, value) {
subObj[key] = value;
});
$li.children('ul').children().each(function() {
if (!subObj.children) { subObj.children = []; }
subObj.children.push(that.buildJsonDS($(this)));
Expand Down Expand Up @@ -789,7 +789,7 @@
// start up loading status
if (this.startLoading($topEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent(event.data.nodeData) : opts.ajaxURL.parent + $node[0].id;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent($node.data('nodeData')) : opts.ajaxURL.parent + $node[0].id;
this.loadNodes('parent', url, $topEdge);
}
}
Expand All @@ -812,7 +812,7 @@
} else { // load the new children nodes of the specified node by ajax request
if (this.startLoading($bottomEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children(event.data.nodeData) : opts.ajaxURL.children + $node[0].id;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children($node.data('nodeData')) : opts.ajaxURL.children + $node[0].id;
this.loadNodes('children', url, $bottomEdge);
}
}
Expand Down Expand Up @@ -855,8 +855,8 @@
if (this.startLoading($hEdge)) {
var nodeId = $node[0].id;
var url = (this.getNodeState($node, 'parent').exist) ?
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings(event.data.nodeData) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families(event.data.nodeData) : opts.ajaxURL.families + nodeId);
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings($node.data('nodeData')) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families($node.data('nodeData')) : opts.ajaxURL.families + nodeId);
this.loadNodes('siblings', url, $hEdge);
}
}
Expand Down Expand Up @@ -1145,6 +1145,10 @@
$nodeDiv.append('<div class="title">' + data[opts.nodeTitle] + '</div>')
.append(typeof opts.nodeContent !== 'undefined' ? '<div class="content">' + (data[opts.nodeContent] || '') + '</div>' : '');
}
//
var nodeData = $.extend({}, data);
delete nodeData.children;
$nodeDiv.data('nodeData', nodeData);
// append 4 direction arrows or expand/collapse buttons
var flags = data.relationship || '';
if (opts.verticalLevel && level >= opts.verticalLevel) {
Expand All @@ -1168,9 +1172,9 @@

$nodeDiv.on('mouseenter mouseleave', this.nodeEnterLeaveHandler.bind(this));
$nodeDiv.on('click', this.nodeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', { 'nodeData': data }, this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', { 'nodeData': data }, this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', { 'nodeData': data }, this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.toggleBtn', this.toggleVNodes.bind(this));

if (opts.draggable) {
Expand Down
462 changes: 296 additions & 166 deletions demo/js/jspdf.min.js

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@
'name': $li.contents().eq(0).text().trim(),
'relationship': ($li.parent().parent().is('li') ? '1': '0') + ($li.siblings('li').length ? 1: 0) + ($li.children('ul').length ? 1 : 0)
};
if ($li.attr('data-id')) {
subObj.id = $li.attr('data-id');
}
$.each($li.data(), function(key, value) {
subObj[key] = value;
});
$li.children('ul').children().each(function() {
if (!subObj.children) { subObj.children = []; }
subObj.children.push(that.buildJsonDS($(this)));
Expand Down Expand Up @@ -789,7 +789,7 @@
// start up loading status
if (this.startLoading($topEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent(event.data.nodeData) : opts.ajaxURL.parent + $node[0].id;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent($node.data('nodeData')) : opts.ajaxURL.parent + $node[0].id;
this.loadNodes('parent', url, $topEdge);
}
}
Expand All @@ -812,7 +812,7 @@
} else { // load the new children nodes of the specified node by ajax request
if (this.startLoading($bottomEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children(event.data.nodeData) : opts.ajaxURL.children + $node[0].id;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children($node.data('nodeData')) : opts.ajaxURL.children + $node[0].id;
this.loadNodes('children', url, $bottomEdge);
}
}
Expand Down Expand Up @@ -855,8 +855,8 @@
if (this.startLoading($hEdge)) {
var nodeId = $node[0].id;
var url = (this.getNodeState($node, 'parent').exist) ?
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings(event.data.nodeData) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families(event.data.nodeData) : opts.ajaxURL.families + nodeId);
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings($node.data('nodeData')) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families($node.data('nodeData')) : opts.ajaxURL.families + nodeId);
this.loadNodes('siblings', url, $hEdge);
}
}
Expand Down Expand Up @@ -1145,6 +1145,10 @@
$nodeDiv.append('<div class="title">' + data[opts.nodeTitle] + '</div>')
.append(typeof opts.nodeContent !== 'undefined' ? '<div class="content">' + (data[opts.nodeContent] || '') + '</div>' : '');
}
//
var nodeData = $.extend({}, data);
delete nodeData.children;
$nodeDiv.data('nodeData', nodeData);
// append 4 direction arrows or expand/collapse buttons
var flags = data.relationship || '';
if (opts.verticalLevel && level >= opts.verticalLevel) {
Expand All @@ -1168,9 +1172,9 @@

$nodeDiv.on('mouseenter mouseleave', this.nodeEnterLeaveHandler.bind(this));
$nodeDiv.on('click', this.nodeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', { 'nodeData': data }, this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', { 'nodeData': data }, this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', { 'nodeData': data }, this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.toggleBtn', this.toggleVNodes.bind(this));

if (opts.draggable) {
Expand Down
2 changes: 1 addition & 1 deletion dist/js/jquery.orgchart.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/jquery.orgchart.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orgchart",
"version": "2.1.1",
"version": "2.1.2",
"description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
"main": "./dist/js/jquery.orgchart.min.js",
"style": [
Expand Down
18 changes: 11 additions & 7 deletions src/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@
// start up loading status
if (this.startLoading($topEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent(event.data.nodeData) : opts.ajaxURL.parent + $node[0].id;
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent($node.data('nodeData')) : opts.ajaxURL.parent + $node[0].id;
this.loadNodes('parent', url, $topEdge);
}
}
Expand All @@ -812,7 +812,7 @@
} else { // load the new children nodes of the specified node by ajax request
if (this.startLoading($bottomEdge)) {
var opts = this.options;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children(event.data.nodeData) : opts.ajaxURL.children + $node[0].id;
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children($node.data('nodeData')) : opts.ajaxURL.children + $node[0].id;
this.loadNodes('children', url, $bottomEdge);
}
}
Expand Down Expand Up @@ -855,8 +855,8 @@
if (this.startLoading($hEdge)) {
var nodeId = $node[0].id;
var url = (this.getNodeState($node, 'parent').exist) ?
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings(event.data.nodeData) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families(event.data.nodeData) : opts.ajaxURL.families + nodeId);
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings($node.data('nodeData')) : opts.ajaxURL.siblings + nodeId) :
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families($node.data('nodeData')) : opts.ajaxURL.families + nodeId);
this.loadNodes('siblings', url, $hEdge);
}
}
Expand Down Expand Up @@ -1145,6 +1145,10 @@
$nodeDiv.append('<div class="title">' + data[opts.nodeTitle] + '</div>')
.append(typeof opts.nodeContent !== 'undefined' ? '<div class="content">' + (data[opts.nodeContent] || '') + '</div>' : '');
}
//
var nodeData = $.extend({}, data);
delete nodeData.children;
$nodeDiv.data('nodeData', nodeData);
// append 4 direction arrows or expand/collapse buttons
var flags = data.relationship || '';
if (opts.verticalLevel && level >= opts.verticalLevel) {
Expand All @@ -1168,9 +1172,9 @@

$nodeDiv.on('mouseenter mouseleave', this.nodeEnterLeaveHandler.bind(this));
$nodeDiv.on('click', this.nodeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', { 'nodeData': data }, this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', { 'nodeData': data }, this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', { 'nodeData': data }, this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.topEdge', this.topEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.bottomEdge', this.bottomEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.leftEdge, .rightEdge', this.hEdgeClickHandler.bind(this));
$nodeDiv.on('click', '.toggleBtn', this.toggleVNodes.bind(this));

if (opts.draggable) {
Expand Down

0 comments on commit e7bca4f

Please sign in to comment.