Commit d8034179 authored by Nicolas Mérigot's avatar Nicolas Mérigot

fix: check document state before registering hook

parent 9765d1a3
Pipeline #1974 passed with stage
in 27 seconds
......@@ -19,14 +19,13 @@ class SIBOidc extends HTMLElement {
this.settings = Object.assign({}, defaultSettings);
}
connectedCallback() {
async connectedCallback() {
this.settings = Object.assign({}, defaultSettings, this.dataset);
// initialize OIDC Manager
this.manager = new UserManager(this.settings);
// add a hook on DOMContentLoaded
document.addEventListener('DOMContentLoaded', async () => {
const processDOM = async () => {
const user = await this.getUser();
const id = user.profile.website;
const selector = `[bind-user]:not([data-src="${id}"])`;
......@@ -34,7 +33,14 @@ class SIBOidc extends HTMLElement {
for (const element of elements) {
element.setAttribute('data-src', id);
}
});
};
// check document state and add a hook on DOMContentLoaded if needed
if (document.readyState == 'loading') {
document.addEventListener('DOMContentLoaded', processDOM);
} else {
await processDOM();
}
}
disconnectedCallback() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment