diff --git a/_embed/public/js/common.js b/_embed/public/js/common.js index e2745264..1e5f340d 100644 --- a/_embed/public/js/common.js +++ b/_embed/public/js/common.js @@ -61,7 +61,7 @@ Element.prototype.changeToDone = function(error, html) { let firstStep = () => { this.innerHTML = 'done'; if (error) { - this.innerHTML = 'close'; + this.innerHTML = 'close'; } this.style.opacity = 1; @@ -151,7 +151,7 @@ function deleteEvent(event) { let request = new XMLHttpRequest(), html = buttons.delete.changeToLoading(), el, url; - + if (single) { url = window.location.pathname; } else { @@ -174,7 +174,7 @@ function deleteEvent(event) { buttons.delete.changeToDone(request.status != 204, html); } } - + request.send(); }); @@ -219,9 +219,9 @@ function searchEvent(event) { if (event.keyCode == 13) { box.innerHTML = ''; search.classList.add('ongoing'); - + let url = window.location.host + window.location.pathname; - + if (document.getElementById("editor")) { url = removeLastDirectoryPartOf(url); } @@ -326,4 +326,4 @@ document.addEventListener("DOMContentLoaded", function(event) { setupSearch(); return false; -}); +}); \ No newline at end of file diff --git a/_embed/public/js/editor.js b/_embed/public/js/editor.js index 2c3b509d..d7e2093c 100644 --- a/_embed/public/js/editor.js +++ b/_embed/public/js/editor.js @@ -254,4 +254,4 @@ document.addEventListener("DOMContentLoaded", (event) => { }); return false; -}); +}); \ No newline at end of file diff --git a/_embed/public/js/listing.js b/_embed/public/js/listing.js index 27728b4d..df91e536 100644 --- a/_embed/public/js/listing.js +++ b/_embed/public/js/listing.js @@ -9,7 +9,6 @@ var reloadListing = function(callback) { if (request.readyState == 4) { if (request.status == 200) { document.querySelector('body main').innerHTML = request.responseText; - addNewDirEvents(); if (typeof callback == 'function') { callback(); @@ -120,16 +119,15 @@ var handleFiles = function(files, base) { return false; } -// Handles the back button event -var backEvent = function(event) { +function unselectAll() { var items = document.getElementsByClassName('item'); Array.from(items).forEach(link => { link.setAttribute("aria-selected", false); }); + selectedItems = []; - - var event = new CustomEvent('changed-selected'); - document.dispatchEvent(event); + + document.sendCostumEvent('changed-selected'); return false; } @@ -164,20 +162,6 @@ var handleViewType = function(viewList) { return false; } -var addNewDirEvents = function() { - document.getElementById('new').addEventListener('click', event => { - let newdir = document.getElementById('newdir'); - newdir.classList.add('enabled'); - newdir.focus(); - }); - - document.getElementById('newdir').addEventListener('blur', event => { - document.getElementById('newdir').classList.remove('enabled'); - }); - - document.getElementById('newdir').addEventListener('keydown', newDirEvent); -} - // Handles the new directory event var newDirEvent = function(event) { // TODO: create new dir button and new file button @@ -202,9 +186,7 @@ var newDirEvent = function(event) { request.onreadystatechange = function() { if (request.readyState == 4) { button.changeToDone((request.status != 201), html); - reloadListing(() => { - addNewDirEvents(); - }); + reloadListing(); } } } @@ -277,12 +259,10 @@ document.addEventListener('DOMContentLoaded', event => { // Add event to back button and executes back event on ESC document.addEventListener('keydown', (event) => { if (event.keyCode == 27) { - backEvent(event); + unselectAll(); } }); - - if (user.AllowEdit) { // Enables rename button document.getElementById("rename").addEventListener("click", renameEvent); @@ -294,7 +274,17 @@ document.addEventListener('DOMContentLoaded', event => { document.getElementById("upload-input").click(); }); - addNewDirEvents(); + document.getElementById('new').addEventListener('click', event => { + let newdir = document.getElementById('newdir'); + newdir.classList.add('enabled'); + newdir.focus(); + }); + + document.getElementById('newdir').addEventListener('blur', event => { + document.getElementById('newdir').classList.remove('enabled'); + }); + + document.getElementById('newdir').addEventListener('keydown', newDirEvent); // Drag and Drop let items = document.getElementsByClassName('item'); @@ -403,16 +393,16 @@ function itemDrop(e) { } } -function openItem(event) { +function openItemEvent(event) { window.location = event.currentTarget.dataset.url; } -function selectItem(event) { +function selectItemEvent(event) { let el = event.currentTarget; if (selectedItems.length != 0) event.preventDefault(); if (selectedItems.indexOf(el.id) == -1) { - if (!event.ctrlKey) backEvent(event); + if (!event.ctrlKey) unselectAll(); el.setAttribute("aria-selected", true); selectedItems.push(el.id); diff --git a/_embed/templates/base.tmpl b/_embed/templates/base.tmpl index 179095a5..2a1ba303 100644 --- a/_embed/templates/base.tmpl +++ b/_embed/templates/base.tmpl @@ -115,6 +115,15 @@
{{ template "content" . }} + + {{ if and (.User.AllowNew) (.IsDir) }} + +
+
+ add +
+
+ {{ end }}
diff --git a/_embed/templates/listing.tmpl b/_embed/templates/listing.tmpl index 80635123..eabbdf9c 100644 --- a/_embed/templates/listing.tmpl +++ b/_embed/templates/listing.tmpl @@ -8,8 +8,8 @@ {{ if .IsDir}}ondragover="itemDragOver(event)" ondrop="itemDrop(event)"{{ end }} draggable="true" class="item" - onclick="selectItem(event)" - ondblclick="openItem(event)" + onclick="selectItemEvent(event)" + ondblclick="openItemEvent(event)" data-dir="{{ .IsDir }}" data-url="{{ .URL }}" id="{{ EncodeBase64 .Name }}"> @@ -39,13 +39,4 @@ {{ end }} - -{{ if .User.AllowNew }} - -
-
- add -
-
-{{ end }} {{ end }}