filebrowser/_embed/public/js/listing.js

567 lines
15 KiB
JavaScript
Raw Normal View History

2016-12-30 11:15:10 +00:00
'use strict';
2017-01-01 22:40:12 +00:00
var listing = {
2017-01-03 17:06:04 +00:00
selectMultiple: false
2017-01-01 22:40:12 +00:00
};
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
listing.reload = function (callback) {
2017-01-03 17:06:04 +00:00
let request = new XMLHttpRequest();
request.open('GET', window.location);
request.setRequestHeader('Minimal', 'true');
request.send();
2017-01-03 17:35:13 +00:00
request.onreadystatechange = function () {
if(request.readyState == 4) {
if(request.status == 200) {
2017-01-03 17:06:04 +00:00
document.querySelector('body main').innerHTML = request.responseText;
listing.addDoubleTapEvent();
2017-01-03 17:35:13 +00:00
if(typeof callback == 'function') {
2017-01-03 17:06:04 +00:00
callback();
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:35:13 +00:00
listing.itemDragStart = function (event) {
2017-01-03 17:06:04 +00:00
let el = event.target;
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
for(let i = 0; i < 5; i++) {
if(!el.classList.contains('item')) {
2017-01-03 17:06:04 +00:00
el = el.parentElement;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
event.dataTransfer.setData("id", el.id);
event.dataTransfer.setData("name", el.querySelector('.name').innerHTML);
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.itemDragOver = function (event) {
2017-01-03 17:06:04 +00:00
event.preventDefault();
let el = event.target;
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
for(let i = 0; i < 5; i++) {
if(!el.classList.contains('item')) {
2017-01-03 17:06:04 +00:00
el = el.parentElement;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
el.style.opacity = 1;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.itemDrop = function (e) {
2017-01-03 17:06:04 +00:00
e.preventDefault();
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
let el = e.target,
2017-01-03 17:35:13 +00:00
id = e.dataTransfer.getData("id"),
name = e.dataTransfer.getData("name");
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
if(id == "" || name == "") return;
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
for(let i = 0; i < 5; i++) {
if(!el.classList.contains('item')) {
2017-01-03 17:06:04 +00:00
el = el.parentElement;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
if(el.id === id) return;
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
let oldLink = document.getElementById(id).dataset.url,
2017-01-03 17:35:13 +00:00
newLink = el.dataset.url + name;
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
webdav.move(oldLink, newLink)
2017-01-03 17:35:13 +00:00
.then(() => listing.reload())
.catch(e => console.log(e));
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.documentDrop = function (event) {
2017-01-03 17:06:04 +00:00
event.preventDefault();
let dt = event.dataTransfer,
2017-01-03 17:35:13 +00:00
files = dt.files,
el = event.target,
items = document.getElementsByClassName('item');
2017-01-03 17:06:04 +00:00
2017-01-03 17:35:13 +00:00
for(let i = 0; i < 5; i++) {
if(el != null && !el.classList.contains('item')) {
2017-01-03 17:06:04 +00:00
el = el.parentElement;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 15:29:36 +00:00
2017-01-03 17:35:13 +00:00
if(files.length > 0) {
if(el != null && el.classList.contains('item') && el.dataset.dir == "true") {
2017-01-03 17:06:04 +00:00
listing.handleFiles(files, el.querySelector('.name').innerHTML + "/");
return;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:06:04 +00:00
listing.handleFiles(files, "");
} else {
Array.from(items).forEach(file => {
file.style.opacity = 1;
});
}
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.rename = function (event) {
if(!selectedItems.length || selectedItems.length > 1) {
2017-01-03 17:06:04 +00:00
return false;
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
let item = document.getElementById(selectedItems[0]);
2016-12-31 18:35:27 +00:00
2017-01-03 17:35:13 +00:00
if(item.classList.contains('disabled')) {
2017-01-03 17:06:04 +00:00
return false;
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
let link = item.dataset.url,
2017-01-03 17:35:13 +00:00
field = item.querySelector('.name'),
name = field.innerHTML;
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
let submit = (event) => {
event.preventDefault();
2016-12-31 18:35:27 +00:00
2017-01-03 17:06:04 +00:00
let newName = event.currentTarget.querySelector('input').value,
2017-01-03 18:13:08 +00:00
newLink = removeLastDirectoryPartOf(link) + "/" + newName;
2017-01-03 17:06:04 +00:00
closePrompt(event);
2017-01-03 18:13:08 +00:00
buttons.setLoading('rename');
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
webdav.move(link, newLink).then(() => {
listing.reload(() => {
newName = btoa(newName);
selectedItems = [newName];
document.getElementById(newName).setAttribute("aria-selected", true);
listing.handleSelectionChange();
});
2016-12-31 18:35:27 +00:00
2017-01-03 18:13:08 +00:00
buttons.setDone('rename');
2017-01-03 17:06:04 +00:00
}).catch(error => {
field.innerHTML = name;
2017-01-03 18:13:08 +00:00
buttons.setDone('rename', false);
2017-01-03 17:06:04 +00:00
console.log(error);
});
2016-12-30 11:15:10 +00:00
return false;
2017-01-03 17:06:04 +00:00
}
let clone = document.importNode(templates.question.content, true);
clone.querySelector('h3').innerHTML = 'Rename';
clone.querySelector('input').value = name;
clone.querySelector('.ok').innerHTML = 'Rename';
clone.querySelector('form').addEventListener('submit', submit);
document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active');
return false;
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:35:13 +00:00
listing.handleFiles = function (files, base) {
2017-01-03 18:13:08 +00:00
buttons.setLoading('upload');
let promises = [];
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
for(let file of files) {
2017-01-03 17:06:04 +00:00
promises.push(webdav.put(window.location.pathname + base + file.name, file));
}
Promise.all(promises)
2017-01-03 17:35:13 +00:00
.then(() => {
listing.reload();
2017-01-03 18:13:08 +00:00
buttons.setDone('upload');
2017-01-03 17:35:13 +00:00
})
.catch(e => {
console.log(e);
2017-01-03 18:13:08 +00:00
buttons.setDone('upload', false);
2017-01-03 17:35:13 +00:00
})
2017-01-03 17:06:04 +00:00
return false;
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:35:13 +00:00
listing.unselectAll = function () {
2017-01-03 17:06:04 +00:00
let items = document.getElementsByClassName('item');
Array.from(items).forEach(link => {
link.setAttribute("aria-selected", false);
});
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
selectedItems = [];
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
listing.handleSelectionChange();
return false;
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:35:13 +00:00
listing.handleSelectionChange = function (event) {
2017-01-03 17:06:04 +00:00
listing.redefineDownloadURLs();
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
let selectedNumber = selectedItems.length,
2017-01-03 17:35:13 +00:00
fileAction = document.getElementById("file-only");
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
if(selectedNumber) {
2017-01-03 17:06:04 +00:00
fileAction.classList.remove("disabled");
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
if(selectedNumber > 1) {
2017-01-03 17:06:04 +00:00
buttons.open.classList.add("disabled");
buttons.rename.classList.add("disabled");
}
2017-01-01 22:40:12 +00:00
2017-01-03 17:35:13 +00:00
if(selectedNumber == 1) {
if(document.getElementById(selectedItems[0]).dataset.dir == "true") {
2017-01-03 17:06:04 +00:00
buttons.open.classList.add("disabled");
} else {
buttons.open.classList.remove("disabled");
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
buttons.rename.classList.remove("disabled");
2016-12-30 11:15:10 +00:00
}
return false;
2017-01-03 17:06:04 +00:00
}
fileAction.classList.add("disabled");
return false;
2016-12-31 15:29:36 +00:00
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
listing.redefineDownloadURLs = function () {
2017-01-03 17:06:04 +00:00
let files = "";
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
for(let i = 0; i < selectedItems.length; i++) {
2017-01-03 17:06:04 +00:00
let url = document.getElementById(selectedItems[i]).dataset.url;
files += url.replace(window.location.pathname, "") + ",";
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
files = files.substring(0, files.length - 1);
files = encodeURIComponent(files);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
let links = document.querySelectorAll("#download ul a");
Array.from(links).forEach(link => {
link.href = "?download=" + link.dataset.format + "&files=" + files;
});
2016-12-30 11:15:10 +00:00
}
2017-01-03 17:35:13 +00:00
listing.openItem = function (event) {
2017-01-03 17:06:04 +00:00
window.location = event.currentTarget.dataset.url;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.selectItem = function (event) {
2017-01-03 17:06:04 +00:00
let el = event.currentTarget;
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
if(selectedItems.length != 0) event.preventDefault();
if(selectedItems.indexOf(el.id) == -1) {
if(!event.ctrlKey && !listing.selectMultiple) listing.unselectAll();
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
el.setAttribute("aria-selected", true);
selectedItems.push(el.id);
} else {
el.setAttribute("aria-selected", false);
selectedItems.removeElement(el.id);
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
listing.handleSelectionChange();
return false;
2016-12-31 15:29:36 +00:00
}
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
listing.newFileButton = function (event) {
2017-01-03 17:06:04 +00:00
event.preventDefault();
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
let clone = document.importNode(templates.question.content, true);
clone.querySelector('h3').innerHTML = 'New file';
clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir.';
clone.querySelector('.ok').innerHTML = 'Create';
clone.querySelector('form').addEventListener('submit', listing.newFilePrompt);
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
document.querySelector('body').appendChild(clone)
document.querySelector('.overlay').classList.add('active');
document.querySelector('.prompt').classList.add('active');
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.newFilePrompt = function (event) {
2017-01-03 17:06:04 +00:00
event.preventDefault();
2017-01-03 18:13:08 +00:00
buttons.setLoading('new');
2017-01-03 17:06:04 +00:00
2017-01-03 18:13:08 +00:00
let name = event.currentTarget.querySelector('input').value;
2017-01-03 17:06:04 +00:00
2017-01-03 18:13:08 +00:00
webdav.new(window.location.pathname + name)
.then(() => {
buttons.setDone('new');
2017-01-03 17:06:04 +00:00
listing.reload();
2017-01-03 18:13:08 +00:00
})
.catch(e => {
console.log(e);
buttons.setDone('new', false);
});
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
closePrompt(event);
return false;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.updateColumns = function (event) {
2017-01-03 17:06:04 +00:00
let columns = Math.floor(document.getElementById('listing').offsetWidth / 300),
2017-01-03 17:35:13 +00:00
items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']);
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
items.style.width = `calc(${100/columns}% - 1em)`;
2016-12-31 15:29:36 +00:00
}
2017-01-03 17:35:13 +00:00
listing.addDoubleTapEvent = function () {
2017-01-03 17:06:04 +00:00
let items = document.getElementsByClassName('item'),
2017-01-03 17:35:13 +00:00
touches = {
id: '',
count: 0
};
2017-01-03 17:06:04 +00:00
Array.from(items).forEach(file => {
file.addEventListener('touchstart', event => {
2017-01-03 17:35:13 +00:00
if(touches.id != file.id) {
2017-01-03 17:06:04 +00:00
touches.id = file.id;
touches.count = 1;
setTimeout(() => {
touches.count = 0;
2017-01-03 23:12:18 +00:00
}, 300)
2017-01-03 17:06:04 +00:00
return;
}
touches.count++;
2017-01-03 17:35:13 +00:00
if(touches.count > 1) {
2017-01-03 17:06:04 +00:00
window.location = file.dataset.url;
}
2017-01-02 12:20:20 +00:00
});
2017-01-03 17:06:04 +00:00
});
2017-01-02 12:20:20 +00:00
}
2016-12-31 15:29:36 +00:00
// Keydown events
2016-12-31 21:04:47 +00:00
window.addEventListener('keydown', (event) => {
2017-01-03 17:35:13 +00:00
if(event.keyCode == 27) {
2017-01-03 17:06:04 +00:00
listing.unselectAll();
2016-12-31 18:35:27 +00:00
2017-01-03 17:35:13 +00:00
if(document.querySelectorAll('.prompt').length) {
2017-01-03 17:06:04 +00:00
closePrompt(event);
2016-12-31 18:35:27 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 18:35:27 +00:00
2017-01-03 17:35:13 +00:00
if(event.keyCode == 113) {
2017-01-03 17:06:04 +00:00
listing.rename();
}
2017-01-01 22:40:12 +00:00
2017-01-03 17:35:13 +00:00
if(event.ctrlKey || event.metaKey) {
switch(String.fromCharCode(event.which).toLowerCase()) {
case 's':
2017-01-03 17:10:30 +00:00
event.preventDefault();
window.location = "?download=true"
2016-12-31 21:04:47 +00:00
}
2017-01-03 17:06:04 +00:00
}
2016-12-31 15:29:36 +00:00
});
window.addEventListener("resize", () => {
2017-01-03 17:06:04 +00:00
listing.updateColumns();
2016-12-31 15:29:36 +00:00
});
2017-01-04 17:58:14 +00:00
listing.selectMoveFolder = function (event) {
2017-01-03 22:33:59 +00:00
if(event.target.getAttribute("aria-selected") === "true") {
event.target.setAttribute("aria-selected", false);
return;
} else {
if(document.querySelector(".file-list li[aria-selected=true]")) {
document.querySelector(".file-list li[aria-selected=true]").setAttribute("aria-selected", false);
}
event.target.setAttribute("aria-selected", true);
return;
}
}
2017-01-04 17:58:14 +00:00
listing.getJSON = function (link) {
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest();
request.open("GET", link);
request.setRequestHeader("Accept", "application/json");
request.onload = () => {
if(request.status == 200) {
resolve(request.responseText);
} else {
reject(request.statusText);
}
}
request.onerror = () => reject(request.statusText);
request.send();
});
}
listing.moveMakeItem = function (url, name) {
let node = document.createElement("li");
node.dataset.url = url;
node.innerHTML = name;
node.setAttribute("aria-selected", false);
node.addEventListener("dblclick", listing.moveDialogNext);
node.addEventListener("click", listing.selectMoveFolder);
return node;
}
listing.moveDialogNext = function (event) {
2017-01-03 22:33:59 +00:00
let request = new XMLHttpRequest(),
2017-01-04 17:58:14 +00:00
prompt = document.querySelector("form.prompt.active"),
list = prompt.querySelector("div.file-list ul");
2017-01-03 22:33:59 +00:00
2017-01-04 17:58:14 +00:00
prompt.addEventListener("submit", listing.moveSelected);
listing.getJSON(event.target.dataset.url)
.then((data) => {
2017-01-03 22:33:59 +00:00
let dirs = 0;
prompt.querySelector("ul").innerHTML = "";
prompt.querySelector('code').innerHTML = event.target.dataset.url;
2017-01-04 17:58:14 +00:00
if(event.target.dataset.url != baseURL + "/") {
let node = listing.moveMakeItem(removeLastDirectoryPartOf(event.target.dataset.url) + "/", "..")
list.appendChild(node);
2017-01-03 23:12:18 +00:00
}
2017-01-04 17:58:14 +00:00
if(JSON.parse(data) == null) {
2017-01-03 22:33:59 +00:00
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
return;
}
2017-01-04 17:58:14 +00:00
for(let f of JSON.parse(data)) {
2017-01-03 22:33:59 +00:00
if(f.IsDir === true) {
dirs++;
2017-01-04 17:58:14 +00:00
list.appendChild(listing.moveMakeItem(f.URL, f.Name));
2017-01-03 22:33:59 +00:00
}
}
2017-01-04 17:58:14 +00:00
if(dirs === 0)
2017-01-03 22:33:59 +00:00
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
2017-01-04 17:58:14 +00:00
})
.catch(e => console.log(e));
2017-01-03 22:33:59 +00:00
}
2017-01-04 17:58:14 +00:00
listing.moveSelected = function (event) {
2017-01-03 22:33:59 +00:00
event.preventDefault();
let promises = [];
buttons.setLoading("move");
for(let file of selectedItems) {
let fileElement = document.getElementById(file),
2017-01-04 17:58:14 +00:00
destFolder = event.target.querySelector("p code").innerHTML;
2017-01-22 12:23:33 +00:00
if(event.currentTarget.querySelector("li[aria-selected=true]") != null) {
destFolder = event.currentTarget.querySelector("li[aria-selected=true]").dataset.url;
}
2017-01-04 17:58:14 +00:00
let destPath = "/" + destFolder + "/" + fileElement.querySelector(".name").innerHTML;
destPath = destPath.replace('//', '/');
promises.push(webdav.move(fileElement.dataset.url, destPath));
2017-01-03 22:33:59 +00:00
}
Promise.all(promises)
.then(() => {
closePrompt(event);
buttons.setDone("move");
listing.reload();
})
.catch(e => {
console.log(e);
})
}
2017-01-04 17:58:14 +00:00
listing.moveEvent = function (event) {
2017-01-03 22:33:59 +00:00
if(event.currentTarget.classList.contains("disabled"))
return;
2017-01-04 17:58:14 +00:00
listing.getJSON(window.location.pathname)
.then((data) => {
let prompt = document.importNode(templates.move.content, true),
list = prompt.querySelector("div.file-list ul"),
dirs = 0;
2017-01-03 23:12:18 +00:00
2017-01-04 17:58:14 +00:00
prompt.querySelector("form").addEventListener("submit", listing.moveSelected);
prompt.querySelector('code').innerHTML = window.location.pathname;
2017-01-03 22:33:59 +00:00
2017-01-04 17:58:14 +00:00
if(window.location.pathname !== baseURL + "/") {
list.appendChild(listing.moveMakeItem(removeLastDirectoryPartOf(window.location.pathname) + "/", ".."));
}
2017-01-03 22:33:59 +00:00
2017-01-04 17:58:14 +00:00
for(let f of JSON.parse(data)) {
if(f.IsDir === true) {
dirs++;
list.appendChild(listing.moveMakeItem(f.URL, f.Name));
2017-01-03 22:33:59 +00:00
}
2017-01-04 17:58:14 +00:00
}
2017-01-03 22:33:59 +00:00
2017-01-04 17:58:14 +00:00
if(dirs === 0) {
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
2017-01-03 22:33:59 +00:00
}
2017-01-04 17:58:14 +00:00
document.body.appendChild(prompt);
document.querySelector(".overlay").classList.add("active");
document.querySelector(".prompt").classList.add("active");
})
.catch(e => console.log(e));
}
2017-01-03 22:33:59 +00:00
2016-12-31 15:29:36 +00:00
document.addEventListener('DOMContentLoaded', event => {
2017-01-03 17:06:04 +00:00
listing.updateColumns();
listing.addDoubleTapEvent();
2016-12-31 15:29:36 +00:00
2017-01-03 17:06:04 +00:00
buttons.rename = document.getElementById("rename");
buttons.upload = document.getElementById("upload");
buttons.new = document.getElementById('new');
buttons.download = document.getElementById('download');
2017-01-03 22:33:59 +00:00
buttons.move = document.getElementById("move");
2017-01-04 17:58:14 +00:00
buttons.move.addEventListener("click", listing.moveEvent);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
document.getElementById('multiple-selection-activate').addEventListener('click', event => {
listing.selectMultiple = true;
clickOverlay.click();
2017-01-01 23:38:11 +00:00
2017-01-03 17:06:04 +00:00
document.getElementById('multiple-selection').classList.add('active');
document.querySelector('body').style.paddingBottom = "4em";
})
2017-01-01 22:40:12 +00:00
2017-01-03 17:06:04 +00:00
document.getElementById('multiple-selection-cancel').addEventListener('click', event => {
listing.selectMultiple = false;
2017-01-01 22:40:12 +00:00
2017-01-03 17:06:04 +00:00
document.querySelector('body').style.paddingBottom = "0";
document.getElementById('multiple-selection').classList.remove('active');
})
2017-01-01 22:40:12 +00:00
2017-01-03 17:35:13 +00:00
if(user.AllowEdit) {
2017-01-03 17:06:04 +00:00
buttons.rename.addEventListener("click", listing.rename);
}
2017-01-01 23:38:11 +00:00
2017-01-03 17:06:04 +00:00
let items = document.getElementsByClassName('item');
2016-12-30 11:15:10 +00:00
2017-01-03 17:35:13 +00:00
if(user.AllowNew) {
2017-01-03 17:06:04 +00:00
buttons.upload.addEventListener("click", (event) => {
document.getElementById("upload-input").click();
});
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
buttons.new.addEventListener('click', listing.newFileButton);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
// Drag and Drop
2017-01-03 17:35:13 +00:00
document.addEventListener("dragover", function (event) {
2017-01-03 17:06:04 +00:00
event.preventDefault();
}, false);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
document.addEventListener("dragenter", (event) => {
Array.from(items).forEach(file => {
file.style.opacity = 0.5;
});
}, false);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
document.addEventListener("dragend", (event) => {
Array.from(items).forEach(file => {
file.style.opacity = 1;
});
}, false);
2016-12-30 11:15:10 +00:00
2017-01-03 17:06:04 +00:00
document.addEventListener("drop", listing.documentDrop, false);
}
2017-01-01 23:38:11 +00:00
});