Skip to content

Commit 38a2449

Browse files
committed
make enough space for users to build up their ajax requests
1 parent 3c0b089 commit 38a2449

File tree

6 files changed

+36
-46
lines changed

6 files changed

+36
-46
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,10 @@ var oc = $('#chartContainerId').orgchart(options);
249249
<tbody>
250250
<tr>
251251
<td>data</td>
252-
<td>json or string</td>
252+
<td>json</td>
253253
<td>yes</td>
254254
<td></td>
255-
<td>datasource usded to build out structure of orgchart. It could be a json object or a string containing the URL to which the ajax request is sent.</td>
255+
<td>datasource usded to build out structure of orgchart. It should be a json object.</td>
256256
</tr>
257257
<tr>
258258
<td>pan</td>
@@ -413,7 +413,7 @@ var oc = $('#chartContainerId').orgchart(options);
413413
<td>function</td>
414414
<td>no</td>
415415
<td></td>
416-
<td>It can often be useful to know when your table has fully been initialised, data loaded and rendered, particularly when using an ajax data source. It receives one parament: "$chart" stands for jquery object of initialised chart.</td>
416+
<td>It can often be useful to know when your table has fully been initialised, data loaded and rendered. It receives one parament: "$chart" stands for jquery object of initialised chart.</td>
417417
</tr>
418418
<tr>
419419
<td>icons</td>

demo/ajax-datasource.html

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
<link rel="icon" href="img/logo.png">
77
<link rel="stylesheet" href="css/jquery.orgchart.css">
88
<link rel="stylesheet" href="css/style.css">
9+
<style type="text/css">
10+
.spinner {
11+
line-height: 420px;
12+
}
13+
.spinner::before {
14+
width: 72px;
15+
height: 72px;
16+
border-radius: 36px;
17+
}
18+
</style>
919
</head>
1020
<body>
1121
<div id="chart-container"></div>
@@ -46,10 +56,20 @@
4656
}
4757
});
4858

49-
$('#chart-container').orgchart({
50-
'data' : '/orgchart/initdata',
51-
'nodeContent': 'title'
52-
});
59+
$('#chart-container').append(`<i class="oci oci-spinner spinner"></i>`);
60+
$.ajax({
61+
'url': '/orgchart/initdata',
62+
'dataType': 'json'
63+
})
64+
.done(function(data, textStatus, jqXHR) {
65+
$('#chart-container').orgchart({
66+
'data': data,
67+
'nodeContent': 'title'
68+
});
69+
})
70+
.always(function() {
71+
$('#chart-container').children('.spinner').remove();
72+
});
5373

5474
});
5575
</script>

dist/js/jquery.orgchart.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,13 @@
7676
this.triggerInitEvent();
7777
}
7878
var $root = $chart.append($('<ul class="nodes"><li class="hierarchy"></li></ul>')).find('.hierarchy');
79-
if ($.type(data) === 'object') {
79+
8080
if (data instanceof $) { // ul datasource
8181
this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);
8282
} else { // local json datasource
8383
this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));
8484
}
85-
} else {
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-
}
85+
10186
$chartContainer.append($chart);
10287

10388
// append the export button

dist/js/jquery.orgchart.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/jquery.orgchart.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/jquery.orgchart.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,13 @@
7676
this.triggerInitEvent();
7777
}
7878
var $root = $chart.append($('<ul class="nodes"><li class="hierarchy"></li></ul>')).find('.hierarchy');
79-
if ($.type(data) === 'object') {
79+
8080
if (data instanceof $) { // ul datasource
8181
this.buildHierarchy($root, this.buildJsonDS(data.children()), 0, this.options);
8282
} else { // local json datasource
8383
this.buildHierarchy($root, this.options.ajaxURL ? data : this.attachRel(data, '00'));
8484
}
85-
} else {
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-
}
85+
10186
$chartContainer.append($chart);
10287

10388
// append the export button

0 commit comments

Comments
 (0)