Skip to content

Commit 2ac4efe

Browse files
committed
add content to the body of connectedCallback
1 parent 8d09aef commit 2ac4efe

2 files changed

Lines changed: 29 additions & 30 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"no-spaced-func": 2,
8888
"no-sparse-arrays": 2,
8989
"no-throw-literal": 2,
90-
"no-trailing-spaces": 2,
90+
"no-trailing-spaces": 1,
9191
"no-undef": 2,
9292
"no-undef-init": 2,
9393
"no-unneeded-ternary": 2,

src/orgchart-webcomponents.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,12 @@ export default class OrgChart extends HTMLElement {
3333
'pan': false,
3434
'zoom': false
3535
},
36-
opts = Object.assign(defaultOptions, options),
37-
data = opts.data,
38-
chart = document.createElement('div');
36+
opts = Object.assign(defaultOptions, options);
3937

4038
this.options = opts;
41-
delete this.options.data;
42-
this.dataset.options = JSON.stringify(opts);
43-
this.setAttribute('class', 'orgchart' + (opts.chartClass !== '' ? ' ' + opts.chartClass : '') +
44-
(opts.direction !== 't2b' ? ' ' + opts.direction : ''));
45-
if (typeof data === 'object') { // local json datasource
46-
this.buildHierarchy(this, opts.ajaxURL ? data : this._attachRel(data, '00'), 0);
47-
} else if (typeof data === 'string' && data.startsWith('#')) { // ul datasource
48-
this.buildHierarchy(this, this._buildJsonDS(document.querySelector(data).children[0]), 0);
49-
} else { // ajax datasource
50-
let spinner = document.createElement('i');
5139

52-
spinner.setAttribute('class', 'fa fa-circle-o-notch fa-spin spinner');
53-
this.appendChild(spinner);
54-
this._getJSON(data)
55-
.then(function (resp) {
56-
that.buildHierarchy(that, opts.ajaxURL ? resp : that._attachRel(resp, '00'), 0);
57-
})
58-
.catch(function (err) {
59-
console.error('failed to fetch datasource for orgchart', err);
60-
})
61-
.finally(function () {
62-
let spinner = that.querySelector('.spinner');
63-
64-
spinner.parentNode.removeChild(spinner);
65-
});
66-
}
6740
this.addEventListener('click', this._clickChart.bind(this));
6841

69-
7042
if (opts.pan && opts.chartContainer) {
7143
let chartContainer = document.querySelector(opts.chartContainer);
7244

@@ -87,7 +59,34 @@ export default class OrgChart extends HTMLElement {
8759
}
8860
}
8961
connectedCallback() {
62+
let that = this,
63+
opts = this.options,
64+
data = opts.data;
9065

66+
this.setAttribute('class', 'orgchart' + (opts.chartClass !== '' ? ' ' + opts.chartClass : '') +
67+
(opts.direction !== 't2b' ? ' ' + opts.direction : ''));
68+
if (typeof data === 'object') { // local json datasource
69+
this.buildHierarchy(this, opts.ajaxURL ? data : this._attachRel(data, '00'), 0);
70+
} else if (typeof data === 'string' && data.startsWith('#')) { // ul datasource
71+
this.buildHierarchy(this, this._buildJsonDS(document.querySelector(data).children[0]), 0);
72+
} else { // ajax datasource
73+
let spinner = document.createElement('i');
74+
75+
spinner.setAttribute('class', 'fa fa-circle-o-notch fa-spin spinner');
76+
this.appendChild(spinner);
77+
this._getJSON(data)
78+
.then(function (resp) {
79+
that.buildHierarchy(that, opts.ajaxURL ? resp : that._attachRel(resp, '00'), 0);
80+
})
81+
.catch(function (err) {
82+
console.error('failed to fetch datasource for orgchart', err);
83+
})
84+
.finally(function () {
85+
let spinner = that.querySelector('.spinner');
86+
87+
spinner.parentNode.removeChild(spinner);
88+
});
89+
}
9190
}
9291
disconnectedCallback() {
9392

0 commit comments

Comments
 (0)