MediaWiki:Mobile.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 52: Line 52:
});
});
}
}
// Enhanced table sorting for mobile
// Compatible table sorting for mobile - no mw.user dependencies
// Debug version - table sorting for mobile
function initMobileSorting() {
mw.hook('wikipage.content').add(function($content) {
    console.log('Initializing mobile sorting...');
     console.log('Hook fired, skin:', mw.config.get('skin'));
     console.log('Current skin:', mw.config.get('skin'));
      
      
     if (mw.config.get('skin') === 'minerva') {
     if (mw.config.get('skin') === 'minerva') {
         console.log('Minerva skin detected');
         console.log('Minerva detected, looking for tables...');
          
          
         var $tables = $content.find('.wikitable, table.sortable');
         var tables = document.querySelectorAll('.wikitable, table.sortable');
         console.log('Found tables:', $tables.length);
         console.log('Found tables:', tables.length);
          
          
         if ($tables.length > 0) {
         if (tables.length > 0) {
             console.log('Loading tablesorter...');
             // Try to load jQuery tablesorter
            mw.loader.using('jquery.tablesorter').done(function() {
            if (typeof mw !== 'undefined' && mw.loader) {
                console.log('Tablesorter loaded successfully');
                mw.loader.using('jquery.tablesorter').then(function() {
               
                    console.log('Tablesorter module loaded');
                $tables.each(function(index) {
                    var $table = $(this);
                    console.log('Processing table', index, $table);
                      
                      
                     if (!$table.hasClass('sortable')) {
                     $(tables).each(function(index, table) {
                        $table.addClass('sortable');
                        var $table = $(table);
                         console.log('Added sortable class to table', index);
                        console.log('Processing table', index);
                    }
                       
                   
                        if (!$table.hasClass('sortable')) {
                    try {
                            $table.addClass('sortable');
                        $table.tablesorter();
                         }
                        console.log('Tablesorter applied to table', index);
                       
                    } catch (e) {
                        try {
                        console.error('Error applying tablesorter to table', index, e);
                            $table.tablesorter();
                     }
                            console.log('Tablesorter applied to table', index);
                        } catch (e) {
                            console.error('Error applying tablesorter:', e);
                        }
                     });
                }).catch(function(e) {
                    console.error('Failed to load tablesorter:', e);
                 });
                 });
             }).fail(function() {
             }
                console.error('Failed to load tablesorter module');
            });
        } else {
            console.log('No tables found to sort');
         }
         }
    } else {
        console.log('Not Minerva skin, current skin:', mw.config.get('skin'));
     }
     }
}
// Try multiple initialization methods
$(document).ready(function() {
    initMobileSorting();
});
// Also try when content loads
mw.hook('wikipage.content').add(function() {
    initMobileSorting();
});
});
});
});