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 1: Line 1:
mw.hook( 'wikipage.categories' ).add( function ( $content ) {
function attachModifiedClickHandler(element) {
$('.CategoryTreeToggle.CategoryTreeToggleHandlerAttached').each(function() {
     const handlers = $._data(element, 'events')?.click;
     const handlers = $._data(this, 'events').click;
   
     if (handlers && handlers.length > 0) {
     if (handlers && handlers.length > 0) {
         const originalHandler = handlers[0].handler;
         const originalHandler = handlers[0].handler;


         $(this).off('click').on('click', function(event) {
         $(element).off('click').on('click', function(event) {
             event.stopPropagation();
             event.stopPropagation();
  console.log("intercepted handler");
             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
  });

});