557
edits
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 16: | Line 16: | ||
} ); | } ); | ||
} ); | } ); | ||
$( function(){ | $( function(){ | ||
| Line 632: | Line 633: | ||
importScript('MediaWiki:Compare.js'); | importScript('MediaWiki:Compare.js'); | ||
} ); | } ); | ||
/* Footnotes as tooltip - from it.wikipedia.org - request by Candalua */ | /* Footnotes as tooltip - from it.wikipedia.org - request by Candalua */ | ||
$( function () | $( function () | ||
{ | { | ||
| Line 702: | Line 703: | ||
}); | }); | ||
} | } | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 730: | Line 730: | ||
$('#bodyContent').append(downloadButton); | $('#bodyContent').append(downloadButton); | ||
}); | }); | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 745: | Line 744: | ||
} | } | ||
}); | }); | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 779: | Line 776: | ||
} | } | ||
}); | }); | ||
}); | |||
// Table sorting functions for all devices | |||
function initMobileSorting() { | |||
console.log('Initializing table sorting for all devices...'); | |||
var tables = document.querySelectorAll('.wikitable, table.sortable'); | |||
console.log('Found tables:', tables.length); | |||
$(tables).each(function(index, table) { | |||
setupTableSorting($(table), index); | |||
}); | |||
} | |||
function setupTableSorting($table, tableIndex) { | |||
var $headers = $table.find('th'); | |||
if ($headers.length === 0) return; | |||
console.log('Setting up table', tableIndex, 'with', $headers.length, 'headers'); | |||
$table.off('click.tablesort'); | |||
$headers.each(function() { | |||
var $header = $(this); | |||
$header.css({ | |||
'cursor': 'pointer', | |||
'user-select': 'none', | |||
'background-color': '#f8f9fa', | |||
'border-bottom': '2px solid #a2a9b1', | |||
'position': 'relative' | |||
}); | |||
$header.find('.sort-arrow').remove(); | |||
$header.append('<span class="sort-arrow" style="margin-left: 5px; color: #666; font-size: 12px;">⇅</span>'); | |||
}); | |||
$table.on('click.tablesort', 'th', function(e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
var $clickedHeader = $(this); | |||
var columnIndex = $clickedHeader.index(); | |||
var $allHeaders = $table.find('th'); | |||
var $dataRows = $table.find('tbody tr'); | |||
if ($dataRows.length === 0) { | |||
$dataRows = $table.find('tr').not($table.find('tr').first()); | |||
} | |||
if ($dataRows.length === 0) return; | |||
var currentSortClass = $clickedHeader.hasClass('sort-asc') ? 'asc' : | |||
$clickedHeader.hasClass('sort-desc') ? 'desc' : 'none'; | |||
var newSortDirection = currentSortClass === 'asc' ? 'desc' : 'asc'; | |||
$allHeaders.removeClass('sort-asc sort-desc'); | |||
$allHeaders.find('.sort-arrow').text('⇅').css('color', '#666'); | |||
$clickedHeader.addClass('sort-' + newSortDirection); | |||
var arrow = newSortDirection === 'asc' ? '⇑' : '⇓'; | |||
$clickedHeader.find('.sort-arrow').text(arrow).css('color', '#000'); | |||
var rowsArray = $dataRows.toArray(); | |||
rowsArray.sort(function(rowA, rowB) { | |||
var $cellA = $(rowA).find('td').eq(columnIndex); | |||
var $cellB = $(rowB).find('td').eq(columnIndex); | |||
if ($cellA.length === 0 || $cellB.length === 0) return 0; | |||
var textA = $cellA.text().trim(); | |||
var textB = $cellB.text().trim(); | |||
var numA = parseFloat(textA.replace(/[,$%\s]/g, '')); | |||
var numB = parseFloat(textB.replace(/[,$%\s]/g, '')); | |||
var result; | |||
if (!isNaN(numA) && !isNaN(numB)) { | |||
result = numA - numB; | |||
} else { | |||
result = textA.localeCompare(textB); | |||
} | |||
return newSortDirection === 'desc' ? -result : result; | |||
}); | |||
var $tbody = $table.find('tbody'); | |||
if ($tbody.length > 0) { | |||
$tbody.empty().append(rowsArray); | |||
} else { | |||
$table.find('tr').not($table.find('tr').first()).remove(); | |||
$table.append(rowsArray); | |||
} | |||
setTimeout(function() { | |||
setupTableSorting($table, tableIndex); | |||
}, 10); | |||
}); | |||
} | |||
// Initialize table sorting on page load | |||
$(document).ready(function() { | |||
initMobileSorting(); | initMobileSorting(); | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
initMobileSorting(); | initMobileSorting(); | ||
}); | }); | ||
}); | }); | ||