79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
/*
|
|
* Detect next Gancio events and activate Next events
|
|
*/
|
|
|
|
function ActiveNext(tab_next, tab_past) {
|
|
const nexttab = document.getElementById("tab-" + tab_next);
|
|
const next = document.getElementById("tab-pane-" + tab_next);
|
|
const pasttab = document.getElementById("tab-" + tab_past);
|
|
const past = document.getElementById("tab-pane-" + tab_past);
|
|
if (nexttab != null && next !== null){
|
|
past.classList.remove("active");
|
|
pasttab.classList.remove("active");
|
|
past.classList.add("fade");
|
|
}
|
|
if (pasttab != null && past !== null){
|
|
next.classList.remove("fade");
|
|
next.classList.add("active");
|
|
nexttab.classList.add("active");
|
|
}
|
|
}
|
|
|
|
function HideElement(id) {
|
|
const element = document.getElementById(id);
|
|
if (element) {
|
|
element.style.display = "none";
|
|
}
|
|
}
|
|
|
|
function ActiveNextEvents(tab_next, tab_past, msg_id) {
|
|
ActiveNext(tab_next, tab_past);
|
|
HideElement(msg_id);
|
|
}
|
|
|
|
// Using MutationObserver
|
|
|
|
function CheckNextEvents(ge_id, callbackifdiv) {
|
|
// Select element with ge_id
|
|
const targetNode = document.getElementById(ge_id);
|
|
|
|
// Verify existence of element and that it has ShadowRoot
|
|
if (targetNode && targetNode.shadowRoot) {
|
|
const shadowRoot = targetNode.shadowRoot;
|
|
|
|
// Look for a div element in shadowRoot
|
|
const divElement = shadowRoot.querySelector('div');
|
|
if (divElement) {
|
|
// console.log('<div> is present in ShadowRoot');
|
|
callbackifdiv();
|
|
return true;
|
|
} else { // In there are not div, keep looking
|
|
// MutationObserver configuration
|
|
const config = { childList: true };
|
|
|
|
// Callback to execute when changes in shadowRoot
|
|
const callback = (mutationsList) => {
|
|
for (const mutation of mutationsList) {
|
|
if (mutation.type === 'childList') {
|
|
// Verify new child nodes
|
|
mutation.addedNodes.forEach((node) => {
|
|
// Check in node is <div>
|
|
if (node.nodeType === Node.ELEMENT_NODE && node.nodeName === 'DIV') {
|
|
// console.log('New <div> added to ShadowRoot');
|
|
callbackifdiv();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
// Instance a MutationObserver
|
|
const observer = new MutationObserver(callback);
|
|
|
|
// Start to observ the ShadowRoot
|
|
observer.observe(shadowRoot, config);
|
|
}
|
|
}
|
|
return false;
|
|
}
|