This commit is contained in:
Henrique Dias 2017-01-03 17:10:30 +00:00
parent 7b81b0828f
commit ce9405341a
4 changed files with 669 additions and 669 deletions

View File

@ -4,7 +4,6 @@ go:
- tip - tip
install: install:
- go generate
- go get -u -v $(go list -f '{{join .Imports "\n"}}' ./... | sort | uniq | grep -v caddy-filemanager) - go get -u -v $(go list -f '{{join .Imports "\n"}}' ./... | sort | uniq | grep -v caddy-filemanager)
- go get -u -v github.com/mholt/caddy/caddyhttp - go get -u -v github.com/mholt/caddy/caddyhttp
- go get -u -v github.com/caddyserver/caddydev - go get -u -v github.com/caddyserver/caddydev
@ -12,7 +11,8 @@ install:
- go get github.com/gordonklaus/ineffassign - go get github.com/gordonklaus/ineffassign
script: script:
- diff <(echo -n) <(gofmt -s -d .)
- go generate
- sed -i 's/\_ \"github.com\/mholt\/caddy\/caddyhttp\"/\_ \"github.com\/mholt\/caddy\/caddyhttp\"\n\_ \"github.com\/hacdias\/caddy-filemanager\"/g' $GOPATH/src/github.com/mholt/caddy/caddy/caddymain/run.go - sed -i 's/\_ \"github.com\/mholt\/caddy\/caddyhttp\"/\_ \"github.com\/mholt\/caddy\/caddyhttp\"\n\_ \"github.com\/hacdias\/caddy-filemanager\"/g' $GOPATH/src/github.com/mholt/caddy/caddy/caddymain/run.go
- go build github.com/mholt/caddy/caddy - go build github.com/mholt/caddy/caddy
- diff <(echo -n) <(gofmt -s -d .)
- ineffassign . - ineffassign .

File diff suppressed because it is too large Load Diff

View File

@ -3,253 +3,253 @@
var editor = {}; var editor = {};
editor.textareaAutoGrow = function() { editor.textareaAutoGrow = function() {
let autogrow = function() { let autogrow = function() {
console.log(this.style.height) console.log(this.style.height)
this.style.height = 'auto'; this.style.height = 'auto';
this.style.height = (this.scrollHeight) + 'px'; this.style.height = (this.scrollHeight) + 'px';
} }
let textareas = document.getElementsByTagName('textarea'); let textareas = document.getElementsByTagName('textarea');
let addAutoGrow = () => { let addAutoGrow = () => {
Array.from(textareas).forEach(textarea => { Array.from(textareas).forEach(textarea => {
autogrow.bind(textarea)(); autogrow.bind(textarea)();
textarea.addEventListener('keyup', autogrow); textarea.addEventListener('keyup', autogrow);
}); });
} }
addAutoGrow(); addAutoGrow();
window.addEventListener('resize', addAutoGrow) window.addEventListener('resize', addAutoGrow)
} }
function deleteFrontMatterItem(event) { function deleteFrontMatterItem(event) {
event.preventDefault(); event.preventDefault();
document.getElementById(this.dataset.delete).remove(); document.getElementById(this.dataset.delete).remove();
} }
function makeFromBaseTemplate(id, type, name, parent) { function makeFromBaseTemplate(id, type, name, parent) {
let clone = document.importNode(templates.base.content, true); let clone = document.importNode(templates.base.content, true);
clone.querySelector('fieldset').id = id; clone.querySelector('fieldset').id = id;
clone.querySelector('fieldset').dataset.type = type; clone.querySelector('fieldset').dataset.type = type;
clone.querySelector('h3').innerHTML = name; clone.querySelector('h3').innerHTML = name;
clone.querySelector('.delete').dataset.delete = id; clone.querySelector('.delete').dataset.delete = id;
clone.querySelector('.delete').addEventListener('click', deleteFrontMatterItem); clone.querySelector('.delete').addEventListener('click', deleteFrontMatterItem);
clone.querySelector('.add').addEventListener('click', addFrontMatterItem); clone.querySelector('.add').addEventListener('click', addFrontMatterItem);
if (parent.classList.contains("frontmatter")) { if (parent.classList.contains("frontmatter")) {
parent.insertBefore(clone, document.querySelector('div.button.add')); parent.insertBefore(clone, document.querySelector('div.button.add'));
return return
} }
parent.appendChild(clone); parent.appendChild(clone);
} }
function makeFromArrayItemTemplate(id, number, parent) { function makeFromArrayItemTemplate(id, number, parent) {
let clone = document.importNode(templates.arrayItem.content, true); let clone = document.importNode(templates.arrayItem.content, true);
clone.querySelector('[data-type="array-item"]').id = `${id}-${number}`; clone.querySelector('[data-type="array-item"]').id = `${id}-${number}`;
clone.querySelector('input').name = id; clone.querySelector('input').name = id;
clone.querySelector('input').id = id; clone.querySelector('input').id = id;
clone.querySelector('div.action').dataset.delete = `${id}-${number}`; clone.querySelector('div.action').dataset.delete = `${id}-${number}`;
clone.querySelector('div.action').addEventListener('click', deleteFrontMatterItem); clone.querySelector('div.action').addEventListener('click', deleteFrontMatterItem);
parent.querySelector('.group').appendChild(clone) parent.querySelector('.group').appendChild(clone)
document.getElementById(`${id}-${number}`).querySelector('input').focus(); document.getElementById(`${id}-${number}`).querySelector('input').focus();
} }
function makeFromObjectItemTemplate(id, name, parent) { function makeFromObjectItemTemplate(id, name, parent) {
let clone = document.importNode(templates.objectItem.content, true); let clone = document.importNode(templates.objectItem.content, true);
clone.querySelector('.block').id = `block-${id}`; clone.querySelector('.block').id = `block-${id}`;
clone.querySelector('.block').dataset.content = id; clone.querySelector('.block').dataset.content = id;
clone.querySelector('label').for = id; clone.querySelector('label').for = id;
clone.querySelector('label').innerHTML = name; clone.querySelector('label').innerHTML = name;
clone.querySelector('input').name = id; clone.querySelector('input').name = id;
clone.querySelector('input').id = id; clone.querySelector('input').id = id;
clone.querySelector('.action').dataset.delete = `block-${id}`; clone.querySelector('.action').dataset.delete = `block-${id}`;
clone.querySelector('.action').addEventListener('click', deleteFrontMatterItem); clone.querySelector('.action').addEventListener('click', deleteFrontMatterItem);
parent.appendChild(clone) parent.appendChild(clone)
document.getElementById(id).focus(); document.getElementById(id).focus();
} }
function addFrontMatterItemPrompt(parent) { function addFrontMatterItemPrompt(parent) {
return function(event) { return function(event) {
event.preventDefault(); event.preventDefault();
let value = event.currentTarget.querySelector('input').value; let value = event.currentTarget.querySelector('input').value;
if (value === '') { if (value === '') {
return true; return true;
}
closePrompt(event);
let name = value.substring(0, value.lastIndexOf(':')),
type = value.substring(value.lastIndexOf(':') + 1, value.length);
if (type !== "" && type !== "array" && type !== "object") {
name = value;
}
name = name.replace(' ', '_');
let id = name;
if (parent.id != '') {
id = parent.id + "." + id;
}
if (type == "array" || type == "object") {
if (parent.dataset.type == "parent") {
makeFromBaseTemplate(id, type, name, document.querySelector('.frontmatter'));
return;
}
makeFromBaseTemplate(id, type, name, block);
return;
}
let group = parent.querySelector('.group');
if (group == null) {
parent.insertAdjacentHTML('afterbegin', '<div class="group"></div>');
group = parent.querySelector('.group');
}
makeFromObjectItemTemplate(id, name, group);
} }
closePrompt(event);
let name = value.substring(0, value.lastIndexOf(':')),
type = value.substring(value.lastIndexOf(':') + 1, value.length);
if (type !== "" && type !== "array" && type !== "object") {
name = value;
}
name = name.replace(' ', '_');
let id = name;
if (parent.id != '') {
id = parent.id + "." + id;
}
if (type == "array" || type == "object") {
if (parent.dataset.type == "parent") {
makeFromBaseTemplate(id, type, name, document.querySelector('.frontmatter'));
return;
}
makeFromBaseTemplate(id, type, name, block);
return;
}
let group = parent.querySelector('.group');
if (group == null) {
parent.insertAdjacentHTML('afterbegin', '<div class="group"></div>');
group = parent.querySelector('.group');
}
makeFromObjectItemTemplate(id, name, group);
}
} }
function addFrontMatterItem(event) { function addFrontMatterItem(event) {
event.preventDefault(); event.preventDefault();
let parent = event.currentTarget.parentNode, let parent = event.currentTarget.parentNode,
type = parent.dataset.type; type = parent.dataset.type;
// If the block is an array // If the block is an array
if (type === "array") { if (type === "array") {
let id = parent.id + "[]", let id = parent.id + "[]",
count = parent.querySelectorAll('.group > div').length, count = parent.querySelectorAll('.group > div').length,
fieldsets = parent.getElementsByTagName("fieldset"); fieldsets = parent.getElementsByTagName("fieldset");
if (fieldsets.length > 0) { if (fieldsets.length > 0) {
let itemType = fieldsets[0].dataset.type, let itemType = fieldsets[0].dataset.type,
itemID = parent.id + "[" + fieldsets.length + "]", itemID = parent.id + "[" + fieldsets.length + "]",
itemName = fieldsets.length; itemName = fieldsets.length;
makeFromBaseTemplate(itemID, itemType, itemName, parent); makeFromBaseTemplate(itemID, itemType, itemName, parent);
} else { } else {
makeFromArrayItemTemplate(id, count, parent); makeFromArrayItemTemplate(id, count, parent);
}
return;
} }
if (type == "object" || type == "parent") { return;
let clone = document.importNode(templates.question.content, true); }
clone.querySelector('form').id = tempID;
clone.querySelector('h3').innerHTML = 'New field';
clone.querySelector('p').innerHTML = 'Write the field name and then press enter. If you want to create an array or an object, end the name with <code>:array</code> or <code>:object.</code>';
clone.querySelector('.ok').innerHTML = 'Create';
clone.querySelector('form').addEventListener('submit', addFrontMatterItemPrompt(parent));
clone.querySelector('form').classList.add('active')
document.querySelector('body').appendChild(clone);
document.querySelector('.overlay').classList.add('active'); if (type == "object" || type == "parent") {
document.getElementById(tempID).classList.add('active'); let clone = document.importNode(templates.question.content, true);
} clone.querySelector('form').id = tempID;
clone.querySelector('h3').innerHTML = 'New field';
clone.querySelector('p').innerHTML = 'Write the field name and then press enter. If you want to create an array or an object, end the name with <code>:array</code> or <code>:object.</code>';
clone.querySelector('.ok').innerHTML = 'Create';
clone.querySelector('form').addEventListener('submit', addFrontMatterItemPrompt(parent));
clone.querySelector('form').classList.add('active')
document.querySelector('body').appendChild(clone);
return false; document.querySelector('.overlay').classList.add('active');
document.getElementById(tempID).classList.add('active');
}
return false;
} }
document.addEventListener("DOMContentLoaded", (event) => { document.addEventListener("DOMContentLoaded", (event) => {
if (!document.getElementById('editor')) return; if (!document.getElementById('editor')) return;
editor.textareaAutoGrow(); editor.textareaAutoGrow();
templates.arrayItem = document.getElementById("array-item-template"); templates.arrayItem = document.getElementById("array-item-template");
templates.base = document.getElementById('base-template'); templates.base = document.getElementById('base-template');
templates.objectItem = document.getElementById("object-item-template"); templates.objectItem = document.getElementById("object-item-template");
templates.temporary = document.getElementById('temporary-template'); templates.temporary = document.getElementById('temporary-template');
buttons.save = document.querySelector('#save'); buttons.save = document.querySelector('#save');
let container = document.getElementById('editor'), let container = document.getElementById('editor'),
kind = container.dataset.kind; kind = container.dataset.kind;
if (kind != 'frontmatter-only') { if (kind != 'frontmatter-only') {
let editor = document.querySelector('.content #ace'), let editor = document.querySelector('.content #ace'),
mode = editor.dataset.mode, mode = editor.dataset.mode,
textarea = document.querySelector('textarea[name="content"]'), textarea = document.querySelector('textarea[name="content"]'),
aceEditor = ace.edit('ace'), aceEditor = ace.edit('ace'),
options = { options = {
wrap: true, wrap: true,
maxLines: Infinity, maxLines: Infinity,
theme: "ace/theme/github", theme: "ace/theme/github",
showPrintMargin: false, showPrintMargin: false,
fontSize: "1em", fontSize: "1em",
minLines: 20 minLines: 20
}; };
aceEditor.getSession().setMode("ace/mode/" + mode); aceEditor.getSession().setMode("ace/mode/" + mode);
aceEditor.getSession().setValue(textarea.value); aceEditor.getSession().setValue(textarea.value);
aceEditor.getSession().on('change', function() { aceEditor.getSession().on('change', function() {
textarea.value = aceEditor.getSession().getValue(); textarea.value = aceEditor.getSession().getValue();
}); });
if (mode == "markdown") options.showGutter = false; if (mode == "markdown") options.showGutter = false;
aceEditor.setOptions(options); aceEditor.setOptions(options);
}
let deleteFrontMatterItemButtons = document.getElementsByClassName('delete');
Array.from(deleteFrontMatterItemButtons).forEach(button => {
button.addEventListener('click', deleteFrontMatterItem);
});
let addFrontMatterItemButtons = document.getElementsByClassName('add');
Array.from(addFrontMatterItemButtons).forEach(button => {
button.addEventListener('click', addFrontMatterItem);
});
let saveContent = function() {
let data = form2js(document.querySelector('form'));
if (typeof data.content === "undefined" && kind != 'frontmatter-only') {
data.content = "";
} }
let deleteFrontMatterItemButtons = document.getElementsByClassName('delete'); if (typeof data.content === "number") {
Array.from(deleteFrontMatterItemButtons).forEach(button => { data.content = data.content.toString();
button.addEventListener('click', deleteFrontMatterItem);
});
let addFrontMatterItemButtons = document.getElementsByClassName('add');
Array.from(addFrontMatterItemButtons).forEach(button => {
button.addEventListener('click', addFrontMatterItem);
});
let saveContent = function() {
let data = form2js(document.querySelector('form'));
if (typeof data.content === "undefined" && kind != 'frontmatter-only') {
data.content = "";
}
if (typeof data.content === "number") {
data.content = data.content.toString();
}
let html = buttons.save.querySelector('i').changeToLoading(),
request = new XMLHttpRequest();
request.open("PUT", toWebDavURL(window.location.pathname));
request.setRequestHeader('Kind', kind);
request.send(JSON.stringify(data));
request.onreadystatechange = function() {
if (request.readyState == 4) {
buttons.save.querySelector('i').changeToDone((request.status != 201), html);
}
}
} }
document.querySelector('#save').addEventListener('click', event => { let html = buttons.save.querySelector('i').changeToLoading(),
request = new XMLHttpRequest();
request.open("PUT", toWebDavURL(window.location.pathname));
request.setRequestHeader('Kind', kind);
request.send(JSON.stringify(data));
request.onreadystatechange = function() {
if (request.readyState == 4) {
buttons.save.querySelector('i').changeToDone((request.status != 201), html);
}
}
}
document.querySelector('#save').addEventListener('click', event => {
event.preventDefault();
saveContent();
});
document.querySelector('form').addEventListener('submit', (event) => {
event.preventDefault();
saveContent();
});
window.addEventListener('keydown', (event) => {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault(); event.preventDefault();
saveContent(); saveContent();
}); break;
}
}
});
document.querySelector('form').addEventListener('submit', (event) => { return false;
event.preventDefault(); });
saveContent();
});
window.addEventListener('keydown', (event) => {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault();
saveContent();
break;
}
}
});
return false;
});

View File

@ -54,8 +54,8 @@ listing.itemDrop = function(e) {
e.preventDefault(); e.preventDefault();
let el = e.target, let el = e.target,
id = e.dataTransfer.getData("id"), id = e.dataTransfer.getData("id"),
name = e.dataTransfer.getData("name"); name = e.dataTransfer.getData("name");
if (id == "" || name == "") return; if (id == "" || name == "") return;
@ -68,19 +68,19 @@ listing.itemDrop = function(e) {
if (el.id === id) return; if (el.id === id) return;
let oldLink = document.getElementById(id).dataset.url, let oldLink = document.getElementById(id).dataset.url,
newLink = el.dataset.url + name; newLink = el.dataset.url + name;
webdav.move(oldLink, newLink) webdav.move(oldLink, newLink)
.then(() => listing.reload()) .then(() => listing.reload())
.catch(e => console.log(e)); .catch(e => console.log(e));
} }
listing.documentDrop = function(event) { listing.documentDrop = function(event) {
event.preventDefault(); event.preventDefault();
let dt = event.dataTransfer, let dt = event.dataTransfer,
files = dt.files, files = dt.files,
el = event.target, el = event.target,
items = document.getElementsByClassName('item'); items = document.getElementsByClassName('item');
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
if (el != null && !el.classList.contains('item')) { if (el != null && !el.classList.contains('item')) {
@ -114,15 +114,15 @@ listing.rename = function(event) {
} }
let link = item.dataset.url, let link = item.dataset.url,
field = item.querySelector('.name'), field = item.querySelector('.name'),
name = field.innerHTML; name = field.innerHTML;
let submit = (event) => { let submit = (event) => {
event.preventDefault(); event.preventDefault();
let newName = event.currentTarget.querySelector('input').value, let newName = event.currentTarget.querySelector('input').value,
newLink = removeLastDirectoryPartOf(link) + "/" + newName, newLink = removeLastDirectoryPartOf(link) + "/" + newName,
html = buttons.rename.querySelector('i').changeToLoading(); html = buttons.rename.querySelector('i').changeToLoading();
closePrompt(event); closePrompt(event);
webdav.move(link, newLink).then(() => { webdav.move(link, newLink).then(() => {
@ -159,21 +159,21 @@ listing.rename = function(event) {
listing.handleFiles = function(files, base) { listing.handleFiles = function(files, base) {
let html = buttons.upload.querySelector('i').changeToLoading(), let html = buttons.upload.querySelector('i').changeToLoading(),
promises = []; promises = [];
for (let file of files) { for (let file of files) {
promises.push(webdav.put(window.location.pathname + base + file.name, file)); promises.push(webdav.put(window.location.pathname + base + file.name, file));
} }
Promise.all(promises) Promise.all(promises)
.then(() => { .then(() => {
listing.reload(); listing.reload();
buttons.upload.querySelector('i').changeToDone(false, html); buttons.upload.querySelector('i').changeToDone(false, html);
}) })
.catch(e => { .catch(e => {
console.log(e); console.log(e);
buttons.upload.querySelector('i').changeToDone(true, html); buttons.upload.querySelector('i').changeToDone(true, html);
}) })
return false; return false;
} }
@ -194,7 +194,7 @@ listing.handleSelectionChange = function(event) {
listing.redefineDownloadURLs(); listing.redefineDownloadURLs();
let selectedNumber = selectedItems.length, let selectedNumber = selectedItems.length,
fileAction = document.getElementById("file-only"); fileAction = document.getElementById("file-only");
if (selectedNumber) { if (selectedNumber) {
fileAction.classList.remove("disabled"); fileAction.classList.remove("disabled");
@ -278,9 +278,9 @@ listing.newFilePrompt = function(event) {
event.preventDefault(); event.preventDefault();
let button = document.getElementById('new'), let button = document.getElementById('new'),
html = button.querySelector('i').changeToLoading(), html = button.querySelector('i').changeToLoading(),
request = new XMLHttpRequest(), request = new XMLHttpRequest(),
name = event.currentTarget.querySelector('input').value; name = event.currentTarget.querySelector('input').value;
request.open((name.endsWith("/") ? "MKCOL" : "PUT"), toWebDavURL(window.location.pathname + name)); request.open((name.endsWith("/") ? "MKCOL" : "PUT"), toWebDavURL(window.location.pathname + name));
request.send(); request.send();
@ -297,17 +297,17 @@ listing.newFilePrompt = function(event) {
listing.updateColumns = function(event) { listing.updateColumns = function(event) {
let columns = Math.floor(document.getElementById('listing').offsetWidth / 300), let columns = Math.floor(document.getElementById('listing').offsetWidth / 300),
items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']); items = getCSSRule(['#listing.mosaic .item', '.mosaic#listing .item']);
items.style.width = `calc(${100/columns}% - 1em)`; items.style.width = `calc(${100/columns}% - 1em)`;
} }
listing.addDoubleTapEvent = function() { listing.addDoubleTapEvent = function() {
let items = document.getElementsByClassName('item'), let items = document.getElementsByClassName('item'),
touches = { touches = {
id: '', id: '',
count: 0 count: 0
}; };
Array.from(items).forEach(file => { Array.from(items).forEach(file => {
file.addEventListener('touchstart', event => { file.addEventListener('touchstart', event => {
@ -349,8 +349,8 @@ window.addEventListener('keydown', (event) => {
console.log("hey") console.log("hey")
switch (String.fromCharCode(event.which).toLowerCase()) { switch (String.fromCharCode(event.which).toLowerCase()) {
case 's': case 's':
event.preventDefault(); event.preventDefault();
window.location = "?download=true" window.location = "?download=true"
} }
} }
}); });