User:Monster Domosed/common.js: Difference between revisionsGive feedback
trying to make MediaWiki:Gadget-ability-upgrades work inside ability tooltip |
No edit summary |
||
| Line 386: | Line 386: | ||
} | } | ||
/* ─── Initialize ability upgrade gadget for tooltip content ─── */ | |||
function initAbilityUpgrades( $container ) { | function initAbilityUpgrades( $container ) { | ||
// Check if the gadget exists | // Check if the gadget exists | ||
| Line 411: | Line 411: | ||
$( el ).on( 'mouseleave.abilityUpgrade', function () { | $( el ).on( 'mouseleave.abilityUpgrade', function () { | ||
window.abilityUpgradeGadget.onUnhover( container ); | window.abilityUpgradeGadget.onUnhover( container ); | ||
} ); | |||
} ); | |||
// Add click listeners (this was missing!) | |||
$( container ).find( '.ability-upgrade' ).each( function () { | |||
var upgradeElem = this; | |||
$( upgradeElem ).off( 'click.abilityUpgrade' ); | |||
$( upgradeElem ).on( 'click.abilityUpgrade', function ( e ) { | |||
// Simulate the click event that the gadget is listening for | |||
var clickEvent = new MouseEvent( 'click', { | |||
bubbles: true, | |||
cancelable: true, | |||
view: window | |||
} ); | |||
// Set the target to the upgrade element | |||
Object.defineProperty( clickEvent, 'target', { | |||
value: upgradeElem, | |||
writable: false | |||
} ); | |||
// Dispatch to document so the gadget's listener catches it | |||
document.dispatchEvent( clickEvent ); | |||
} ); | } ); | ||
} ); | } ); | ||