Skip to content

Commit

Permalink
Expose the method hideParent & show Parent
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Dec 11, 2016
1 parent b0f02e7 commit 6ab86d4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 22 deletions.
40 changes: 38 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,43 @@ Removes the designated node and its descedant nodes.
</table>
##### .orgchart('getHierarchy')
This method is designed to get the hierarchy relationships of orgchart for further processing. For example, after editing the orgchart, you could send the returned value of this method to server-side and save the new state of orghcart.
##### .orgchart('hideDescendants',$node)
##### .orgchart('hideParent',$node)
This method allows you to hide programatically the parent node of any specific node(.node element), if it has
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>$node</td>
<td>JQuery Object</td>
<td>Yes</td>
<td>None</td>
<td>Is the desired JQuery Object to hide its parent node. Of course, its sibling nodes will be hidden at the same time</td>
</tr>
</table>
##### .orgchart('showParent',$node)
This method allows you to show programatically the parent node of any specific node(.node element), if it has
<table>
<tr>
<th>Name</th>
<th>Type</th>
<th>Required</th>
<th>Default</th>
<th>Description</th>
</tr>
<tr>
<td>$node</td>
<td>JQuery Object</td>
<td>Yes</td>
<td>None</td>
<td>Is the desired JQuery Object to show its parent node</td>
</tr>
</table>
##### .orgchart('hideChildren',$node)
This method allows you to hide programatically the children of any specific node(.node element), if it has
<table>
<tr>
Expand All @@ -648,7 +684,7 @@ This method allows you to hide programatically the children of any specific node
<td>Is the desired JQuery Object to hide its children nodes</td>
</tr>
</table>
##### .orgchart('showDescendants',$node)
##### .orgchart('showChildren',$node)
This method allows you to show programatically the children of any specific node(.node element), if it has
<table>
<tr>
Expand Down
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": "1.2.9",
"version": "1.3.0",
"homepage": "https://github.com/dabeng/OrgChart",
"authors": [
"dabeng <[email protected]>"
Expand Down
35 changes: 17 additions & 18 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
* https://github.com/dabeng/OrgChart
*
* Demos of jQuery OrgChart Plugin
* http://dabeng.github.io/OrgChart/local-datasource/
* http://dabeng.github.io/OrgChart/ajax-datasource/
* http://dabeng.github.io/OrgChart/ondemand-loading-data/
* http://dabeng.github.io/OrgChart/option-createNode/
* http://dabeng.github.io/OrgChart/export-orgchart/
* http://dabeng.github.io/OrgChart/integrate-map/
* http://dabeng.github.io/OrgChart/
*
* Copyright 2016, dabeng
* http://dabeng.github.io/
Expand Down Expand Up @@ -54,10 +49,14 @@
return removeNodes.apply(this, Array.prototype.splice.call(arguments, 1));
case 'getHierarchy':
return getHierarchy.apply(this, Array.prototype.splice.call(arguments, 1));
case 'hideDescendants':
return hideDescendants.apply(this, Array.prototype.splice.call(arguments, 1));
case 'showDescendants':
return showDescendants.apply(this, Array.prototype.splice.call(arguments, 1));
case 'hideParent':
return hideParent.apply(this, Array.prototype.splice.call(arguments, 1));
case 'showParent':
return showParent.apply(this, Array.prototype.splice.call(arguments, 1));
case 'hideChildren':
return hideChildren.apply(this, Array.prototype.splice.call(arguments, 1));
case 'showChildren':
return showChildren.apply(this, Array.prototype.splice.call(arguments, 1));
case 'hideSiblings':
return hideSiblings.apply(this, Array.prototype.splice.call(arguments, 1));
case 'showSiblings':
Expand Down Expand Up @@ -353,7 +352,7 @@
}

// recursively hide the ancestor node and sibling nodes of the specified node
function hideAncestorsSiblings($node) {
function hideParent($node) {
var $temp = $node.closest('table').closest('tr').siblings();
if ($temp.eq(0).find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
Expand All @@ -377,7 +376,7 @@
}
// if the current node has the parent node, hide it recursively
if ($parent.length && grandfatherVisible) {
hideAncestorsSiblings($parent);
hideParent($parent);
}
}

Expand All @@ -399,7 +398,7 @@
}

// recursively hide the descendant nodes of the specified node
function hideDescendants($node) {
function hideChildren($node) {
var $temp = $node.closest('tr').siblings();
if ($temp.last().find('.spinner').length) {
$node.closest('.orgchart').data('inAjax', false);
Expand All @@ -424,7 +423,7 @@
}

// show the children nodes of the specified node
function showDescendants($node) {
function showChildren($node) {
var $temp = $node.closest('tr').siblings();
var isVerticalDesc = $temp.is('.verticalNodes') ? true : false;
var $descendants = isVerticalDesc
Expand Down Expand Up @@ -652,7 +651,7 @@
if ($parent.is('.slide')) { return; }
// hide the ancestor nodes and sibling nodes of the specified node
if (parentState.visible) {
hideAncestorsSiblings($node);
hideParent($node);
$parent.one('transitionend', function() {
if (isInAction($node)) {
switchVerticalArrow($that);
Expand Down Expand Up @@ -693,9 +692,9 @@
if ($children.find('.node:visible').is('.slide')) { return; }
// hide the descendant nodes of the specified node
if (childrenState.visible) {
hideDescendants($node);
hideChildren($node);
} else { // show the descendants
showDescendants($node);
showChildren($node);
}
} else { // load the new children nodes of the specified node by ajax request
var nodeId = $that.parent()[0].id;
Expand Down Expand Up @@ -1019,7 +1018,7 @@
if (!$node.find('.symbol').length) {
$node.children('.title').prepend('<i class="fa '+ opts.parentNodeSymbol + ' symbol"></i>');
}
showDescendants($node);
showChildren($node);
}
});
}
Expand Down
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": "1.2.9",
"version": "1.3.0",
"description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
"main": "./dist/js/jquery.orgchart.js",
"style": [
Expand Down

0 comments on commit 6ab86d4

Please sign in to comment.