User:Monster Domosed/common.js: Difference between revisions

No edit summary
No edit summary
Tag: Manual revert
Line 388: Line 388:
     /* ─── Initialize ability upgrade gadget for tooltip content ─── */
     /* ─── Initialize ability upgrade gadget for tooltip content ─── */
     function initAbilityUpgrades( $container ) {
     function initAbilityUpgrades( $container ) {
        // Check if the gadget exists
        if ( !window.abilityUpgradeGadget ) {
            return;
        }
         var abilityCards = $container.find( '.ability-card' );
         var abilityCards = $container.find( '.ability-card' );
         if ( !abilityCards.length ) {
         if ( !abilityCards.length ) {
Line 397: Line 402:
             var container = this;
             var container = this;
              
              
             // Add hover listeners if gadget exists
             // Add hover listeners
             if ( window.abilityUpgradeGadget ) {
             $( container ).find( '.ability-upgrade' ).each( function () {
                $( container ).find( '.ability-upgrade' ).each( function () {
                var el = this;
                    var el = this;
                $( el ).off( 'mouseenter.abilityUpgrade mouseleave.abilityUpgrade' );
                    $( el ).off( 'mouseenter.abilityUpgrade mouseleave.abilityUpgrade' );
                $( el ).on( 'mouseenter.abilityUpgrade', function () {
                    $( el ).on( 'mouseenter.abilityUpgrade', function () {
                    window.abilityUpgradeGadget.onHover( container, el );
                        window.abilityUpgradeGadget.onHover( container, el );
                    } );
                    $( el ).on( 'mouseleave.abilityUpgrade', function () {
                        window.abilityUpgradeGadget.onUnhover( container );
                    } );
                 } );
                 } );
            }
                 $( el ).on( 'mouseleave.abilityUpgrade', function () {
           
                     window.abilityUpgradeGadget.onUnhover( container );
            // Add click listeners - directly trigger a real click on the element
            $( container ).find( '.ability-upgrade' ).each( function () {
                var upgradeElem = this;
                 $( upgradeElem ).off( 'click.abilityUpgrade' );
                $( upgradeElem ).on( 'click.abilityUpgrade', function ( e ) {
                     // Stop this event from propagating
                    e.stopPropagation();
                   
                    // Create a new native click event on the actual element
                    // This will bubble up naturally and be caught by the gadget's document listener
                    var nativeEvent = new MouseEvent( 'click', {
                        bubbles: true,
                        cancelable: true,
                        view: window,
                        clientX: e.clientX,
                        clientY: e.clientY
                    } );
                   
                    // Dispatch on the upgrade element itself, not document
                    upgradeElem.dispatchEvent( nativeEvent );
                 } );
                 } );
             } );
             } );