Toggle menu
862
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 8: Line 8:
             originalHandler.call(this, event);
             originalHandler.call(this, event);
         });
         });
         $(element).addClass('FixCatTreeClick');
         element.classList.add('FixCatTreeClick');
     }
     }
}
}


addOnLoadHandler(function() {
addOnLoadHandler(function() {
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            const target = mutation.target;


  const observer = new MutationObserver((mutations) => {
            if (
    mutations.forEach((mutation) => {
                mutation.attributeName === 'class' &&
         const { target } = mutation;
                target.classList.contains('CategoryTreeToggleHandlerAttached') &&
                !target.classList.contains('FixCatTreeClick')
            ) {
                attachModifiedClickHandler(target);
            }
         });
    });


        if (mutation.attributeName === 'class' && target.classList.contains('CategoryTreeToggleHandlerAttached') &&
    observer.observe(document.body, {
                !target.classList.contains('FixCatTreeClick')) {
        attributes: true,
            attachModifiedClickHandler(target);
        attributeFilter: ['class'],
         }
         subtree: true
     });
     });
  });
  observer.observe(document.body, {
    attributes: true,
    attributeFilter: ['class'],
    subtree: true
  });
});
});

Revision as of 10:35, 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.classList.add('FixCatTreeClick');
    }
}

addOnLoadHandler(function() {
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            const target = mutation.target;

            if (
                mutation.attributeName === 'class' &&
                target.classList.contains('CategoryTreeToggleHandlerAttached') &&
                !target.classList.contains('FixCatTreeClick')
            ) {
                attachModifiedClickHandler(target);
            }
        });
    });

    observer.observe(document.body, {
        attributes: true,
        attributeFilter: ['class'],
        subtree: true
    });
});