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

No edit summary
No edit summary
Line 386: Line 386:
     }
     }


    /* ─── 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 402: Line 397:
             var container = this;
             var container = this;
              
              
             // Add hover listeners
             // Add hover listeners if gadget exists
             $( container ).find( '.ability-upgrade' ).each( function () {
             if ( window.abilityUpgradeGadget ) {
                var el = this;
                $( container ).find( '.ability-upgrade' ).each( function () {
                $( el ).off( 'mouseenter.abilityUpgrade mouseleave.abilityUpgrade' );
                    var el = this;
                $( el ).on( 'mouseenter.abilityUpgrade', function () {
                    $( el ).off( 'mouseenter.abilityUpgrade mouseleave.abilityUpgrade' );
                    window.abilityUpgradeGadget.onHover( container, el );
                    $( el ).on( 'mouseenter.abilityUpgrade', function () {
                        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 (this was missing!)
             // Add click listeners - directly trigger a real click on the element
             $( container ).find( '.ability-upgrade' ).each( function () {
             $( container ).find( '.ability-upgrade' ).each( function () {
                 var upgradeElem = this;
                 var upgradeElem = this;
                 $( upgradeElem ).off( 'click.abilityUpgrade' );
                 $( upgradeElem ).off( 'click.abilityUpgrade' );
                 $( upgradeElem ).on( 'click.abilityUpgrade', function ( e ) {
                 $( upgradeElem ).on( 'click.abilityUpgrade', function ( e ) {
                     // Simulate the click event that the gadget is listening for
                     // Stop this event from propagating
                     var clickEvent = new MouseEvent( 'click', {
                    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,
                         bubbles: true,
                         cancelable: true,
                         cancelable: true,
                         view: window
                         view: window,
                    } );
                         clientX: e.clientX,
                   
                         clientY: e.clientY
                    // 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
                     // Dispatch on the upgrade element itself, not document
                     document.dispatchEvent( clickEvent );
                     upgradeElem.dispatchEvent( nativeEvent );
                 } );
                 } );
             } );
             } );