update.
parent
68aea511fa
commit
6bc5b881d6
|
@ -3,7 +3,7 @@
|
|||
var selectedItems = [];
|
||||
|
||||
// Array prototype function to remove an element
|
||||
Array.prototype.removeElement = function(element) {
|
||||
Array.prototype.removeElement = function (element) {
|
||||
var i = this.indexOf(element);
|
||||
if (i != -1) {
|
||||
this.splice(i, 1);
|
||||
|
@ -11,7 +11,7 @@ Array.prototype.removeElement = function(element) {
|
|||
}
|
||||
|
||||
// Array prototype function to replace an element
|
||||
Array.prototype.replaceElement = function(oldEl, newEl) {
|
||||
Array.prototype.replaceElement = function (oldEl, newEl) {
|
||||
var i = this.indexOf(oldEl);
|
||||
if (i != -1) {
|
||||
this[i] = newEl;
|
||||
|
@ -19,24 +19,24 @@ Array.prototype.replaceElement = function(oldEl, newEl) {
|
|||
}
|
||||
|
||||
// Document prototype function to send a costum event to itself
|
||||
Document.prototype.sendCostumEvent = function(text) {
|
||||
Document.prototype.sendCostumEvent = function (text) {
|
||||
document.dispatchEvent(new CustomEvent(text));
|
||||
}
|
||||
|
||||
// Document prototype to get a cookie content
|
||||
Document.prototype.getCookie = function(name) {
|
||||
Document.prototype.getCookie = function (name) {
|
||||
var re = new RegExp("(?:(?:^|.*;\\s*)" + name + "\\s*\\=\\s*([^;]*).*$)|^.*$");
|
||||
return document.cookie.replace(re, "$1");
|
||||
}
|
||||
|
||||
// Changes a button to the loading animation
|
||||
Element.prototype.changeToLoading = function() {
|
||||
Element.prototype.changeToLoading = function () {
|
||||
let element = this;
|
||||
let originalText = element.innerHTML;
|
||||
|
||||
element.style.opacity = 0;
|
||||
|
||||
setTimeout(function() {
|
||||
setTimeout(function () {
|
||||
element.innerHTML = '<i class="material-icons spin">autorenew</i>';
|
||||
element.style.opacity = 1;
|
||||
}, 200);
|
||||
|
@ -45,7 +45,7 @@ Element.prototype.changeToLoading = function() {
|
|||
}
|
||||
|
||||
// Changes an element to done animation
|
||||
Element.prototype.changeToDone = function(error, html) {
|
||||
Element.prototype.changeToDone = function (error, html) {
|
||||
this.style.opacity = 0;
|
||||
|
||||
let thirdStep = () => {
|
||||
|
@ -79,7 +79,7 @@ Element.prototype.changeToDone = function(error, html) {
|
|||
}
|
||||
|
||||
// Event for toggling the mode of view
|
||||
var viewEvent = function(event) {
|
||||
var viewEvent = function (event) {
|
||||
let cookie = document.getCookie('view-list');
|
||||
let listing = document.getElementById('listing');
|
||||
|
||||
|
@ -94,7 +94,7 @@ var viewEvent = function(event) {
|
|||
}
|
||||
|
||||
// Handles the view type change
|
||||
var handleViewType = function(viewList) {
|
||||
var handleViewType = function (viewList) {
|
||||
let listing = document.getElementById('listing');
|
||||
let button = document.getElementById('view');
|
||||
|
||||
|
@ -110,7 +110,7 @@ var handleViewType = function(viewList) {
|
|||
}
|
||||
|
||||
// Handles the open file button event
|
||||
var openEvent = function(event) {
|
||||
var openEvent = function (event) {
|
||||
if (selectedItems.length) {
|
||||
window.open(selectedItems[0] + '?raw=true');
|
||||
return false;
|
||||
|
@ -121,7 +121,7 @@ var openEvent = function(event) {
|
|||
}
|
||||
|
||||
// Handles the back button event
|
||||
var backEvent = function(event) {
|
||||
var backEvent = function (event) {
|
||||
var items = document.getElementsByClassName('item');
|
||||
Array.from(items).forEach(link => {
|
||||
link.classList.remove('selected');
|
||||
|
@ -134,7 +134,7 @@ var backEvent = function(event) {
|
|||
}
|
||||
|
||||
// Handles the delete button event
|
||||
var deleteEvent = function(event) {
|
||||
var deleteEvent = function (event) {
|
||||
if (selectedItems.length) {
|
||||
Array.from(selectedItems).forEach(link => {
|
||||
let html = document.getElementById("delete").changeToLoading();
|
||||
|
@ -142,7 +142,7 @@ var deleteEvent = function(event) {
|
|||
|
||||
request.open('DELETE', link);
|
||||
request.send();
|
||||
request.onreadystatechange = function() {
|
||||
request.onreadystatechange = function () {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
document.getElementById(link).remove();
|
||||
|
@ -161,7 +161,7 @@ var deleteEvent = function(event) {
|
|||
let request = new XMLHttpRequest();
|
||||
request.open('DELETE', window.location);
|
||||
request.send();
|
||||
request.onreadystatechange = function() {
|
||||
request.onreadystatechange = function () {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status == 200) {
|
||||
window.location.pathname = RemoveLastDirectoryPartOf(window.location.pathname);
|
||||
|
@ -175,12 +175,12 @@ var deleteEvent = function(event) {
|
|||
}
|
||||
|
||||
// Prevent Default event
|
||||
var preventDefault = function(event) {
|
||||
var preventDefault = function (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
// Rename file event
|
||||
var renameEvent = function(event) {
|
||||
var renameEvent = function (event) {
|
||||
if (selectedItems.length) {
|
||||
Array.from(selectedItems).forEach(link => {
|
||||
let item = document.getElementById(link);
|
||||
|
@ -200,7 +200,7 @@ var renameEvent = function(event) {
|
|||
request.open('PATCH', link);
|
||||
request.setRequestHeader('Rename-To', newName);
|
||||
request.send();
|
||||
request.onreadystatechange = function() {
|
||||
request.onreadystatechange = function () {
|
||||
if (request.readyState == 4) {
|
||||
if (request.status != 200) {
|
||||
span.innerHTML = name;
|
||||
|
@ -247,7 +247,7 @@ var renameEvent = function(event) {
|
|||
}
|
||||
|
||||
// Download file event
|
||||
var downloadEvent = function(event) {
|
||||
var downloadEvent = function (event) {
|
||||
if (selectedItems.length) {
|
||||
Array.from(selectedItems).forEach(item => {
|
||||
window.open(item + "?download=true");
|
||||
|
@ -259,13 +259,13 @@ var downloadEvent = function(event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
var RemoveLastDirectoryPartOf = function(url) {
|
||||
var RemoveLastDirectoryPartOf = function (url) {
|
||||
var arr = url.split('/');
|
||||
arr.pop();
|
||||
return (arr.join('/'));
|
||||
}
|
||||
|
||||
document.addEventListener("changed-selected", function(event) {
|
||||
document.addEventListener("changed-selected", function (event) {
|
||||
var toolbar = document.getElementById("toolbar");
|
||||
var selectedNumber = selectedItems.length;
|
||||
|
||||
|
@ -291,7 +291,7 @@ document.addEventListener("changed-selected", function(event) {
|
|||
return false;
|
||||
});
|
||||
|
||||
var itemClickEvent = function(event) {
|
||||
var itemClickEvent = function (event) {
|
||||
var url = this.getElementsByTagName('a')[0].getAttribute('href');
|
||||
|
||||
if (selectedItems.length != 0) event.preventDefault();
|
||||
|
@ -308,7 +308,24 @@ var itemClickEvent = function(event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
var localizeDatetime = function (e, index, ar) {
|
||||
if (e.textContent === undefined) {
|
||||
return;
|
||||
}
|
||||
var d = new Date(e.getAttribute('datetime'));
|
||||
if (isNaN(d)) {
|
||||
d = new Date(e.textContent);
|
||||
if (isNaN(d)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
e.textContent = d.toLocaleString();
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function (event) {
|
||||
var timeList = Array.prototype.slice.call(document.getElementsByTagName("time"));
|
||||
timeList.forEach(localizeDatetime);
|
||||
|
||||
var items = document.getElementsByClassName('item');
|
||||
Array.from(items).forEach(link => {
|
||||
link.addEventListener('click', itemClickEvent);
|
||||
|
@ -338,6 +355,5 @@ document.addEventListener("DOMContentLoaded", function(event) {
|
|||
drop.style.backgroundColor = 'transparent';
|
||||
}; */
|
||||
|
||||
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{{ define "actions" }}
|
||||
<div>
|
||||
<div class="action" id="open"><i class="material-icons">open_in_new</i></div>
|
||||
<div class="action" id="rename"><i class="material-icons">mode_edit</i></div>
|
||||
<div class="action" id="download"><i class="material-icons">file_download</i></div>
|
||||
<div class="action" id="delete"><i class="material-icons">delete</i></div>
|
||||
</div>
|
||||
<div class="action" id="open"><i class="material-icons">open_in_new</i></div>
|
||||
{{ if .IsDir }}<div class="action" id="rename"><i class="material-icons">mode_edit</i></div>{{ end }}
|
||||
<div class="action" id="download"><i class="material-icons">file_download</i></div>
|
||||
<div class="action" id="delete"><i class="material-icons">delete</i></div>
|
||||
{{ end }}
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
<link rel="stylesheet" href="{{ .Config.BaseURL }}/_filemanagerinternal/css/styles.css">
|
||||
<script src="{{ .Config.BaseURL }}/_filemanagerinternal/js/application.js"></script>
|
||||
{{ if ne .Config.StyleSheet "" }}<style>{{ .Config.StyleSheet}}</style>{{ end }}
|
||||
{{ if .Config.HugoEnabled }}
|
||||
<!-- Hugo plugin stuff -->
|
||||
<link rel="stylesheet" href="{{ .Config.BaseURL }}/_hugointernal/css/styles.css">
|
||||
<script src="{{ .Config.BaseURL }}/_hugointernal/js/application.js"></script>
|
||||
{{ end }}
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
@ -17,17 +22,23 @@
|
|||
<div class="action disabled" id="prev"><i class="material-icons">subdirectory_arrow_left</i></div>{{ end }}
|
||||
<p><a href="{{ if eq .Config.BaseURL "" }}/{{ else }}{{ .Config.BaseURL }}{{ end }}">File Manager</a> {{ if ne .Name "/"}}<i class="material-icons">chevron_right</i> {{ .Name }}</p>{{ end }}
|
||||
</div>
|
||||
{{ if .IsDir}}
|
||||
<div>
|
||||
{{ if .IsDir}}
|
||||
<form>
|
||||
<i class="material-icons">search</i> <input type="text" placeholder="Search">
|
||||
</form>
|
||||
<div class="action" id="view"><i class="material-icons">view_headline</i></div>
|
||||
<div class="action" id="upload"><i class="material-icons">file_upload</i></div>
|
||||
</div>
|
||||
{{ else }}
|
||||
{{ template "actions" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ if .Config.HugoEnabled }}
|
||||
<!-- Hugo plugin stuff -->
|
||||
<div class="action" id="settings"><i class="material-icons">settings</i></div>
|
||||
<div class="action" id="logout"><i class="material-icons">exit_to_app</i></div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{{ if .IsDir }}
|
||||
|
@ -39,29 +50,11 @@
|
|||
{{ template "actions" . }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
<main>
|
||||
{{ template "content" .Data }}
|
||||
</main>
|
||||
<footer>
|
||||
Served with <a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a> and <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>.
|
||||
Served with <a rel="noopener noreferrer" href="https://caddyserver.com">Caddy</a> and <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">File Manager</a>. {{ if .Config.HugoEnabled }}With a flavour of <a rel="noopener noreferrer" href="https://github.com/hacdias/caddy-filemanager">Hugo</a>.{{ end }}
|
||||
</footer>
|
||||
<script type="text/javascript">
|
||||
function localizeDatetime(e, index, ar) {
|
||||
if (e.textContent === undefined) {
|
||||
return;
|
||||
}
|
||||
var d = new Date(e.getAttribute('datetime'));
|
||||
if (isNaN(d)) {
|
||||
d = new Date(e.textContent);
|
||||
if (isNaN(d)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
e.textContent = d.toLocaleString();
|
||||
}
|
||||
var timeList = Array.prototype.slice.call(document.getElementsByTagName("time"));
|
||||
timeList.forEach(localizeDatetime);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
14
page.go
14
page.go
|
@ -1,8 +1,6 @@
|
|||
package filemanager
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"log"
|
||||
|
@ -102,16 +100,18 @@ func (p *Page) AddTemplate(name string, assets AssetFunc, functions template.Fun
|
|||
|
||||
// PrintAsHTML formats the page in HTML and executes the template
|
||||
func (p Page) PrintAsHTML(w http.ResponseWriter) (int, error) {
|
||||
var buffer bytes.Buffer
|
||||
writer := bufio.NewWriter(&buffer)
|
||||
err := p.Tpl.Execute(writer, p.Info)
|
||||
// var buffer bytes.Buffer
|
||||
//writer := bufio.NewWriter(&buffer)
|
||||
err := p.Tpl.Execute(w, p.Info)
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
buffer.WriteTo(w)
|
||||
// _, err = buffer.WriteTo(w)
|
||||
// w.Write(buffer.Bytes())
|
||||
return http.StatusOK, nil
|
||||
}
|
||||
|
||||
|
|
5
setup.go
5
setup.go
|
@ -36,7 +36,8 @@ type Config struct {
|
|||
PathScope string
|
||||
Root http.FileSystem
|
||||
BaseURL string
|
||||
StyleSheet string
|
||||
StyleSheet string // Costum stylesheet
|
||||
HugoEnabled bool // This must be only used by Hugo plugin
|
||||
}
|
||||
|
||||
// parseConfiguration parses the configuration set by the user so it can
|
||||
|
@ -55,7 +56,7 @@ func parseConfiguration(c *caddy.Controller) ([]Config, error) {
|
|||
}
|
||||
|
||||
for c.Next() {
|
||||
var cfg = Config{PathScope: ".", BaseURL: ""}
|
||||
var cfg = Config{PathScope: ".", BaseURL: "", HugoEnabled: false}
|
||||
for c.NextBlock() {
|
||||
switch c.Val() {
|
||||
case "show":
|
||||
|
|
Loading…
Reference in New Issue