557
edits
No edit summary |
No edit summary |
||
| (31 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
mw.loader.load('// | //Final working Common.js | ||
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" | ||
// into the edit box: | // into the edit box: | ||
| Line 15: | Line 18: | ||
} ); | } ); | ||
} ); | } ); | ||
$( function(){ | $( function(){ | ||
| Line 575: | 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 625: | 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 694: | Line 704: | ||
screslist[fitelement].style.display = "block"; | screslist[fitelement].style.display = "block"; | ||
} | } | ||
}); | |||
if (mw.user.isAnon) { // Check if the user is anonymous | |||
$(function () { | |||
$('.ext-wikisource-download-button').hide(); // Hide the button for anonymous users | |||
}); | |||
} | |||
$(document).ready(function() { | |||
// Get the page title | |||
var pageTitle = mw.config.get('wgTitle'); | |||
// Encode the title and replace spaces with '%20' | |||
var encodedTitle = encodeURIComponent(pageTitle).replace(/%20/g, '%20'); // Correctly handle spaces | |||
// Create the download button | |||
var downloadButton = $('<a>') | |||
.attr('href', 'https://wiki.ekatrafoundation.org/images/epub/' + encodedTitle + '.epub') | |||
.attr('download', '') // Suggests to download the file rather than opening it | |||
.text('Download EPUB') | |||
.css({ | |||
'display': 'inline-block', | |||
'padding': '8px 16px', | |||
'background-color': '#4CAF50', | |||
'color': '#ffffff', | |||
'text-align': 'center', | |||
'border-radius': '4px', | |||
'text-decoration': 'none', | |||
'margin-top': '10px' | |||
}); | |||
// Add the button to the page content | |||
$('#bodyContent').append(downloadButton); | |||
}); | |||
$(document).ready(function() { | |||
// Get the page title from the MediaWiki configuration | |||
var pageTitle = mw.config.get('wgTitle'); | |||
// Check if the page title contains a forward slash | |||
if (pageTitle.indexOf('/') === -1) { | |||
// Show the download button if it's a top-level page | |||
$('a[href*="/find_epub.php"]').show(); | |||
} else { | |||
// Hide the download button if it's a subpage | |||
$('a[href*="/find_epub.php"]').hide(); | |||
} | |||
}); | |||
$(document).ready(function() { | |||
var $element = $('#editpage-specialchars'); | |||
var isDragging = false; | |||
var startX, startY, initialX, initialY; | |||
$element.on('mousedown', function(e) { | |||
isDragging = true; | |||
startX = e.clientX; | |||
startY = e.clientY; | |||
initialX = $element.offset().left; | |||
initialY = $element.offset().top; | |||
$element.addClass('dragging'); | |||
}); | |||
$(document).on('mousemove', function(e) { | |||
if (isDragging) { | |||
var dx = e.clientX - startX; | |||
var dy = e.clientY - startY; | |||
$element.css({ | |||
top: initialY + dy + 'px', | |||
left: initialX + dx + 'px' | |||
}); | |||
} | |||
}); | |||
$(document).on('mouseup', function() { | |||
if (isDragging) { | |||
isDragging = false; | |||
$element.removeClass('dragging'); | |||
} | |||
}); | |||
}); | |||
// 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(); | |||
mw.hook('wikipage.content').add(function() { | |||
initMobileSorting(); | |||
}); | |||
}); | }); | ||