MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
1,028 bytes added ,  21:49, 26 August 2025
no edit summary
No edit summary
No edit summary
Line 698: Line 698:
});
});


if (mw.user.isAnon) { // Check if the user is anonymous
if (mw.user.isAnon() === true) { // Check if the user is anonymous
     $(function () {
     $(function () {
         $('.ext-wikisource-download-button').hide(); // Hide the button for anonymous users
         $('.ext-wikisource-download-button').hide(); // Hide the button for anonymous users
Line 820: Line 820:
         var $clickedHeader = $(this);
         var $clickedHeader = $(this);
         var columnIndex = $clickedHeader.index();
         var columnIndex = $clickedHeader.index();
       
        console.log('Clicked header column index:', columnIndex);
          
          
         var $allHeaders = $table.find('th');
         var $allHeaders = $table.find('th');
Line 828: Line 830:
         }
         }
          
          
         if ($dataRows.length === 0) return;
         if ($dataRows.length === 0) {
            console.log('No data rows found');
            return;
        }
       
        console.log('Found', $dataRows.length, 'data rows');
          
          
         var currentSortClass = $clickedHeader.hasClass('sort-asc') ? 'asc' :  
         var currentSortClass = $clickedHeader.hasClass('sort-asc') ? 'asc' :  
Line 844: Line 851:
          
          
         rowsArray.sort(function(rowA, rowB) {
         rowsArray.sort(function(rowA, rowB) {
             var $cellA = $(rowA).find('td').eq(columnIndex);
             var $rowACells = $(rowA).find('td, th');
             var $cellB = $(rowB).find('td').eq(columnIndex);
             var $rowBCells = $(rowB).find('td, th');
              
              
             if ($cellA.length === 0 || $cellB.length === 0) return 0;
            var $cellA = $rowACells.eq(columnIndex);
            var $cellB = $rowBCells.eq(columnIndex);
           
             if ($cellA.length === 0 || $cellB.length === 0) {
                console.log('Cell not found for column', columnIndex);
                return 0;
            }
              
              
             var textA = $cellA.text().trim();
             var textA = $cellA.text().trim();
             var textB = $cellB.text().trim();
             var textB = $cellB.text().trim();
              
              
            console.log('Comparing:', textA, 'vs', textB);
           
            // Handle empty cells
            if (textA === '' && textB === '') return 0;
            if (textA === '') return newSortDirection === 'asc' ? -1 : 1;
            if (textB === '') return newSortDirection === 'asc' ? 1 : -1;
           
            // Try numeric comparison first
             var numA = parseFloat(textA.replace(/[,$%\s]/g, ''));
             var numA = parseFloat(textA.replace(/[,$%\s]/g, ''));
             var numB = parseFloat(textB.replace(/[,$%\s]/g, ''));
             var numB = parseFloat(textB.replace(/[,$%\s]/g, ''));
Line 858: Line 879:
             if (!isNaN(numA) && !isNaN(numB)) {
             if (!isNaN(numA) && !isNaN(numB)) {
                 result = numA - numB;
                 result = numA - numB;
                console.log('Numeric sort:', numA, 'vs', numB, '=', result);
             } else {
             } else {
                 result = textA.localeCompare(textB);
                 result = textA.localeCompare(textB);
                console.log('Text sort:', textA, 'vs', textB, '=', result);
             }
             }
              
              
Line 872: Line 895:
             $table.append(rowsArray);
             $table.append(rowsArray);
         }
         }
       
        console.log('Sorting completed for column', columnIndex);
          
          
         setTimeout(function() {
         setTimeout(function() {

Navigation menu