MediaWiki:Common.js: Difference between revisions
From Emmy The Robot Fandom Wiki
Content added Content deleted
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
searchInput.setAttribute('type', 'text'); |
searchInput.setAttribute('type', 'text'); |
||
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
searchInput.setAttribute('id', 'mediawiki-text-parser-input'); |
||
searchInput.setAttribute('placeholder', 'Type to |
searchInput.setAttribute('placeholder', 'Type to search1'); |
||
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild); |
document.getElementById('mw-content-text').insertBefore(searchInput, document.getElementById('mw-content-text').firstChild); |
||
// Get the table |
|||
var table = document.querySelector('table.wikitable.sortable.mw-datatable.jquery-tablesorter'); |
|||
// Attach an event listener to the search input field |
// Attach an event listener to the search input field |
||
Line 20: | Line 23: | ||
var searchText = this.value.toLowerCase(); |
var searchText = this.value.toLowerCase(); |
||
// Get all |
// Get all rows in the table |
||
var rows = |
var rows = table.querySelectorAll('tr'); |
||
// Loop through each row |
// Loop through each row |
||
rows.forEach(function(row) { |
rows.forEach(function(row, index) { |
||
if (index === 0) { |
|||
// Show the first row (headers) always |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
// Set the display property of the row and its cells |
|||
⚫ | |||
row.style.display = 'table-row'; |
row.style.display = 'table-row'; |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
Array.from(rowCells).forEach(function(cell) { |
Array.from(rowCells).forEach(function(cell) { |
||
var cellText = cell.textContent.toLowerCase(); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
}); |
}); |
||
⚫ | |||
// Set the display property of the row and its cells |
|||
⚫ | |||
row.style.display = 'table-row'; |
|||
⚫ | |||
cell.style.display = 'table-cell'; |
|||
⚫ | |||
} else { |
|||
row.style.display = 'none'; |
|||
⚫ | |||
} |
} |
||
}); |
}); |