orgchart 3.8.2 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orgchart",
3
- "version": "3.8.2",
3
+ "version": "4.0.1",
4
4
  "description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
5
5
  "main": "./dist/js/jquery.orgchart.min.js",
6
6
  "style": [
@@ -535,15 +535,36 @@
535
535
  }
536
536
 
537
537
  /* styles for compact nodes */
538
- .orgchart .hierarchy > .node.compact {
538
+ .orgchart .node.compact {
539
539
  position: static;
540
540
  display: grid;
541
541
  width: 140px;
542
542
  height: 50px;
543
- overflow: hidden;
544
543
  background-color: #eee;
545
544
  }
546
545
 
546
+ .orgchart .node.compact.looseMode {
547
+ display: grid;
548
+ width: unset;
549
+ height: unset;
550
+ }
551
+
552
+ .orgchart .node.compact > .node {
553
+ display: none;
554
+ }
555
+
556
+ .orgchart .node.compact.looseMode > .node {
557
+ display: inline-block;
558
+ }
559
+
560
+ .orgchart .node.compact > .node.compact {
561
+ position: relative;
562
+ }
563
+
564
+ .orgchart .node.compact > .node.compact.looseMode {
565
+ display: grid;
566
+ }
567
+
547
568
  .orgchart .node.compact.even,
548
569
  .orgchart .node.compact.even:hover {
549
570
  background-color: #eee;
@@ -566,43 +587,22 @@
566
587
  background-color: #eee;
567
588
  }
568
589
 
569
- .orgchart .hierarchy > .node.compact.looseMode {
570
- display: grid;
571
- width: unset;
572
- height: unset;
573
- overflow: unset;
574
- }
575
-
576
- .orgchart .hierarchy > .node.compact::before {
590
+ .orgchart .node.compact::before {
577
591
  top: var(--top-cross-point, -10px);
578
592
  }
579
593
 
580
- .orgchart .node.compact > .node.compact {
581
- position: relative;
582
- display: grid;
583
- width: 140px;
584
- height: 50px;
585
- overflow: hidden;
586
- }
587
-
588
- .orgchart .node.compact .node.compact.looseMode {
589
- width: unset;
590
- height: unset;
591
- overflow: unset;
592
- }
593
-
594
- .orgchart .hierarchy > .node.compact > .content {
594
+ .orgchart .node.compact > .content {
595
595
  position: absolute;
596
596
  top: 25px;
597
597
  left: 5px;
598
598
  }
599
599
 
600
- .orgchart .hierarchy > .node.compact.looseMode > .title {
600
+ .orgchart .node.compact.looseMode > .title {
601
601
  margin-top: 5px;
602
602
  margin-left: 5px;
603
603
  }
604
604
 
605
- .orgchart .hierarchy > .node.compact.looseMode > .content {
605
+ .orgchart .node.compact.looseMode > .content {
606
606
  top: 30px;
607
607
  left: 10px;
608
608
  }
@@ -635,13 +635,13 @@
635
635
  cursor: pointer;
636
636
  }
637
637
 
638
- .orgchart .hierarchy > .node.compact > .backToCompactSymbol {
638
+ .orgchart .node.compact > .backToCompactSymbol {
639
639
  position: absolute;
640
640
  top: 5px;
641
641
  left: 5px;
642
642
  }
643
643
 
644
- .orgchart .hierarchy > .node.compact.looseMode > .backToCompactSymbol {
644
+ .orgchart .node.compact.looseMode > .backToCompactSymbol {
645
645
  top: 10px;
646
646
  left: 10px;
647
647
  }
@@ -657,7 +657,7 @@
657
657
  left: 3px;
658
658
  }
659
659
 
660
- .orgchart .hierarchy > .node.compact > .backToLooseSymbol {
660
+ .orgchart .node.compact > .backToLooseSymbol {
661
661
  position: absolute;
662
662
  top: 25px;
663
663
  right: 5px;
@@ -80,7 +80,11 @@
80
80
  if (data instanceof $) { // ul datasource
81
81
  this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);
82
82
  } else { // local json datasource
83
- this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));
83
+ if (data.relationship) {
84
+ this.buildHierarchy($root, data);
85
+ } else {
86
+ this.buildHierarchy($root, this.attachRel(data, '00'));
87
+ }
84
88
  }
85
89
 
86
90
  $chartContainer.append($chart);
@@ -136,10 +140,6 @@
136
140
  });
137
141
  mo.observe(this.$chartContainer[0], { childList: true });
138
142
  },
139
- triggerLoadEvent: function ($target, rel) {
140
- var initEvent = $.Event('load-' + rel +'.orgchart');
141
- $target.trigger(initEvent);
142
- },
143
143
  triggerShowEvent: function ($target, rel) {
144
144
  var initEvent = $.Event('show-' + rel + '.orgchart');
145
145
  $target.trigger(initEvent);
@@ -567,6 +567,9 @@
567
567
  isVisibleNode: function (index, elem) {
568
568
  return this.getNodeState($(elem)).visible;
569
569
  },
570
+ isCompactDescendant: function (index, elem) {
571
+ return $(elem).parent().is('.node.compact');
572
+ },
570
573
  // do some necessary cleanup tasks when hide animation is finished
571
574
  hideChildrenEnd: function (event) {
572
575
  var $node = event.data.node;
@@ -581,7 +584,7 @@
581
584
  $node.closest('.hierarchy').addClass('isChildrenCollapsed');
582
585
  var $lowerLevel = $node.siblings('.nodes');
583
586
  this.stopAjax($lowerLevel);
584
- var $animatedNodes = $lowerLevel.find('.node').filter(this.isVisibleNode.bind(this));
587
+ var $animatedNodes = $lowerLevel.find('.node').filter(this.isVisibleNode.bind(this)).not(this.isCompactDescendant.bind(this));
585
588
  var isVerticalDesc = $lowerLevel.is('.vertical');
586
589
  if (!isVerticalDesc) {
587
590
  $animatedNodes.closest('.hierarchy').addClass('isCollapsedDescendant');
@@ -831,32 +834,20 @@
831
834
  this.$chart.find('.focused').removeClass('focused');
832
835
  $(event.delegateTarget).addClass('focused');
833
836
  },
834
- // load new nodes by ajax
835
- loadNodes: function (rel, url, $edge) {
837
+ addAncestors: function (data, parentId) {
838
+ var $root = this.$chart.children('.nodes').children('.hierarchy');
839
+ this.buildHierarchy($root, data);
840
+ $root.children().slice(0, 2)
841
+ .wrapAll('<li class="hierarchy"></li>').parent()
842
+ .appendTo($('#' + parentId).siblings('.nodes'));
843
+ },
844
+ addDescendants:function (data, $parent) {
836
845
  var that = this;
837
- var opts = this.options;
838
- $.ajax({ 'url': url, 'dataType': 'json' })
839
- .done(function (data) {
840
- if (that.$chart.data('inAjax')) {
841
- if (rel === 'parent') {
842
- if (!$.isEmptyObject(data)) {
843
- that.addParent($edge.parent(), data);
844
- }
845
- } else if (rel === 'children') {
846
- if (data.children.length) {
847
- that.addChildren($edge.parent(), data[rel]);
848
- }
849
- } else {
850
- that.addSiblings($edge.parent(), data.siblings ? data.siblings : data);
851
- }
852
- that.triggerLoadEvent($edge.parent(), rel);
853
- }
854
- })
855
- .fail(function () {
856
- console.log('Failed to get ' + rel + ' data');
857
- })
858
- .always(function () {
859
- that.endLoading($edge);
846
+ var $descendants = $('<ul class="nodes"></ul>');
847
+ $parent.after($descendants);
848
+ $.each(data, function (i) {
849
+ $descendants.append($('<li class="hierarchy"></li>'));
850
+ that.buildHierarchy($descendants.children().eq(i), this);
860
851
  });
861
852
  },
862
853
  //
@@ -870,7 +861,6 @@
870
861
  },
871
862
  // actions on clinking top edge of a node
872
863
  topEdgeClickHandler: function (event) {
873
- event.stopPropagation();
874
864
  var that = this;
875
865
  var $topEdge = $(event.target);
876
866
  var $node = $(event.delegateTarget);
@@ -887,18 +877,10 @@
887
877
  this.showParent($node);
888
878
  this.triggerShowEvent($node, 'parent');
889
879
  }
890
- } else { // load the new parent node of the specified node by ajax request
891
- // start up loading status
892
- if (this.startLoading($topEdge)) {
893
- var opts = this.options;
894
- var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent($node.data('nodeData')) : opts.ajaxURL.parent + $node[0].id;
895
- this.loadNodes('parent', url, $topEdge);
896
- }
897
880
  }
898
881
  },
899
882
  // actions on clinking bottom edge of a node
900
883
  bottomEdgeClickHandler: function (event) {
901
- event.stopPropagation();
902
884
  var $bottomEdge = $(event.target);
903
885
  var $node = $(event.delegateTarget);
904
886
  var childrenState = this.getNodeState($node, 'children');
@@ -913,17 +895,10 @@
913
895
  this.showChildren($node);
914
896
  this.triggerShowEvent($node, 'children');
915
897
  }
916
- } else { // load the new children nodes of the specified node by ajax request
917
- if (this.startLoading($bottomEdge)) {
918
- var opts = this.options;
919
- var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children($node.data('nodeData')) : opts.ajaxURL.children + $node[0].id;
920
- this.loadNodes('children', url, $bottomEdge);
921
- }
922
898
  }
923
899
  },
924
900
  // actions on clicking horizontal edges
925
901
  hEdgeClickHandler: function (event) {
926
- event.stopPropagation();
927
902
  var $hEdge = $(event.target);
928
903
  var $node = $(event.delegateTarget);
929
904
  var opts = this.options;
@@ -960,22 +935,16 @@
960
935
  this.triggerShowEvent($node, 'siblings');
961
936
  }
962
937
  }
963
- } else {
964
- // load the new sibling nodes of the specified node by ajax request
965
- if (this.startLoading($hEdge)) {
966
- var nodeId = $node[0].id;
967
- var url = (this.getNodeState($node, 'parent').exist) ?
968
- ($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings($node.data('nodeData')) : opts.ajaxURL.siblings + nodeId) :
969
- ($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families($node.data('nodeData')) : opts.ajaxURL.families + nodeId);
970
- this.loadNodes('siblings', url, $hEdge);
971
- }
972
938
  }
973
939
  },
974
940
  // show the compact node's children in the compact mode
975
941
  backToCompactHandler: function (event) {
976
942
  $(event.delegateTarget).removeClass('looseMode')
943
+ .find('.looseMode').removeClass('looseMode')
977
944
  .children('.backToCompactSymbol').addClass('hidden').end()
978
945
  .children('.backToLooseSymbol').removeClass('hidden');
946
+ $(event.delegateTarget).children('.backToCompactSymbol').addClass('hidden').end()
947
+ .children('.backToLooseSymbol').removeClass('hidden');
979
948
  },
980
949
  // show the compact node's children in the loose mode
981
950
  backToLooseHandler: function (event) {
@@ -7,21 +7,23 @@ describe('Load data on-demand', () => {
7
7
  cy.visit('demo/ondemand-loading-data.html');
8
8
  });
9
9
 
10
- it('load child nodes of hehei', () => {
10
+ it('load the descendants of hehei', () => {
11
11
  cy.get(heihei).find('.bottomEdge').click();
12
12
  cy.get(heihei).should(($node) => {
13
13
  expect($node.siblings('.nodes').children('.hierarchy').length).to.equal(2);
14
+ expect($node.siblings('.nodes').children('.hierarchy').eq(0).find('.node:contains("Er Dan")')).to.exist;
14
15
  });
15
16
  });
16
17
 
17
- it('load parent node of sumiao', () => {
18
+ it('load the ancestors of sumiao by expanding vertically', () => {
18
19
  cy.get(sumiao).find('.topEdge').click();
19
20
  cy.get(sumiao).should(($node) => {
20
21
  expect($node.closest('.nodes').siblings('.node:contains("Lao Lao")')).to.exist;
22
+ expect($node.closest('.hierarchy').siblings().length).to.equal(7);
21
23
  });
22
24
  });
23
25
 
24
- it('load parent and sibling nodes of sumiao', () => {
26
+ it('load the ancestors of sumiao by expanding horizontally', () => {
25
27
  cy.get(sumiao).find('.leftEdge').click();
26
28
  cy.get(sumiao).should(($node) => {
27
29
  expect($node.closest('.nodes').siblings('.node:contains("Lao Lao")')).to.exist;
@@ -7,21 +7,22 @@ const page = new Page();
7
7
  const sumiao = page.sumiao;
8
8
  const heihei = page.heihei;
9
9
 
10
- test('load child nodes of hehei', async t => {
10
+ test('load the descendants of hehei', async t => {
11
11
  await t
12
12
  .hover(heihei)
13
13
  .click(heihei.find('.bottomEdge'))
14
14
  .expect(heihei.sibling('.nodes').child('.hierarchy').count).eql(2);
15
15
  });
16
16
 
17
- test('load parent node of sumiao', async t => {
17
+ test('load the ancestors of sumiao by expanding vertically', async t => {
18
18
  await t
19
19
  .hover(sumiao)
20
20
  .click(sumiao.find('.topEdge'))
21
- .expect(sumiao.parent(1).sibling('.node').withText('Lao Lao').count).eql(1);
21
+ .expect(sumiao.parent(1).sibling('.node').withText('Lao Lao').count).eql(1)
22
+ .expect(sumiao.parent(0).sibling().count).eql(7);
22
23
  });
23
24
 
24
- test('load parent and sibling nodes of sumiao', async t => {
25
+ test('load the ancestors of sumiao by expanding horizontally', async t => {
25
26
  await t
26
27
  .hover(sumiao)
27
28
  .click(sumiao.find('.leftEdge'))