More actions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
function attachModifiedClickHandler(element) { | |||
const handlers = $._data(element, 'events')?.click; | |||
const handlers = $._data( | |||
if (handlers && handlers.length > 0) { | if (handlers && handlers.length > 0) { | ||
const originalHandler = handlers[0].handler; | const originalHandler = handlers[0].handler; | ||
$( | $(element).off('click').on('click', function(event) { | ||
event.stopPropagation(); | event.stopPropagation(); | ||
originalHandler.call(this, event); | originalHandler.call(this, event); | ||
}); | }); | ||
$(element).addClass('FixCatTreeClick'); | |||
} | } | ||
}); | } | ||
addOnLoadHandler(function() { | |||
const observer = new MutationObserver((mutations) => { | |||
mutations.forEach((mutation) => { | |||
const { target } = mutation; | |||
if (mutation.attributeName === 'class' && target.classList.contains('CategoryTreeToggleHandlerAttached') && | |||
!target.classList.contains('FixCatTreeClick')) { | |||
attachModifiedClickHandler(target); | |||
} | |||
}); | |||
}); | |||
observer.observe(document.body, { | |||
attributes: true, | |||
attributeFilter: ['class'], | |||
subtree: true | |||
}); | |||
}); | }); |
Revision as of 10:33, 30 October 2024
function attachModifiedClickHandler(element) {
const handlers = $._data(element, 'events')?.click;
if (handlers && handlers.length > 0) {
const originalHandler = handlers[0].handler;
$(element).off('click').on('click', function(event) {
event.stopPropagation();
originalHandler.call(this, event);
});
$(element).addClass('FixCatTreeClick');
}
}
addOnLoadHandler(function() {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const { target } = mutation;
if (mutation.attributeName === 'class' && target.classList.contains('CategoryTreeToggleHandlerAttached') &&
!target.classList.contains('FixCatTreeClick')) {
attachModifiedClickHandler(target);
}
});
});
observer.observe(document.body, {
attributes: true,
attributeFilter: ['class'],
subtree: true
});
});