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 { ...@@ -19,14 +19,13 @@ class SIBOidc extends HTMLElement {
this.settings = Object.assign({}, defaultSettings); this.settings = Object.assign({}, defaultSettings);
} }
connectedCallback() { async connectedCallback() {
this.settings = Object.assign({}, defaultSettings, this.dataset); this.settings = Object.assign({}, defaultSettings, this.dataset);
// initialize OIDC Manager // initialize OIDC Manager
this.manager = new UserManager(this.settings); this.manager = new UserManager(this.settings);
// add a hook on DOMContentLoaded const processDOM = async () => {
document.addEventListener('DOMContentLoaded', async () => {
const user = await this.getUser(); const user = await this.getUser();
const id = user.profile.website; const id = user.profile.website;
const selector = `[bind-user]:not([data-src="${id}"])`; const selector = `[bind-user]:not([data-src="${id}"])`;
...@@ -34,7 +33,14 @@ class SIBOidc extends HTMLElement { ...@@ -34,7 +33,14 @@ class SIBOidc extends HTMLElement {
for (const element of elements) { for (const element of elements) {
element.setAttribute('data-src', id); 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() { 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