orgchart 3.8.2 → 4.0.0

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.0",
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": [
@@ -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);
@@ -831,32 +831,20 @@
831
831
  this.$chart.find('.focused').removeClass('focused');
832
832
  $(event.delegateTarget).addClass('focused');
833
833
  },
834
- // load new nodes by ajax
835
- loadNodes: function (rel, url, $edge) {
834
+ addAncestors: function (data, parentId) {
835
+ var $root = this.$chart.children('.nodes').children('.hierarchy');
836
+ this.buildHierarchy($root, data);
837
+ $root.children().slice(0, 2)
838
+ .wrapAll('<li class="hierarchy"></li>').parent()
839
+ .appendTo($('#' + parentId).siblings('.nodes'));
840
+ },
841
+ addDescendants:function (data, $parent) {
836
842
  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);
843
+ var $descendants = $('<ul class="nodes"></ul>');
844
+ $parent.after($descendants);
845
+ $.each(data, function (i) {
846
+ $descendants.append($('<li class="hierarchy"></li>'));
847
+ that.buildHierarchy($descendants.children().eq(i), this);
860
848
  });
861
849
  },
862
850
  //
@@ -870,7 +858,6 @@
870
858
  },
871
859
  // actions on clinking top edge of a node
872
860
  topEdgeClickHandler: function (event) {
873
- event.stopPropagation();
874
861
  var that = this;
875
862
  var $topEdge = $(event.target);
876
863
  var $node = $(event.delegateTarget);
@@ -887,18 +874,10 @@
887
874
  this.showParent($node);
888
875
  this.triggerShowEvent($node, 'parent');
889
876
  }
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
877
  }
898
878
  },
899
879
  // actions on clinking bottom edge of a node
900
880
  bottomEdgeClickHandler: function (event) {
901
- event.stopPropagation();
902
881
  var $bottomEdge = $(event.target);
903
882
  var $node = $(event.delegateTarget);
904
883
  var childrenState = this.getNodeState($node, 'children');
@@ -913,17 +892,10 @@
913
892
  this.showChildren($node);
914
893
  this.triggerShowEvent($node, 'children');
915
894
  }
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
895
  }
923
896
  },
924
897
  // actions on clicking horizontal edges
925
898
  hEdgeClickHandler: function (event) {
926
- event.stopPropagation();
927
899
  var $hEdge = $(event.target);
928
900
  var $node = $(event.delegateTarget);
929
901
  var opts = this.options;
@@ -960,15 +932,6 @@
960
932
  this.triggerShowEvent($node, 'siblings');
961
933
  }
962
934
  }
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
935
  }
973
936
  },
974
937
  // show the compact node's children in the compact mode
@@ -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'))