orgchart 3.8.1 → 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/README.md +68 -18
- package/README.zh-cn.md +67 -17
- package/README.zh-tw.md +66 -16
- package/demo/ajax-datasource.html +24 -4
- package/demo/ondemand-loading-data.html +88 -40
- package/dist/js/jquery.orgchart.js +20 -72
- package/dist/js/jquery.orgchart.min.js +4 -4
- package/dist/js/jquery.orgchart.min.js.map +1 -1
- package/package.json +1 -1
- package/src/js/jquery.orgchart.js +20 -72
- package/test/cypress/e2e/ondemand-loading-data.cy.js +5 -3
- package/test/e2e/ondemand-loading-data/test.js +5 -4
package/package.json
CHANGED
|
@@ -76,28 +76,17 @@
|
|
|
76
76
|
this.triggerInitEvent();
|
|
77
77
|
}
|
|
78
78
|
var $root = $chart.append($('<ul class="nodes"><li class="hierarchy"></li></ul>')).find('.hierarchy');
|
|
79
|
-
|
|
79
|
+
|
|
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
|
-
|
|
83
|
+
if (data.relationship) {
|
|
84
|
+
this.buildHierarchy($root, data);
|
|
85
|
+
} else {
|
|
86
|
+
this.buildHierarchy($root, this.attachRel(data, '00'));
|
|
87
|
+
}
|
|
84
88
|
}
|
|
85
|
-
|
|
86
|
-
$chart.append(`<i class="${this.options.icons.theme} ${this.options.icons.spinner} spinner"></i>`);
|
|
87
|
-
$.ajax({
|
|
88
|
-
'url': data,
|
|
89
|
-
'dataType': 'json'
|
|
90
|
-
})
|
|
91
|
-
.done(function(data, textStatus, jqXHR) {
|
|
92
|
-
that.buildHierarchy($root, that.options.ajaxURL ? data : that.attachRel(data, '00'), 0, that.options);
|
|
93
|
-
})
|
|
94
|
-
.fail(function(jqXHR, textStatus, errorThrown) {
|
|
95
|
-
console.log(errorThrown);
|
|
96
|
-
})
|
|
97
|
-
.always(function() {
|
|
98
|
-
$chart.children('.spinner').remove();
|
|
99
|
-
});
|
|
100
|
-
}
|
|
89
|
+
|
|
101
90
|
$chartContainer.append($chart);
|
|
102
91
|
|
|
103
92
|
// append the export button
|
|
@@ -151,10 +140,6 @@
|
|
|
151
140
|
});
|
|
152
141
|
mo.observe(this.$chartContainer[0], { childList: true });
|
|
153
142
|
},
|
|
154
|
-
triggerLoadEvent: function ($target, rel) {
|
|
155
|
-
var initEvent = $.Event('load-' + rel +'.orgchart');
|
|
156
|
-
$target.trigger(initEvent);
|
|
157
|
-
},
|
|
158
143
|
triggerShowEvent: function ($target, rel) {
|
|
159
144
|
var initEvent = $.Event('show-' + rel + '.orgchart');
|
|
160
145
|
$target.trigger(initEvent);
|
|
@@ -846,32 +831,20 @@
|
|
|
846
831
|
this.$chart.find('.focused').removeClass('focused');
|
|
847
832
|
$(event.delegateTarget).addClass('focused');
|
|
848
833
|
},
|
|
849
|
-
|
|
850
|
-
|
|
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) {
|
|
851
842
|
var that = this;
|
|
852
|
-
var
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
if (!$.isEmptyObject(data)) {
|
|
858
|
-
that.addParent($edge.parent(), data);
|
|
859
|
-
}
|
|
860
|
-
} else if (rel === 'children') {
|
|
861
|
-
if (data.children.length) {
|
|
862
|
-
that.addChildren($edge.parent(), data[rel]);
|
|
863
|
-
}
|
|
864
|
-
} else {
|
|
865
|
-
that.addSiblings($edge.parent(), data.siblings ? data.siblings : data);
|
|
866
|
-
}
|
|
867
|
-
that.triggerLoadEvent($edge.parent(), rel);
|
|
868
|
-
}
|
|
869
|
-
})
|
|
870
|
-
.fail(function () {
|
|
871
|
-
console.log('Failed to get ' + rel + ' data');
|
|
872
|
-
})
|
|
873
|
-
.always(function () {
|
|
874
|
-
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);
|
|
875
848
|
});
|
|
876
849
|
},
|
|
877
850
|
//
|
|
@@ -885,7 +858,6 @@
|
|
|
885
858
|
},
|
|
886
859
|
// actions on clinking top edge of a node
|
|
887
860
|
topEdgeClickHandler: function (event) {
|
|
888
|
-
event.stopPropagation();
|
|
889
861
|
var that = this;
|
|
890
862
|
var $topEdge = $(event.target);
|
|
891
863
|
var $node = $(event.delegateTarget);
|
|
@@ -902,18 +874,10 @@
|
|
|
902
874
|
this.showParent($node);
|
|
903
875
|
this.triggerShowEvent($node, 'parent');
|
|
904
876
|
}
|
|
905
|
-
} else { // load the new parent node of the specified node by ajax request
|
|
906
|
-
// start up loading status
|
|
907
|
-
if (this.startLoading($topEdge)) {
|
|
908
|
-
var opts = this.options;
|
|
909
|
-
var url = $.isFunction(opts.ajaxURL.parent) ? opts.ajaxURL.parent($node.data('nodeData')) : opts.ajaxURL.parent + $node[0].id;
|
|
910
|
-
this.loadNodes('parent', url, $topEdge);
|
|
911
|
-
}
|
|
912
877
|
}
|
|
913
878
|
},
|
|
914
879
|
// actions on clinking bottom edge of a node
|
|
915
880
|
bottomEdgeClickHandler: function (event) {
|
|
916
|
-
event.stopPropagation();
|
|
917
881
|
var $bottomEdge = $(event.target);
|
|
918
882
|
var $node = $(event.delegateTarget);
|
|
919
883
|
var childrenState = this.getNodeState($node, 'children');
|
|
@@ -928,17 +892,10 @@
|
|
|
928
892
|
this.showChildren($node);
|
|
929
893
|
this.triggerShowEvent($node, 'children');
|
|
930
894
|
}
|
|
931
|
-
} else { // load the new children nodes of the specified node by ajax request
|
|
932
|
-
if (this.startLoading($bottomEdge)) {
|
|
933
|
-
var opts = this.options;
|
|
934
|
-
var url = $.isFunction(opts.ajaxURL.children) ? opts.ajaxURL.children($node.data('nodeData')) : opts.ajaxURL.children + $node[0].id;
|
|
935
|
-
this.loadNodes('children', url, $bottomEdge);
|
|
936
|
-
}
|
|
937
895
|
}
|
|
938
896
|
},
|
|
939
897
|
// actions on clicking horizontal edges
|
|
940
898
|
hEdgeClickHandler: function (event) {
|
|
941
|
-
event.stopPropagation();
|
|
942
899
|
var $hEdge = $(event.target);
|
|
943
900
|
var $node = $(event.delegateTarget);
|
|
944
901
|
var opts = this.options;
|
|
@@ -975,15 +932,6 @@
|
|
|
975
932
|
this.triggerShowEvent($node, 'siblings');
|
|
976
933
|
}
|
|
977
934
|
}
|
|
978
|
-
} else {
|
|
979
|
-
// load the new sibling nodes of the specified node by ajax request
|
|
980
|
-
if (this.startLoading($hEdge)) {
|
|
981
|
-
var nodeId = $node[0].id;
|
|
982
|
-
var url = (this.getNodeState($node, 'parent').exist) ?
|
|
983
|
-
($.isFunction(opts.ajaxURL.siblings) ? opts.ajaxURL.siblings($node.data('nodeData')) : opts.ajaxURL.siblings + nodeId) :
|
|
984
|
-
($.isFunction(opts.ajaxURL.families) ? opts.ajaxURL.families($node.data('nodeData')) : opts.ajaxURL.families + nodeId);
|
|
985
|
-
this.loadNodes('siblings', url, $hEdge);
|
|
986
|
-
}
|
|
987
935
|
}
|
|
988
936
|
},
|
|
989
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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'))
|