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

testing
No edit summary
Line 8: Line 8:


     var tooltipCache = {};
     var tooltipCache = {};
    var styleCache = {}; // Cache loaded styles
     var $tooltip = null;
     var $tooltip = null;
     var currentTarget = null;
     var currentTarget = null;
Line 85: Line 86:
     }
     }


/* ability upgrade gadget CURRENTLY DOESN'T WORK WITH TOOLTIP*/
    /* ability upgrade gadget CURRENTLY DOESN'T WORK WITH TOOLTIP*/
     /* ─── Initialize ability upgrade gadget for tooltip content ─── */
     /* ─── Initialize ability upgrade gadget for tooltip content ─── */
     function initAbilityUpgrades( $container ) {
     function initAbilityUpgrades( $container ) {
Line 171: Line 172:
             }
             }


             // Fetch rendered template
             // Fetch rendered template with styles
             new mw.Api().post( {
             new mw.Api().post( {
                 action: 'parse',
                 action: 'parse',
                 text: templateText,
                 text: templateText,
                 title: mw.config.get( 'wgPageName' ),
                 title: mw.config.get( 'wgPageName' ),
                 prop: 'text',
                 prop: 'text|modules|modulestyles',
                 disablelimitreport: true,
                 disablelimitreport: true,
                 disableeditsection: true,
                 disableeditsection: true,
Line 183: Line 184:
             } ).then( function ( data ) {
             } ).then( function ( data ) {
                 var html = data.parse.text[ '*' ];
                 var html = data.parse.text[ '*' ];
                var modulestyles = data.parse.modulestyles || [];
                var modules = data.parse.modules || [];
               
                // Combine all modules to load
                var allModules = modulestyles.concat( modules );
               
                 tooltipCache[ cacheKey ] = html;
                 tooltipCache[ cacheKey ] = html;


                 // Only show if the mouse is still on this element
                 // Load the required style modules
                if ( currentTarget === anchor ) {
                if ( allModules.length > 0 ) {
                    tt.html( html ).show();
                    mw.loader.using( allModules ).then( function () {
                    positionTooltip( anchor );
                        // Only show if the mouse is still on this element
                   
                        if ( currentTarget === anchor ) {
                    // Initialize ability upgrades for new content
                            tt.html( html ).show();
                    if ( type === 'ability' ) {
                            positionTooltip( anchor );
                        // Trigger MediaWiki's content hook so other gadgets can initialize
                           
                         mw.hook( 'wikipage.content' ).fire( tt );
                            // Initialize ability upgrades for new content
                        initAbilityUpgrades( tt );
                            if ( type === 'ability' ) {
                                // Trigger MediaWiki's content hook so other gadgets can initialize
                                mw.hook( 'wikipage.content' ).fire( tt );
                                initAbilityUpgrades( tt );
                            }
                        }
                    } );
                } else {
                    // No modules to load, show immediately
                    if ( currentTarget === anchor ) {
                         tt.html( html ).show();
                        positionTooltip( anchor );
                       
                        if ( type === 'ability' ) {
                            mw.hook( 'wikipage.content' ).fire( tt );
                            initAbilityUpgrades( tt );
                        }
                     }
                     }
                 }
                 }