add option to delete files

This commit is contained in:
2020-02-18 14:57:27 +01:00
parent 408e3f7e52
commit 449c69b12d
20 changed files with 524 additions and 212 deletions

View File

@@ -53,7 +53,7 @@ function DirectoryElement(directoryArea, footer) {
// files in the directory and the last scroll position. These are used for
// rendering the file list correctly
// type: {icon, name, href, type, size, sizeLabel, dateCreated}
// type: {icon, name, href, type, size, sizeLabel, dateCreated, selected}
this.allFiles = []
// This array contains indexes referring to places in the allFiles array
@@ -77,6 +77,7 @@ DirectoryElement.prototype.addFile = function(icon, name, href, type, size, size
size: size,
sizeLabel: sizeLabel,
dateCreated: dateCreated,
selected: false,
})
}

View File

@@ -0,0 +1,99 @@
function DirectoryNode(file, index) {
this.el = document.createElement("div")
this.el.classList = "node"
if (file.selected) {
this.el.classList += " node_selected"
}
this.el.href = file.href
this.el.target = "_blank"
this.el.title = file.name
this.el.setAttribute("fileindex", index)
this.el.addEventListener("click", e => {
if (e.detail > 1) {
return // Prevent dblclick from triggering click
}
if (e.which == 2) {
// Middle mouse button opens the file in a new window
this.open(true)
return
}
this.select()
})
this.el.addEventListener("tap")
this.el.addEventListener("dblclick", e => {
this.open(false)
})
{
let cell = document.createElement("div")
let thumb = document.createElement("img")
thumb.src = file.icon
cell.appendChild(thumb)
let label = document.createElement("span")
label.innerText = file.name
cell.appendChild(label)
cell.appendChild(label)
this.el.appendChild(cell)
}
{
let cell = document.createElement("div")
cell.style.width = this.fieldDateWidth
let label = document.createElement("span")
label.innerText = printDate(new Date(file.dateCreated), true, true, false)
cell.appendChild(label)
this.el.appendChild(cell)
}
{
let cell = document.createElement("div")
cell.style.width = this.fieldSizeWidth
let label = document.createElement("span")
label.innerText = file.sizeLabel
cell.appendChild(label)
this.el.appendChild(cell)
}
{
let cell = document.createElement("div")
cell.style.width = this.fieldTypeWidth
let label = document.createElement("span")
label.innerText = file.type
cell.appendChild(label)
this.el.appendChild(cell)
}
return this.el
}
DirectoryNode.prototype.select = function() {
if (this.el.classList.contains("node_selected")) {
this.el.classList = "node"
file.selected = false
} else {
this.el.classList = "node node_selected"
file.selected = true
}
}
DirectoryNode.prototype.open = function(newTab) {
if (newTab) {
window.open(file.href, "_blank")
} else {
window.open(file.href)
}
}
DirectoryNode.prototype.click = function(e) {
if (e.detail > 1) {
return // Prevent dblclick from triggering click
}
if (e.which == 2) {
// Middle mouse button opens the file in a new window
e.preventDefault()
window.open(file.href, "_blank")
return
}
}
DirectoryNode.prototype.doubleClick = function() {
window.open(file.href)
}