557
edits
No edit summary Tag: Reverted |
No edit summary |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
//Final working Common.js | |||
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=User:Gurwinder/Edittool.js&action=raw&ctype=text/javascript'); | mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=User:Gurwinder/Edittool.js&action=raw&ctype=text/javascript'); | ||
'MediaWiki:InterWikiTransclusion.js' | |||
// Turn <span class="mw-charinsert">foo</span> into a button that inserts "foo" | // Turn <span class="mw-charinsert">foo</span> into a button that inserts "foo" | ||
| Line 16: | Line 18: | ||
} ); | } ); | ||
} ); | } ); | ||
$( function(){ | $( function(){ | ||
| Line 576: | Line 579: | ||
msg('label-tooltip'), | msg('label-tooltip'), | ||
null, | null, | ||
mw.user.isAnon | (mw.user.isAnon === true) ? '#pt-createaccount' : '#pt-userpage' | ||
); | ); | ||
menu = $('<div>').addClass('mw-numerakri-menu').append(createSelector())[0]; | menu = $('<div>').addClass('mw-numerakri-menu').append(createSelector())[0]; | ||
| Line 626: | Line 629: | ||
}; | }; | ||
$.getScript( '//wiki.ekatrafoundation.org/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript' ) | //$.getScript( '//wiki.ekatrafoundation.org/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript' ) | ||
.done( function() { | //.done( function() { | ||
// importScript('MediaWiki:InterWikiTransclusion.js'); | |||
// importScript('MediaWiki:TranscludedIn.js'); | |||
// importScript('MediaWiki:Compare.js'); | |||
} ); | //} ); | ||
$.getScript('//wiki.ekatrafoundation.org/index.php?title=MediaWiki:Base.js&action=raw&ctype=text/javascript') | |||
.done(function () { | |||
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=MediaWiki:InterWikiTransclusion.js&action=raw&ctype=text/javascript'); | |||
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=MediaWiki:TranscludedIn.js&action=raw&ctype=text/javascript'); | |||
mw.loader.load('//wiki.ekatrafoundation.org/index.php?title=MediaWiki:Compare.js&action=raw&ctype=text/javascript'); | |||
}); | |||
/* Footnotes as tooltip - from it.wikipedia.org - request by Candalua */ | /* Footnotes as tooltip - from it.wikipedia.org - request by Candalua */ | ||
$( function () | $( function () | ||
{ | { | ||
| Line 697: | Line 706: | ||
}); | }); | ||
if (mw.user.isAnon | if (mw.user.isAnon) { // 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 | ||
}); | }); | ||
} | } | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 730: | Line 738: | ||
$('#bodyContent').append(downloadButton); | $('#bodyContent').append(downloadButton); | ||
}); | }); | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 745: | Line 752: | ||
} | } | ||
}); | }); | ||
$(document).ready(function() { | $(document).ready(function() { | ||
| Line 779: | Line 784: | ||
} | } | ||
}); | }); | ||
}); | |||
// 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(); | ||
}); | }); | ||
}); | }); | ||