Fix some alginment issues

This commit is contained in:
2020-10-20 10:48:52 +02:00
parent 65299d825c
commit a6b50d2a8e
7 changed files with 34 additions and 15 deletions

View File

@@ -90,6 +90,7 @@ DirectoryElement.prototype.renderFiles = function() {
// search term will be put into visibleFiles. The visibleFiles array will then
// be rendered by renderVisibleFiles
DirectoryElement.prototype.search = function(term) {
term = term.toLowerCase()
this.lastSearchTerm = term
this.visibleFiles = []
@@ -102,8 +103,18 @@ DirectoryElement.prototype.search = function(term) {
return
}
let fileName = ""
for (let i in this.allFiles) {
if (this.allFiles[i].name.toLowerCase().includes(term.toLowerCase())) {
fileName = this.allFiles[i].name.toLowerCase()
// If there's an exact match we'll show it as the only result
if (fileName === term) {
this.visibleFiles = [i]
break
}
// If a file name contains the search term we include it in the results
if (fileName.includes(term)) {
this.visibleFiles.push(i)
}
}
@@ -112,6 +123,15 @@ DirectoryElement.prototype.search = function(term) {
this.renderVisibleFiles(true)
}
// searchSubmit opens the first file in the search results
DirectoryElement.prototype.searchSubmit = function() {
if (this.visibleFiles.length === 0) {
return // There are no files visible
}
window.location = this.getVisibleFile(0).href
}
DirectoryElement.prototype.sortBy = function(field) {
if (field === "") {
// If no sort field is provided we use the last used sort field
@@ -169,7 +189,7 @@ DirectoryElement.prototype.createFileButton = function(file, index) {
let el = document.createElement("a")
el.classList = "node"
el.href = file.href
el.target = "_blank"
// el.target = "_blank"
el.title = file.name
el.setAttribute("fileindex", index)

View File

@@ -14,10 +14,14 @@ function FileManager(windowElement) {
document.addEventListener("keydown", e => { this.keyboardEvent(e) })
this.inputSearch.addEventListener("keyup", e => {
if (e.keyCode === 27) {
if (e.keyCode === 27) { // Escape
e.preventDefault()
this.inputSearch.blur()
return
} else if (e.keyCode === 13) { // Enter
e.preventDefault()
this.directoryElement.searchSubmit()
return
}
requestAnimationFrame(() => {
this.directoryElement.search(this.inputSearch.value)

View File

@@ -67,7 +67,6 @@ Viewer.prototype.setFile = function(file) {
this.file = file
if (this.isList) {
document.getElementById("file_viewer_headerbar_title").style.lineHeight = "1em"
document.getElementById("file_viewer_list_title").innerText = this.title
document.getElementById("file_viewer_file_title").innerText = file.name
document.title = this.title + " ~ " + file.name + " ~ pixeldrain"