From a1cefe9a74194c0e552e53bfb31f832355e86cbb Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 30 Dec 2016 11:32:54 +0000 Subject: [PATCH 1/2] updates --- _embed/public/js/common.js | 105 +++++++++++++++++++++++++++--------- _embed/public/js/listing.js | 40 +------------- _embed/templates/base.tmpl | 4 +- 3 files changed, 82 insertions(+), 67 deletions(-) diff --git a/_embed/public/js/common.js b/_embed/public/js/common.js index f3dd8a57..9ae6a028 100644 --- a/_embed/public/js/common.js +++ b/_embed/public/js/common.js @@ -180,19 +180,28 @@ function deleteEvent(event) { return false; } -var searchEvent = function(event) { - let value = this.value, - search = document.getElementById('search'), - scrollable = document.querySelector('#search > div'), - box = document.querySelector('#search > div div'); +function resetSearchText() { + let box = document.querySelector('#search > div div'); - if (value.length == 0) { - box.innerHTML = "Search or use one of your supported commands: " + user.Commands.join(", ") + "."; + if (user.AllowCommands) { + box.innerHTML = `Search or use one of your supported commands: ${user.Commands.join(", ")} `; + } else { + box.innerHTML = "Type and press enter to search."; + } +} + +function searchEvent(event) { + if (this.value.length == 0) { + resetSearchText(); return; } - let pieces = value.split(' '); - let supported = false; + let value = this.value, + search = document.getElementById('search'), + scrollable = document.querySelector('#search > div'), + box = document.querySelector('#search > div div'), + pieces = value.split(' '), + supported = false; user.Commands.forEach(function(cmd) { if (cmd == pieces[0]) { @@ -200,7 +209,7 @@ var searchEvent = function(event) { } }); - if (!supported) { + if (!supported || !user.AllowCommands) { box.innerHTML = "Press enter to search." } else { box.innerHTML = "Press enter to execute." @@ -210,8 +219,9 @@ var searchEvent = function(event) { box.innerHTML = ''; search.classList.add('ongoing'); - if (supported) { - var conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?command=true'); + if (supported && user.AllowCommands) { + let conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?command=true'); + conn.onopen = function() { conn.send(value); }; @@ -225,27 +235,69 @@ var searchEvent = function(event) { search.classList.remove('ongoing'); reloadListing(); } - } else { - box.innerHTML = ''; - let ul = box.querySelector('ul'); - var conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?search=true'); - conn.onopen = function() { - conn.send(value); - }; + return; + } - conn.onmessage = function(event) { - ul.innerHTML += '
  • ' + event.data + '
  • '; - scrollable.scrollTop = scrollable.scrollHeight; - } + box.innerHTML = ''; - conn.onclose = function(event) { - search.classList.remove('ongoing'); - } + let ul = box.querySelector('ul'), + conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?search=true'); + + conn.onopen = function() { + conn.send(value); + }; + + conn.onmessage = function(event) { + ul.innerHTML += '
  • ' + event.data + '
  • '; + scrollable.scrollTop = scrollable.scrollHeight; + } + + conn.onclose = function(event) { + search.classList.remove('ongoing'); } } } +function setupSearch() { + let search = document.getElementById("search"), + searchInput = search.querySelector("input"), + searchDiv = search.querySelector("div"), + hover = false, + focus = false; + + resetSearchText(); + + searchInput.addEventListener('focus', event => { + focus = true; + search.classList.add('active'); + }); + + searchDiv.addEventListener('mouseover', event => { + hover = true; + search.classList.add('active'); + }); + + searchInput.addEventListener('blur', event => { + focus = false; + if (hover) return; + search.classList.remove('active'); + }); + + search.addEventListener('mouseleave', event => { + hover = false; + if (focus) return; + search.classList.remove('active'); + }); + + search.addEventListener("click", event => { + search.classList.add("active"); + search.querySelector("input").focus(); + }); + + searchInput.addEventListener('keyup', searchEvent); +} + /* * * * * * * * * * * * * * * * * * * BOOTSTRAP * @@ -265,5 +317,6 @@ document.addEventListener("DOMContentLoaded", function(event) { buttons.delete.addEventListener("click", deleteEvent); } + setupSearch(); return false; }); \ No newline at end of file diff --git a/_embed/public/js/listing.js b/_embed/public/js/listing.js index 985e13ac..f8338b00 100644 --- a/_embed/public/js/listing.js +++ b/_embed/public/js/listing.js @@ -259,7 +259,7 @@ var redefineDownloadURLs = function() { } -document.addEventListener('listing', event => { +document.addEventListener('DOMContentLoaded', event => { // Handles the current view mode and adds the event to the button handleViewType(document.getCookie("view-list")); document.getElementById("view").addEventListener("click", viewEvent); @@ -283,43 +283,7 @@ document.addEventListener('listing', event => { } }); - if (user.AllowCommands) { - let search = document.getElementById("search"), - searchInput = search.querySelector("input"), - searchDiv = search.querySelector("div"), - hover = false, - focus = false; - - searchInput.addEventListener('focus', event => { - focus = true; - search.classList.add('active'); - }); - - searchDiv.addEventListener('mouseover', event => { - hover = true; - search.classList.add('active'); - }); - - searchInput.addEventListener('blur', event => { - focus = false; - if (hover) return; - search.classList.remove('active'); - }); - - search.addEventListener('mouseleave', event => { - hover = false; - if (focus) return; - search.classList.remove('active'); - }); - - search.addEventListener("click", event => { - search.classList.add("active"); - search.querySelector("input").focus(); - }); - - document.querySelector('#search > div div').innerHTML = "Search or use one of your supported commands: " + user.Commands.join(", ") + "."; - document.querySelector('#search input').addEventListener('keyup', searchEvent); - } + if (user.AllowEdit) { // Enables rename button diff --git a/_embed/templates/base.tmpl b/_embed/templates/base.tmpl index 86892bc0..179095a5 100644 --- a/_embed/templates/base.tmpl +++ b/_embed/templates/base.tmpl @@ -32,16 +32,14 @@

    File Manager

    - {{ if .User.AllowCommands }} - {{ end }}
    exit_to_app Logout From 698bdb7da8006b66c55ee577b5ccb80fd8c69248 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Fri, 30 Dec 2016 11:36:20 +0000 Subject: [PATCH 2/2] fix bug --- _embed/public/js/common.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/_embed/public/js/common.js b/_embed/public/js/common.js index 40f7fa14..b227ba5e 100644 --- a/_embed/public/js/common.js +++ b/_embed/public/js/common.js @@ -167,7 +167,8 @@ function deleteEvent(event) { buttons.delete.changeToDone(request.status != 204, html); } } - r.send(); + + request.send(); }); return false; @@ -211,9 +212,15 @@ 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); + } if (supported && user.AllowCommands) { - let conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?command=true'); + let conn = new WebSocket(`ws://${url}?command=true`); conn.onopen = function() { conn.send(value); @@ -235,7 +242,7 @@ function searchEvent(event) { box.innerHTML = '
      '; let ul = box.querySelector('ul'), - conn = new WebSocket('ws://' + window.location.host + window.location.pathname + '?search=true'); + conn = new WebSocket(`ws://${url}?search=true`); conn.onopen = function() { conn.send(value);