This repository has been archived on 2019-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
httpd-ldap/assets/listing.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-04-12 14:27:43 +02:00
document.addEventListener('DOMContentLoaded', () => {
let searchField = document.createElement('input')
searchField.id = 'search-field'
searchField.autofocus = true
document.querySelector('body').insertBefore(searchField, document.querySelector('table'))
const rows = [...document.querySelectorAll('tr.even, tr.odd')]
pdLink = rows[0].querySelector('.indexcolname a')
if (pdLink.innerText == 'Parent Directory') {
pdLink.href = '../'
pdLink.text = '..'
}
document.querySelector('#search-field').addEventListener("input", e => {
const searchValue = e.target.value.toLowerCase()
rows.forEach(row => {
console.log(row)
const file = row.querySelector('.indexcolname a').innerText
if (!file.toLowerCase().startsWith(searchValue)) {
row.style.display = 'none'
} else {
row.style.display = 'table-row'
}
})
const visibleRows = [...document.querySelectorAll('tr[style="display: table-row;"]')]
if (visibleRows.length === 1) {
window.location = visibleRows[0].querySelector('td a').href
}
})
})