More actions
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
$(element).off('click').on('click', function(event) { | $(element).off('click').on('click', function(event) { | ||
event.stopPropagation(); | event.stopPropagation(); | ||
originalHandler.call(this, event); | originalHandler.call(this, event); | ||
}); | }); | ||
Line 15: | Line 14: | ||
// Use native JavaScript to add the fix class | // Use native JavaScript to add the fix class | ||
element.classList.add('FixCatTreeClick'); | element.classList.add('FixCatTreeClick'); | ||
} | } | ||
} | } | ||
Line 33: | Line 31: | ||
} else if (target && mutation.attributeName == null) { | } else if (target && mutation.attributeName == null) { | ||
target.querySelectorAll(".CategoryTreeToggle.CategoryTreeToggleHandlerAttached:not(.FixCatTreeClick)").forEach((e) => attachModifiedClickHandler(e)); | target.querySelectorAll(".CategoryTreeToggle.CategoryTreeToggleHandlerAttached:not(.FixCatTreeClick)").forEach((e) => attachModifiedClickHandler(e)); | ||
} | } | ||
}); | }); | ||
}); | }); |
Latest revision as of 11:21, 30 October 2024
function attachModifiedClickHandler(element) {
const eventsData = $._data(element, 'events');
const handlers = eventsData && eventsData.click;
if (handlers && handlers.length > 0) {
const originalHandler = handlers[0].handler;
// Properly detach and reattach the click handler using jQuery
$(element).off('click').on('click', function(event) {
event.stopPropagation();
originalHandler.call(this, event);
});
// Use native JavaScript to add the fix class
element.classList.add('FixCatTreeClick');
}
}
addOnloadHook(function() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const target = mutation.target;
// Check if the element has the specified class and has not already been processed
if (
mutation.attributeName === 'class' &&
target.classList.contains('CategoryTreeToggleHandlerAttached') &&
!target.classList.contains('FixCatTreeClick')
) {
attachModifiedClickHandler(target);
} else if (target && mutation.attributeName == null) {
target.querySelectorAll(".CategoryTreeToggle.CategoryTreeToggleHandlerAttached:not(.FixCatTreeClick)").forEach((e) => attachModifiedClickHandler(e));
}
});
});
// Observe changes to attributes, specifically the 'class' attribute, throughout the document
observer.observe(document.body, {
childList: true,
attributes: true,
attributeFilter: ['class'],
subtree: true
});
});