pre-build.sh
Former-commit-id: 58220a0ee1c48708eed3d172d6884a9f3617ffe9 [formerly 0d570e5a54030b9c4f7e280b55816a221438df72] [formerly 3c420b9ecd469d03c3ddfafeb33d4451a2315d55 [formerly 191a3791e0
]]
Former-commit-id: 0f82a221f0201448eecd54e98ac95fcdfea7ede0 [formerly 67ce3f7f0945b90ced9d7b11017286753afd8075]
Former-commit-id: a91572e8026c2290095d02bf3ef125591145dbc7
pull/726/head
parent
e0aef17c94
commit
0a60d711ff
|
@ -1,72 +1,72 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
var tempID = "_fm_internal_temporary_id",
|
var tempID = '_fm_internal_temporary_id',
|
||||||
ssl = (location.protocol === 'https:'),
|
ssl = (window.location.protocol === 'https:'),
|
||||||
templates = {},
|
templates = {},
|
||||||
selectedItems = [],
|
selectedItems = [],
|
||||||
overlay,
|
overlay,
|
||||||
clickOverlay;
|
clickOverlay
|
||||||
|
|
||||||
// Removes an element, if exists, from an array
|
// Removes an element, if exists, from an array
|
||||||
Array.prototype.removeElement = function (element) {
|
Array.prototype.removeElement = function (element) {
|
||||||
var i = this.indexOf(element);
|
var i = this.indexOf(element)
|
||||||
if(i != -1)
|
if (i !== -1)
|
||||||
this.splice(i, 1);
|
this.splice(i, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replaces an element inside an array by another
|
// Replaces an element inside an array by another
|
||||||
Array.prototype.replaceElement = function (oldElement, newElement) {
|
Array.prototype.replaceElement = function (oldElement, newElement) {
|
||||||
var i = this.indexOf(oldElement);
|
var i = this.indexOf(oldElement)
|
||||||
if(i != -1)
|
if (i != -1)
|
||||||
this[i] = newElement;
|
this[i] = newElement
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends a costum event to itself
|
// Sends a costum event to itself
|
||||||
Document.prototype.sendCostumEvent = function (text) {
|
Document.prototype.sendCostumEvent = function (text) {
|
||||||
this.dispatchEvent(new CustomEvent(text));
|
this.dispatchEvent(new CustomEvent(text))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the content of a cookie
|
// Gets the content of a cookie
|
||||||
Document.prototype.getCookie = function (name) {
|
Document.prototype.getCookie = function (name) {
|
||||||
var re = new RegExp("(?:(?:^|.*;\\s*)" + name + "\\s*\\=\\s*([^;]*).*$)|^.*$");
|
var re = new RegExp('(?:(?:^|.*;\\s*)' + name + '\\s*\\=\\s*([^;]*).*$)|^.*$')
|
||||||
return document.cookie.replace(re, "$1");
|
return document.cookie.replace(re, '$1')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the last directory of an url
|
// Remove the last directory of an url
|
||||||
var removeLastDirectoryPartOf = function (url) {
|
var removeLastDirectoryPartOf = function (url) {
|
||||||
var arr = url.split('/');
|
var arr = url.split('/')
|
||||||
if(arr.pop() === "") {
|
if (arr.pop() === '') {
|
||||||
arr.pop();
|
arr.pop()
|
||||||
}
|
}
|
||||||
return(arr.join('/'));
|
return (arr.join('/'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCSSRule(rules) {
|
function getCSSRule (rules) {
|
||||||
for(let i = 0; i < rules.length; i++) {
|
for (let i = 0; i < rules.length; i++) {
|
||||||
rules[i] = rules[i].toLowerCase();
|
rules[i] = rules[i].toLowerCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = null,
|
var result = null,
|
||||||
find = Array.prototype.find;
|
find = Array.prototype.find
|
||||||
|
|
||||||
find.call(document.styleSheets, styleSheet => {
|
find.call(document.styleSheets, styleSheet => {
|
||||||
result = find.call(styleSheet.cssRules, cssRule => {
|
result = find.call(styleSheet.cssRules, cssRule => {
|
||||||
let found = false;
|
let found = false
|
||||||
|
|
||||||
if(cssRule instanceof CSSStyleRule) {
|
if (cssRule instanceof CSSStyleRule) {
|
||||||
for(let i = 0; i < rules.length; i++) {
|
for (let i = 0; i < rules.length; i++) {
|
||||||
if(cssRule.selectorText.toLowerCase() == rules[i])
|
if (cssRule.selectorText.toLowerCase() == rules[i])
|
||||||
found = true;
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return found
|
||||||
});
|
})
|
||||||
|
|
||||||
return result != null;
|
return result != null
|
||||||
});
|
})
|
||||||
|
|
||||||
return result;
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * *
|
||||||
|
@ -75,53 +75,53 @@ function getCSSRule(rules) {
|
||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * */
|
||||||
var buttons = {
|
var buttons = {
|
||||||
previousState: {},
|
previousState: {}
|
||||||
};
|
}
|
||||||
|
|
||||||
buttons.setLoading = function (name) {
|
buttons.setLoading = function (name) {
|
||||||
if(typeof this[name] === 'undefined') return;
|
if (typeof this[name] === 'undefined') return
|
||||||
let i = this[name].querySelector('i');
|
let i = this[name].querySelector('i')
|
||||||
|
|
||||||
this.previousState[name] = i.innerHTML;
|
this.previousState[name] = i.innerHTML
|
||||||
i.style.opacity = 0;
|
i.style.opacity = 0
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
i.classList.add('spin');
|
i.classList.add('spin')
|
||||||
i.innerHTML = 'autorenew';
|
i.innerHTML = 'autorenew'
|
||||||
i.style.opacity = 1;
|
i.style.opacity = 1
|
||||||
}, 200);
|
}, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Changes an element to done animation
|
// Changes an element to done animation
|
||||||
buttons.setDone = function (name, success = true) {
|
buttons.setDone = function (name, success = true) {
|
||||||
let i = this[name].querySelector('i');
|
let i = this[name].querySelector('i')
|
||||||
|
|
||||||
i.style.opacity = 0;
|
i.style.opacity = 0
|
||||||
|
|
||||||
let thirdStep = () => {
|
let thirdStep = () => {
|
||||||
i.innerHTML = this.previousState[name];
|
i.innerHTML = this.previousState[name]
|
||||||
i.style.opacity = null;
|
i.style.opacity = null
|
||||||
|
|
||||||
if(selectedItems.length == 0 && document.getElementById('listing'))
|
if (selectedItems.length == 0 && document.getElementById('listing'))
|
||||||
document.sendCostumEvent('changed-selected');
|
document.sendCostumEvent('changed-selected')
|
||||||
}
|
}
|
||||||
|
|
||||||
let secondStep = () => {
|
let secondStep = () => {
|
||||||
i.style.opacity = 0;
|
i.style.opacity = 0
|
||||||
setTimeout(thirdStep, 200);
|
setTimeout(thirdStep, 200)
|
||||||
}
|
}
|
||||||
|
|
||||||
let firstStep = () => {
|
let firstStep = () => {
|
||||||
i.classList.remove('spin');
|
i.classList.remove('spin')
|
||||||
i.innerHTML = success ?
|
i.innerHTML = success ?
|
||||||
'done' :
|
'done' :
|
||||||
'close';
|
'close'
|
||||||
i.style.opacity = 1;
|
i.style.opacity = 1
|
||||||
setTimeout(secondStep, 1000);
|
setTimeout(secondStep, 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(firstStep, 200);
|
setTimeout(firstStep, 200)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * *
|
||||||
|
@ -129,84 +129,84 @@ buttons.setDone = function (name, success = true) {
|
||||||
* WEBDAV *
|
* WEBDAV *
|
||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * */
|
||||||
var webdav = {};
|
var webdav = {}
|
||||||
|
|
||||||
webdav.convertURL = function (url) {
|
webdav.convertURL = function (url) {
|
||||||
return window.location.origin + url.replace(baseURL + "/", webdavURL + "/");
|
return window.location.origin + url.replace(baseURL + '/', webdavURL + '/')
|
||||||
}
|
}
|
||||||
|
|
||||||
webdav.move = function (oldLink, newLink) {
|
webdav.move = function (oldLink, newLink) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest(),
|
let request = new XMLHttpRequest(),
|
||||||
destination = newLink.replace(baseURL + "/", webdavURL + "/");
|
destination = newLink.replace(baseURL + '/', webdavURL + '/')
|
||||||
|
|
||||||
destination = window.location.origin + destination.substring(prefixURL.length);
|
destination = window.location.origin + destination.substring(prefixURL.length)
|
||||||
|
|
||||||
request.open('MOVE', webdav.convertURL(oldLink), true);
|
request.open('MOVE', webdav.convertURL(oldLink), true)
|
||||||
request.setRequestHeader('Destination', destination);
|
request.setRequestHeader('Destination', destination)
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if(request.status == 201 || request.status == 204) {
|
if (request.status == 201 || request.status == 204) {
|
||||||
resolve();
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
reject(request.statusText);
|
reject(request.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.onerror = () => reject(request.statusText);
|
request.onerror = () => reject(request.statusText)
|
||||||
request.send();
|
request.send()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
webdav.put = function (link, body, headers = {}) {
|
webdav.put = function (link, body, headers = {}) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
request.open('PUT', webdav.convertURL(link), true);
|
request.open('PUT', webdav.convertURL(link), true)
|
||||||
|
|
||||||
for(let key in headers) {
|
for (let key in headers) {
|
||||||
request.setRequestHeader(key, headers[key]);
|
request.setRequestHeader(key, headers[key])
|
||||||
}
|
}
|
||||||
|
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if(request.status == 201) {
|
if (request.status == 201) {
|
||||||
resolve();
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
reject(request.statusText);
|
reject(request.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.onerror = () => reject(request.statusText);
|
request.onerror = () => reject(request.statusText)
|
||||||
request.send(body);
|
request.send(body)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
webdav.delete = function (link) {
|
webdav.delete = function (link) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
request.open('DELETE', webdav.convertURL(link), true);
|
request.open('DELETE', webdav.convertURL(link), true)
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if(request.status == 204) {
|
if (request.status == 204) {
|
||||||
resolve();
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
reject(request.statusText);
|
reject(request.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.onerror = () => reject(request.statusText);
|
request.onerror = () => reject(request.statusText)
|
||||||
request.send();
|
request.send()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
webdav.new = function (link) {
|
webdav.new = function (link) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
request.open((link.endsWith("/") ? "MKCOL" : "PUT"), webdav.convertURL(link), true);
|
request.open((link.endsWith('/') ? 'MKCOL' : 'PUT'), webdav.convertURL(link), true)
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if(request.status == 201) {
|
if (request.status == 201) {
|
||||||
resolve();
|
resolve()
|
||||||
} else {
|
} else {
|
||||||
reject(request.statusText);
|
reject(request.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.onerror = () => reject(request.statusText);
|
request.onerror = () => reject(request.statusText)
|
||||||
request.send();
|
request.send()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * *
|
||||||
|
@ -214,150 +214,150 @@ webdav.new = function (link) {
|
||||||
* EVENTS *
|
* EVENTS *
|
||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * */
|
||||||
function closePrompt(event) {
|
function closePrompt (event) {
|
||||||
let prompt = document.querySelector('.prompt');
|
let prompt = document.querySelector('.prompt')
|
||||||
|
|
||||||
if(!prompt)
|
if (!prompt)
|
||||||
return;
|
return
|
||||||
|
|
||||||
if(typeof event != 'undefined') {
|
if (typeof event != 'undefined') {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector('.overlay').classList.remove('active');
|
document.querySelector('.overlay').classList.remove('active')
|
||||||
prompt.classList.remove('active');
|
prompt.classList.remove('active')
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
prompt.remove();
|
prompt.remove()
|
||||||
}, 100);
|
}, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
function notImplemented(event) {
|
function notImplemented (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
clickOverlay.click();
|
clickOverlay.click()
|
||||||
|
|
||||||
let clone = document.importNode(templates.info.content, true);
|
let clone = document.importNode(templates.info.content, true)
|
||||||
clone.querySelector('h3').innerHTML = 'Not implemented';
|
clone.querySelector('h3').innerHTML = 'Not implemented'
|
||||||
clone.querySelector('p').innerHTML = "Sorry, but this feature wasn't implemented yet.";
|
clone.querySelector('p').innerHTML = "Sorry, but this feature wasn't implemented yet."
|
||||||
|
|
||||||
document.querySelector('body').appendChild(clone)
|
document.querySelector('body').appendChild(clone)
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector('.prompt').classList.add('active');
|
document.querySelector('.prompt').classList.add('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prevent Default event
|
// Prevent Default event
|
||||||
var preventDefault = function (event) {
|
var preventDefault = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
function logoutEvent(event) {
|
function logoutEvent (event) {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
request.open('GET', window.location.pathname, true, "username", "password");
|
request.open('GET', window.location.pathname, true, 'username', 'password')
|
||||||
request.send();
|
request.send()
|
||||||
request.onreadystatechange = function () {
|
request.onreadystatechange = function () {
|
||||||
if(request.readyState == 4) {
|
if (request.readyState == 4) {
|
||||||
window.location = "/";
|
window.location = '/'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEvent(event) {
|
function openEvent (event) {
|
||||||
if(event.currentTarget.classList.contains('disabled'))
|
if (event.currentTarget.classList.contains('disabled'))
|
||||||
return false;
|
return false
|
||||||
|
|
||||||
let link = '?raw=true';
|
let link = '?raw=true'
|
||||||
|
|
||||||
if(selectedItems.length) {
|
if (selectedItems.length) {
|
||||||
link = document.getElementById(selectedItems[0]).dataset.url + link;
|
link = document.getElementById(selectedItems[0]).dataset.url + link
|
||||||
} else {
|
} else {
|
||||||
link = window.location.pathname + link;
|
link = window.location.pathname + link
|
||||||
}
|
}
|
||||||
|
|
||||||
window.open(link);
|
window.open(link)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteOnSingleFile() {
|
function deleteOnSingleFile () {
|
||||||
closePrompt();
|
closePrompt()
|
||||||
buttons.setLoading('delete');
|
buttons.setLoading('delete')
|
||||||
|
|
||||||
let promises = [];
|
let promises = []
|
||||||
|
|
||||||
webdav.delete(window.location.pathname)
|
webdav.delete(window.location.pathname)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
window.location.pathname = removeLastDirectoryPartOf(window.location.pathname);
|
window.location.pathname = removeLastDirectoryPartOf(window.location.pathname)
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
buttons.setDone('delete', false);
|
buttons.setDone('delete', false)
|
||||||
console.log(e)
|
console.log(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteOnListing() {
|
function deleteOnListing () {
|
||||||
closePrompt();
|
closePrompt()
|
||||||
buttons.setLoading('delete');
|
buttons.setLoading('delete')
|
||||||
|
|
||||||
let promises = [];
|
let promises = []
|
||||||
|
|
||||||
for(let id of selectedItems) {
|
for (let id of selectedItems) {
|
||||||
promises.push(webdav.delete(document.getElementById(id).dataset.url));
|
promises.push(webdav.delete(document.getElementById(id).dataset.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
listing.reload();
|
listing.reload()
|
||||||
buttons.setDone('delete');
|
buttons.setDone('delete')
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e)
|
||||||
buttons.setDone('delete', false);
|
buttons.setDone('delete', false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the delete button event
|
// Handles the delete button event
|
||||||
function deleteEvent(event) {
|
function deleteEvent (event) {
|
||||||
let single = false;
|
let single = false
|
||||||
|
|
||||||
if(!selectedItems.length) {
|
if (!selectedItems.length) {
|
||||||
selectedItems = ["placeholder"];
|
selectedItems = ['placeholder']
|
||||||
single = true;
|
single = true
|
||||||
}
|
}
|
||||||
|
|
||||||
let clone = document.importNode(templates.question.content, true);
|
let clone = document.importNode(templates.question.content, true)
|
||||||
clone.querySelector('h3').innerHTML = 'Delete files';
|
clone.querySelector('h3').innerHTML = 'Delete files'
|
||||||
|
|
||||||
if(single) {
|
if (single) {
|
||||||
clone.querySelector('form').addEventListener('submit', deleteOnSingleFile);
|
clone.querySelector('form').addEventListener('submit', deleteOnSingleFile)
|
||||||
clone.querySelector('p').innerHTML = `Are you sure you want to delete this file/folder?`;
|
clone.querySelector('p').innerHTML = `Are you sure you want to delete this file/folder?`
|
||||||
} else {
|
} else {
|
||||||
clone.querySelector('form').addEventListener('submit', deleteOnListing);
|
clone.querySelector('form').addEventListener('submit', deleteOnListing)
|
||||||
clone.querySelector('p').innerHTML = `Are you sure you want to delete ${selectedItems.length} file(s)?`;
|
clone.querySelector('p').innerHTML = `Are you sure you want to delete ${selectedItems.length} file(s)?`
|
||||||
}
|
}
|
||||||
|
|
||||||
clone.querySelector('input').remove();
|
clone.querySelector('input').remove()
|
||||||
clone.querySelector('.ok').innerHTML = 'Delete';
|
clone.querySelector('.ok').innerHTML = 'Delete'
|
||||||
|
|
||||||
document.body.appendChild(clone);
|
document.body.appendChild(clone)
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector('.prompt').classList.add('active');
|
document.querySelector('.prompt').classList.add('active')
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetSearchText() {
|
function resetSearchText () {
|
||||||
let box = document.querySelector('#search > div div');
|
let box = document.querySelector('#search > div div')
|
||||||
|
|
||||||
if(user.AllowCommands) {
|
if (user.AllowCommands) {
|
||||||
box.innerHTML = `Search or use one of your supported commands: ${user.Commands.join(", ")}.`;
|
box.innerHTML = `Search or use one of your supported commands: ${user.Commands.join(", ")}.`
|
||||||
} else {
|
} else {
|
||||||
box.innerHTML = "Type and press enter to search.";
|
box.innerHTML = 'Type and press enter to search.'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchEvent(event) {
|
function searchEvent (event) {
|
||||||
if(this.value.length == 0) {
|
if (this.value.length == 0) {
|
||||||
resetSearchText();
|
resetSearchText()
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = this.value,
|
let value = this.value,
|
||||||
|
@ -365,143 +365,143 @@ function searchEvent(event) {
|
||||||
scrollable = document.querySelector('#search > div'),
|
scrollable = document.querySelector('#search > div'),
|
||||||
box = document.querySelector('#search > div div'),
|
box = document.querySelector('#search > div div'),
|
||||||
pieces = value.split(' '),
|
pieces = value.split(' '),
|
||||||
supported = false;
|
supported = false
|
||||||
|
|
||||||
user.Commands.forEach(function (cmd) {
|
user.Commands.forEach(function (cmd) {
|
||||||
if(cmd == pieces[0]) {
|
if (cmd == pieces[0]) {
|
||||||
supported = true;
|
supported = true
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
if(!supported || !user.AllowCommands) {
|
if (!supported || !user.AllowCommands) {
|
||||||
box.innerHTML = "Press enter to search."
|
box.innerHTML = 'Press enter to search.'
|
||||||
} else {
|
} else {
|
||||||
box.innerHTML = "Press enter to execute."
|
box.innerHTML = 'Press enter to execute.'
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.keyCode == 13) {
|
if (event.keyCode == 13) {
|
||||||
box.innerHTML = '';
|
box.innerHTML = ''
|
||||||
search.classList.add('ongoing');
|
search.classList.add('ongoing')
|
||||||
|
|
||||||
let url = window.location.host + window.location.pathname;
|
let url = window.location.host + window.location.pathname
|
||||||
|
|
||||||
if(document.getElementById("editor")) {
|
if (document.getElementById('editor')) {
|
||||||
url = removeLastDirectoryPartOf(url);
|
url = removeLastDirectoryPartOf(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
let protocol = ssl ? 'wss:' : 'ws:';
|
let protocol = ssl ? 'wss:' : 'ws:'
|
||||||
|
|
||||||
if(supported && user.AllowCommands) {
|
if (supported && user.AllowCommands) {
|
||||||
let conn = new WebSocket(`${protocol}//${url}?command=true`);
|
let conn = new WebSocket(`${protocol}//${url}?command=true`)
|
||||||
|
|
||||||
conn.onopen = function () {
|
conn.onopen = function () {
|
||||||
conn.send(value);
|
conn.send(value)
|
||||||
};
|
}
|
||||||
|
|
||||||
conn.onmessage = function (event) {
|
conn.onmessage = function (event) {
|
||||||
box.innerHTML = event.data;
|
box.innerHTML = event.data
|
||||||
scrollable.scrollTop = scrollable.scrollHeight;
|
scrollable.scrollTop = scrollable.scrollHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.onclose = function (event) {
|
conn.onclose = function (event) {
|
||||||
search.classList.remove('ongoing');
|
search.classList.remove('ongoing')
|
||||||
listing.reload();
|
listing.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
box.innerHTML = '<ul></ul>';
|
box.innerHTML = '<ul></ul>'
|
||||||
|
|
||||||
let ul = box.querySelector('ul'),
|
let ul = box.querySelector('ul'),
|
||||||
conn = new WebSocket(`${protocol}//${url}?search=true`);
|
conn = new WebSocket(`${protocol}//${url}?search=true`)
|
||||||
|
|
||||||
conn.onopen = function () {
|
conn.onopen = function () {
|
||||||
conn.send(value);
|
conn.send(value)
|
||||||
};
|
}
|
||||||
|
|
||||||
conn.onmessage = function (event) {
|
conn.onmessage = function (event) {
|
||||||
ul.innerHTML += '<li><a href="' + event.data + '">' + event.data + '</a></li>';
|
ul.innerHTML += '<li><a href="' + event.data + '">' + event.data + '</a></li>'
|
||||||
scrollable.scrollTop = scrollable.scrollHeight;
|
scrollable.scrollTop = scrollable.scrollHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
conn.onclose = function (event) {
|
conn.onclose = function (event) {
|
||||||
search.classList.remove('ongoing');
|
search.classList.remove('ongoing')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupSearch() {
|
function setupSearch () {
|
||||||
let search = document.getElementById("search"),
|
let search = document.getElementById('search'),
|
||||||
searchInput = search.querySelector("input"),
|
searchInput = search.querySelector('input'),
|
||||||
searchDiv = search.querySelector("div"),
|
searchDiv = search.querySelector('div'),
|
||||||
hover = false,
|
hover = false,
|
||||||
focus = false;
|
focus = false
|
||||||
|
|
||||||
resetSearchText();
|
resetSearchText()
|
||||||
|
|
||||||
searchInput.addEventListener('focus', event => {
|
searchInput.addEventListener('focus', event => {
|
||||||
focus = true;
|
focus = true
|
||||||
search.classList.add('active');
|
search.classList.add('active')
|
||||||
});
|
})
|
||||||
|
|
||||||
searchDiv.addEventListener('mouseover', event => {
|
searchDiv.addEventListener('mouseover', event => {
|
||||||
hover = true;
|
hover = true
|
||||||
search.classList.add('active');
|
search.classList.add('active')
|
||||||
});
|
})
|
||||||
|
|
||||||
searchInput.addEventListener('blur', event => {
|
searchInput.addEventListener('blur', event => {
|
||||||
focus = false;
|
focus = false
|
||||||
if(hover)
|
if (hover)
|
||||||
return;
|
return
|
||||||
search.classList.remove('active');
|
search.classList.remove('active')
|
||||||
});
|
})
|
||||||
|
|
||||||
search.addEventListener('mouseleave', event => {
|
search.addEventListener('mouseleave', event => {
|
||||||
hover = false;
|
hover = false
|
||||||
if(focus)
|
if (focus)
|
||||||
return;
|
return
|
||||||
search.classList.remove('active');
|
search.classList.remove('active')
|
||||||
});
|
})
|
||||||
|
|
||||||
search.addEventListener("click", event => {
|
search.addEventListener('click', event => {
|
||||||
search.classList.add("active");
|
search.classList.add('active')
|
||||||
search.querySelector("input").focus();
|
search.querySelector('input').focus()
|
||||||
});
|
})
|
||||||
|
|
||||||
searchInput.addEventListener('keyup', searchEvent);
|
searchInput.addEventListener('keyup', searchEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeHelp(event) {
|
function closeHelp (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
|
|
||||||
document.querySelector('.help').classList.remove('active');
|
document.querySelector('.help').classList.remove('active')
|
||||||
document.querySelector('.overlay').classList.remove('active');
|
document.querySelector('.overlay').classList.remove('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
function openHelp(event) {
|
function openHelp (event) {
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
|
|
||||||
document.querySelector('.help').classList.add('active');
|
document.querySelector('.help').classList.add('active')
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('keydown', (event) => {
|
window.addEventListener('keydown', (event) => {
|
||||||
if(event.keyCode == 27) {
|
if (event.keyCode == 27) {
|
||||||
if(document.querySelector('.help.active')) {
|
if (document.querySelector('.help.active')) {
|
||||||
closeHelp(event);
|
closeHelp(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.keyCode == 46) {
|
if (event.keyCode == 46) {
|
||||||
deleteEvent(event);
|
deleteEvent(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.keyCode == 112) {
|
if (event.keyCode == 112) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
openHelp(event);
|
openHelp(event)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
/* * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * *
|
||||||
* *
|
* *
|
||||||
|
@ -509,64 +509,64 @@ window.addEventListener('keydown', (event) => {
|
||||||
* *
|
* *
|
||||||
* * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", function (event) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
overlay = document.querySelector('.overlay');
|
overlay = document.querySelector('.overlay')
|
||||||
clickOverlay = document.querySelector('#click-overlay');
|
clickOverlay = document.querySelector('#click-overlay')
|
||||||
|
|
||||||
buttons.logout = document.getElementById("logout");
|
buttons.logout = document.getElementById('logout')
|
||||||
buttons.open = document.getElementById("open");
|
buttons.open = document.getElementById('open')
|
||||||
buttons.delete = document.getElementById("delete");
|
buttons.delete = document.getElementById('delete')
|
||||||
buttons.previous = document.getElementById("previous");
|
buttons.previous = document.getElementById('previous')
|
||||||
|
|
||||||
// Attach event listeners
|
// Attach event listeners
|
||||||
buttons.logout.addEventListener("click", logoutEvent);
|
buttons.logout.addEventListener('click', logoutEvent)
|
||||||
buttons.open.addEventListener("click", openEvent);
|
buttons.open.addEventListener('click', openEvent)
|
||||||
|
|
||||||
templates.question = document.querySelector('#question-template');
|
templates.question = document.querySelector('#question-template')
|
||||||
templates.info = document.querySelector('#info-template');
|
templates.info = document.querySelector('#info-template')
|
||||||
templates.move = document.querySelector("#move-template");
|
templates.move = document.querySelector('#move-template')
|
||||||
|
|
||||||
if(user.AllowEdit) {
|
if (user.AllowEdit) {
|
||||||
buttons.delete.addEventListener("click", deleteEvent);
|
buttons.delete.addEventListener('click', deleteEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
let dropdownButtons = document.querySelectorAll('.action[data-dropdown]')
|
let dropdownButtons = document.querySelectorAll('.action[data-dropdown]')
|
||||||
Array.from(dropdownButtons).forEach(button => {
|
Array.from(dropdownButtons).forEach(button => {
|
||||||
button.addEventListener("click", event => {
|
button.addEventListener('click', event => {
|
||||||
button.querySelector('ul').classList.toggle("active");
|
button.querySelector('ul').classList.toggle('active')
|
||||||
clickOverlay.classList.add('active');
|
clickOverlay.classList.add('active')
|
||||||
|
|
||||||
clickOverlay.addEventListener('click', event => {
|
clickOverlay.addEventListener('click', event => {
|
||||||
button.querySelector('ul').classList.remove("active");
|
button.querySelector('ul').classList.remove('active')
|
||||||
clickOverlay.classList.remove('active');
|
clickOverlay.classList.remove('active')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
overlay.addEventListener('click', event => {
|
overlay.addEventListener('click', event => {
|
||||||
if(document.querySelector('.help.active')) {
|
if (document.querySelector('.help.active')) {
|
||||||
closeHelp(event);
|
closeHelp(event)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
})
|
})
|
||||||
|
|
||||||
let mainActions = document.getElementById('main-actions');
|
let mainActions = document.getElementById('main-actions')
|
||||||
|
|
||||||
document.getElementById('more').addEventListener('click', event => {
|
document.getElementById('more').addEventListener('click', event => {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
event.stopPropagation();
|
event.stopPropagation()
|
||||||
|
|
||||||
clickOverlay.classList.add('active');
|
clickOverlay.classList.add('active')
|
||||||
mainActions.classList.add('active');
|
mainActions.classList.add('active')
|
||||||
|
|
||||||
clickOverlay.addEventListener('click', event => {
|
clickOverlay.addEventListener('click', event => {
|
||||||
mainActions.classList.remove('active');
|
mainActions.classList.remove('active')
|
||||||
clickOverlay.classList.remove('active');
|
clickOverlay.classList.remove('active')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
setupSearch();
|
setupSearch()
|
||||||
return false;
|
return false
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,197 +1,197 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.toggleSourceEditor = function (event) {
|
editor.toggleSourceEditor = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
|
|
||||||
if(document.querySelector('[data-kind="content-only"]')) {
|
if (document.querySelector('[data-kind="content-only"]')) {
|
||||||
window.location = window.location.pathname + "?visual=true"
|
window.location = window.location.pathname + '?visual=true'
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.location = window.location.pathname + "?visual=false"
|
|
||||||
}
|
|
||||||
|
|
||||||
function deleteFrontMatterItem(event) {
|
|
||||||
event.preventDefault();
|
|
||||||
document.getElementById(this.dataset.delete).remove();
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeFromBaseTemplate(id, type, name, parent) {
|
|
||||||
let clone = document.importNode(templates.base.content, true);
|
|
||||||
clone.querySelector('fieldset').id = id;
|
|
||||||
clone.querySelector('fieldset').dataset.type = type;
|
|
||||||
clone.querySelector('h3').innerHTML = name;
|
|
||||||
clone.querySelector('.delete').dataset.delete = id;
|
|
||||||
clone.querySelector('.delete').addEventListener('click', deleteFrontMatterItem);
|
|
||||||
clone.querySelector('.add').addEventListener('click', addFrontMatterItem);
|
|
||||||
|
|
||||||
if(parent.classList.contains("frontmatter")) {
|
|
||||||
parent.insertBefore(clone, document.querySelector('div.button.add'));
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.appendChild(clone);
|
window.location = window.location.pathname + '?visual=false'
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeFromArrayItemTemplate(id, number, parent) {
|
function deleteFrontMatterItem (event) {
|
||||||
let clone = document.importNode(templates.arrayItem.content, true);
|
event.preventDefault()
|
||||||
clone.querySelector('[data-type="array-item"]').id = `${id}-${number}`;
|
document.getElementById(this.dataset.delete).remove()
|
||||||
clone.querySelector('input').name = id;
|
|
||||||
clone.querySelector('input').id = id;
|
|
||||||
clone.querySelector('div.action').dataset.delete = `${id}-${number}`;
|
|
||||||
clone.querySelector('div.action').addEventListener('click', deleteFrontMatterItem);
|
|
||||||
parent.querySelector('.group').appendChild(clone)
|
|
||||||
document.getElementById(`${id}-${number}`).querySelector('input').focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeFromObjectItemTemplate(id, name, parent) {
|
function makeFromBaseTemplate (id, type, name, parent) {
|
||||||
let clone = document.importNode(templates.objectItem.content, true);
|
let clone = document.importNode(templates.base.content, true)
|
||||||
clone.querySelector('.block').id = `block-${id}`;
|
clone.querySelector('fieldset').id = id
|
||||||
clone.querySelector('.block').dataset.content = id;
|
clone.querySelector('fieldset').dataset.type = type
|
||||||
clone.querySelector('label').for = id;
|
clone.querySelector('h3').innerHTML = name
|
||||||
clone.querySelector('label').innerHTML = name;
|
clone.querySelector('.delete').dataset.delete = id
|
||||||
clone.querySelector('input').name = id;
|
clone.querySelector('.delete').addEventListener('click', deleteFrontMatterItem)
|
||||||
clone.querySelector('input').id = id;
|
clone.querySelector('.add').addEventListener('click', addFrontMatterItem)
|
||||||
clone.querySelector('.action').dataset.delete = `block-${id}`;
|
|
||||||
clone.querySelector('.action').addEventListener('click', deleteFrontMatterItem);
|
if (parent.classList.contains('frontmatter')) {
|
||||||
|
parent.insertBefore(clone, document.querySelector('div.button.add'))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
parent.appendChild(clone)
|
parent.appendChild(clone)
|
||||||
document.getElementById(id).focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFrontMatterItemPrompt(parent) {
|
function makeFromArrayItemTemplate (id, number, parent) {
|
||||||
return function (event) {
|
let clone = document.importNode(templates.arrayItem.content, true)
|
||||||
event.preventDefault();
|
clone.querySelector('[data-type="array-item"]').id = `${id}-${number}`
|
||||||
|
clone.querySelector('input').name = id
|
||||||
|
clone.querySelector('input').id = id
|
||||||
|
clone.querySelector('div.action').dataset.delete = `${id}-${number}`
|
||||||
|
clone.querySelector('div.action').addEventListener('click', deleteFrontMatterItem)
|
||||||
|
parent.querySelector('.group').appendChild(clone)
|
||||||
|
document.getElementById(`${id}-${number}`).querySelector('input').focus()
|
||||||
|
}
|
||||||
|
|
||||||
let value = event.currentTarget.querySelector('input').value;
|
function makeFromObjectItemTemplate (id, name, parent) {
|
||||||
if(value === '') {
|
let clone = document.importNode(templates.objectItem.content, true)
|
||||||
return true;
|
clone.querySelector('.block').id = `block-${id}`
|
||||||
|
clone.querySelector('.block').dataset.content = id
|
||||||
|
clone.querySelector('label').for = id
|
||||||
|
clone.querySelector('label').innerHTML = name
|
||||||
|
clone.querySelector('input').name = id
|
||||||
|
clone.querySelector('input').id = id
|
||||||
|
clone.querySelector('.action').dataset.delete = `block-${id}`
|
||||||
|
clone.querySelector('.action').addEventListener('click', deleteFrontMatterItem)
|
||||||
|
|
||||||
|
parent.appendChild(clone)
|
||||||
|
document.getElementById(id).focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFrontMatterItemPrompt (parent) {
|
||||||
|
return function (event) {
|
||||||
|
event.preventDefault()
|
||||||
|
|
||||||
|
let value = event.currentTarget.querySelector('input').value
|
||||||
|
if (value === '') {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
|
|
||||||
let name = value.substring(0, value.lastIndexOf(':')),
|
let name = value.substring(0, value.lastIndexOf(':')),
|
||||||
type = value.substring(value.lastIndexOf(':') + 1, value.length);
|
type = value.substring(value.lastIndexOf(':') + 1, value.length)
|
||||||
|
|
||||||
if(type !== "" && type !== "array" && type !== "object") {
|
if (type !== '' && type !== 'array' && type !== 'object') {
|
||||||
name = value;
|
name = value
|
||||||
}
|
}
|
||||||
|
|
||||||
name = name.replace(' ', '_');
|
name = name.replace(' ', '_')
|
||||||
|
|
||||||
let id = name;
|
let id = name
|
||||||
|
|
||||||
if(parent.id != '') {
|
if (parent.id != '') {
|
||||||
id = parent.id + "." + id;
|
id = parent.id + '.' + id
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == "array" || type == "object") {
|
if (type == 'array' || type == 'object') {
|
||||||
if(parent.dataset.type == "parent") {
|
if (parent.dataset.type == 'parent') {
|
||||||
makeFromBaseTemplate(id, type, name, document.querySelector('.frontmatter'));
|
makeFromBaseTemplate(id, type, name, document.querySelector('.frontmatter'))
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
makeFromBaseTemplate(id, type, name, block);
|
makeFromBaseTemplate(id, type, name, block)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let group = parent.querySelector('.group');
|
let group = parent.querySelector('.group')
|
||||||
|
|
||||||
if(group == null) {
|
if (group == null) {
|
||||||
parent.insertAdjacentHTML('afterbegin', '<div class="group"></div>');
|
parent.insertAdjacentHTML('afterbegin', '<div class="group"></div>')
|
||||||
group = parent.querySelector('.group');
|
group = parent.querySelector('.group')
|
||||||
}
|
}
|
||||||
|
|
||||||
makeFromObjectItemTemplate(id, name, 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;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == "object" || type == "parent") {
|
if (type == 'object' || type == 'parent') {
|
||||||
let clone = document.importNode(templates.question.content, true);
|
let clone = document.importNode(templates.question.content, true)
|
||||||
clone.querySelector('form').id = tempID;
|
clone.querySelector('form').id = tempID
|
||||||
clone.querySelector('h3').innerHTML = 'New field';
|
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('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('.ok').innerHTML = 'Create'
|
||||||
clone.querySelector('form').addEventListener('submit', addFrontMatterItemPrompt(parent));
|
clone.querySelector('form').addEventListener('submit', addFrontMatterItemPrompt(parent))
|
||||||
clone.querySelector('form').classList.add('active')
|
clone.querySelector('form').classList.add('active')
|
||||||
document.querySelector('body').appendChild(clone);
|
document.querySelector('body').appendChild(clone)
|
||||||
|
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.getElementById(tempID).classList.add('active');
|
document.getElementById(tempID).classList.add('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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')
|
||||||
buttons.editSource = document.querySelector('#edit-source');
|
buttons.editSource = document.querySelector('#edit-source')
|
||||||
|
|
||||||
if(buttons.editSource) {
|
if (buttons.editSource) {
|
||||||
buttons.editSource.addEventListener('click', editor.toggleSourceEditor)
|
buttons.editSource.addEventListener('click', editor.toggleSourceEditor)
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = document.getElementById('editor'),
|
let container = document.getElementById('editor'),
|
||||||
kind = container.dataset.kind,
|
kind = container.dataset.kind,
|
||||||
rune = container.dataset.rune;
|
rune = container.dataset.rune
|
||||||
|
|
||||||
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"]'),
|
||||||
|
@ -199,44 +199,44 @@ document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
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().setValue(textarea.value);
|
|
||||||
aceEditor.getSession().on('change', function () {
|
|
||||||
textarea.value = aceEditor.getSession().getValue();
|
|
||||||
});
|
|
||||||
|
|
||||||
if(mode == "markdown") options.showGutter = false;
|
|
||||||
aceEditor.setOptions(options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let deleteFrontMatterItemButtons = document.getElementsByClassName('delete');
|
aceEditor.getSession().setMode('ace/mode/' + mode)
|
||||||
Array.from(deleteFrontMatterItemButtons).forEach(button => {
|
aceEditor.getSession().setValue(textarea.value)
|
||||||
button.addEventListener('click', deleteFrontMatterItem);
|
aceEditor.getSession().on('change', function () {
|
||||||
});
|
textarea.value = aceEditor.getSession().getValue()
|
||||||
|
})
|
||||||
|
|
||||||
let addFrontMatterItemButtons = document.getElementsByClassName('add');
|
if (mode == 'markdown') options.showGutter = false
|
||||||
|
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 => {
|
Array.from(addFrontMatterItemButtons).forEach(button => {
|
||||||
button.addEventListener('click', addFrontMatterItem);
|
button.addEventListener('click', addFrontMatterItem)
|
||||||
});
|
})
|
||||||
|
|
||||||
let saveContent = function () {
|
let saveContent = function () {
|
||||||
let data = form2js(document.querySelector('form'));
|
let data = form2js(document.querySelector('form'))
|
||||||
|
|
||||||
if(typeof data.content === "undefined" && kind != 'frontmatter-only') {
|
if (typeof data.content === 'undefined' && kind !== 'frontmatter-only') {
|
||||||
data.content = "";
|
data.content = ''
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof data.content === "number") {
|
if (typeof data.content === 'number') {
|
||||||
data.content = data.content.toString();
|
data.content = data.content.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
|
|
||||||
buttons.setLoading('save')
|
buttons.setLoading('save')
|
||||||
|
|
||||||
|
@ -248,31 +248,31 @@ document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
buttons.setDone('save')
|
buttons.setDone('save')
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e)
|
||||||
buttons.setDone('save', false)
|
buttons.setDone('save', false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector('#save').addEventListener('click', event => {
|
document.querySelector('#save').addEventListener('click', event => {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
saveContent();
|
saveContent()
|
||||||
});
|
})
|
||||||
|
|
||||||
document.querySelector('form').addEventListener('submit', (event) => {
|
document.querySelector('form').addEventListener('submit', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
saveContent();
|
saveContent()
|
||||||
});
|
})
|
||||||
|
|
||||||
window.addEventListener('keydown', (event) => {
|
window.addEventListener('keydown', (event) => {
|
||||||
if(event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
switch(String.fromCharCode(event.which).toLowerCase()) {
|
switch (String.fromCharCode(event.which).toLowerCase()) {
|
||||||
case 's':
|
case 's':
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
saveContent();
|
saveContent()
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
'use strict';
|
'use strict'
|
||||||
|
|
||||||
var listing = {
|
var listing = {
|
||||||
selectMultiple: false
|
selectMultiple: false
|
||||||
};
|
}
|
||||||
|
|
||||||
listing.reload = function (callback) {
|
listing.reload = function (callback) {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
|
|
||||||
request.open('GET', window.location);
|
request.open('GET', window.location)
|
||||||
request.setRequestHeader('Minimal', 'true');
|
request.setRequestHeader('Minimal', 'true')
|
||||||
request.send();
|
request.send()
|
||||||
request.onreadystatechange = function () {
|
request.onreadystatechange = function () {
|
||||||
if(request.readyState == 4) {
|
if (request.readyState === 4) {
|
||||||
if(request.status == 200) {
|
if (request.status === 200) {
|
||||||
document.querySelector('body main').innerHTML = request.responseText;
|
document.querySelector('body main').innerHTML = request.responseText
|
||||||
listing.addDoubleTapEvent();
|
listing.addDoubleTapEvent()
|
||||||
|
|
||||||
if(typeof callback == 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback();
|
callback()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,281 +25,281 @@ listing.reload = function (callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.itemDragStart = function (event) {
|
listing.itemDragStart = function (event) {
|
||||||
let el = event.target;
|
let el = event.target
|
||||||
|
|
||||||
for(let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
if(!el.classList.contains('item')) {
|
if (!el.classList.contains('item')) {
|
||||||
el = el.parentElement;
|
el = el.parentElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
event.dataTransfer.setData("id", el.id);
|
event.dataTransfer.setData('id', el.id)
|
||||||
event.dataTransfer.setData("name", el.querySelector('.name').innerHTML);
|
event.dataTransfer.setData('name', el.querySelector('.name').innerHTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.itemDragOver = function (event) {
|
listing.itemDragOver = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
let el = event.target;
|
let el = event.target
|
||||||
|
|
||||||
for(let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
if(!el.classList.contains('item')) {
|
if (!el.classList.contains('item')) {
|
||||||
el = el.parentElement;
|
el = el.parentElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
el.style.opacity = 1;
|
el.style.opacity = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.itemDrop = function (e) {
|
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
|
||||||
|
|
||||||
for(let i = 0; i < 5; i++) {
|
for (let i = 0; i < 5; i++) {
|
||||||
if(!el.classList.contains('item')) {
|
if (!el.classList.contains('item')) {
|
||||||
el = el.parentElement;
|
el = el.parentElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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')) {
|
||||||
el = el.parentElement;
|
el = el.parentElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(files.length > 0) {
|
if (files.length > 0) {
|
||||||
if(el != null && el.classList.contains('item') && el.dataset.dir == "true") {
|
if (el != null && el.classList.contains('item') && el.dataset.dir == 'true') {
|
||||||
listing.handleFiles(files, el.querySelector('.name').innerHTML + "/");
|
listing.handleFiles(files, el.querySelector('.name').innerHTML + '/')
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.handleFiles(files, "");
|
listing.handleFiles(files, '')
|
||||||
} else {
|
} else {
|
||||||
Array.from(items).forEach(file => {
|
Array.from(items).forEach(file => {
|
||||||
file.style.opacity = 1;
|
file.style.opacity = 1
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.rename = function (event) {
|
listing.rename = function (event) {
|
||||||
if(!selectedItems.length || selectedItems.length > 1) {
|
if (!selectedItems.length || selectedItems.length > 1) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let item = document.getElementById(selectedItems[0]);
|
let item = document.getElementById(selectedItems[0])
|
||||||
|
|
||||||
if(item.classList.contains('disabled')) {
|
if (item.classList.contains('disabled')) {
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
buttons.setLoading('rename');
|
buttons.setLoading('rename')
|
||||||
|
|
||||||
webdav.move(link, newLink).then(() => {
|
webdav.move(link, newLink).then(() => {
|
||||||
listing.reload(() => {
|
listing.reload(() => {
|
||||||
newName = btoa(newName);
|
newName = btoa(newName)
|
||||||
selectedItems = [newName];
|
selectedItems = [newName]
|
||||||
document.getElementById(newName).setAttribute("aria-selected", true);
|
document.getElementById(newName).setAttribute('aria-selected', true)
|
||||||
listing.handleSelectionChange();
|
listing.handleSelectionChange()
|
||||||
});
|
})
|
||||||
|
|
||||||
buttons.setDone('rename');
|
buttons.setDone('rename')
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
field.innerHTML = name;
|
field.innerHTML = name
|
||||||
buttons.setDone('rename', false);
|
buttons.setDone('rename', false)
|
||||||
console.log(error);
|
console.log(error)
|
||||||
});
|
})
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
let clone = document.importNode(templates.question.content, true);
|
let clone = document.importNode(templates.question.content, true)
|
||||||
clone.querySelector('h3').innerHTML = 'Rename';
|
clone.querySelector('h3').innerHTML = 'Rename'
|
||||||
clone.querySelector('input').value = name;
|
clone.querySelector('input').value = name
|
||||||
clone.querySelector('.ok').innerHTML = 'Rename';
|
clone.querySelector('.ok').innerHTML = 'Rename'
|
||||||
clone.querySelector('form').addEventListener('submit', submit);
|
clone.querySelector('form').addEventListener('submit', submit)
|
||||||
|
|
||||||
document.querySelector('body').appendChild(clone)
|
document.querySelector('body').appendChild(clone)
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector('.prompt').classList.add('active');
|
document.querySelector('.prompt').classList.add('active')
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.handleFiles = function (files, base) {
|
listing.handleFiles = function (files, base) {
|
||||||
buttons.setLoading('upload');
|
buttons.setLoading('upload')
|
||||||
|
|
||||||
let promises = [];
|
let 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.setDone('upload');
|
buttons.setDone('upload')
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e)
|
||||||
buttons.setDone('upload', false);
|
buttons.setDone('upload', false)
|
||||||
})
|
})
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.unselectAll = function () {
|
listing.unselectAll = function () {
|
||||||
let items = document.getElementsByClassName('item');
|
let items = document.getElementsByClassName('item')
|
||||||
Array.from(items).forEach(link => {
|
Array.from(items).forEach(link => {
|
||||||
link.setAttribute("aria-selected", false);
|
link.setAttribute('aria-selected', false)
|
||||||
});
|
})
|
||||||
|
|
||||||
selectedItems = [];
|
selectedItems = []
|
||||||
|
|
||||||
listing.handleSelectionChange();
|
listing.handleSelectionChange()
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.handleSelectionChange = function (event) {
|
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')
|
||||||
|
|
||||||
if(selectedNumber > 1) {
|
if (selectedNumber > 1) {
|
||||||
buttons.open.classList.add("disabled");
|
buttons.open.classList.add('disabled')
|
||||||
buttons.rename.classList.add("disabled");
|
buttons.rename.classList.add('disabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
if(selectedNumber == 1) {
|
if (selectedNumber == 1) {
|
||||||
if(document.getElementById(selectedItems[0]).dataset.dir == "true") {
|
if (document.getElementById(selectedItems[0]).dataset.dir == 'true') {
|
||||||
buttons.open.classList.add("disabled");
|
buttons.open.classList.add('disabled')
|
||||||
} else {
|
} else {
|
||||||
buttons.open.classList.remove("disabled");
|
buttons.open.classList.remove('disabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons.rename.classList.remove("disabled");
|
buttons.rename.classList.remove('disabled')
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fileAction.classList.add("disabled");
|
fileAction.classList.add('disabled')
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.redefineDownloadURLs = function () {
|
listing.redefineDownloadURLs = function () {
|
||||||
let files = "";
|
let files = ''
|
||||||
|
|
||||||
for(let i = 0; i < selectedItems.length; i++) {
|
for (let i = 0; i < selectedItems.length; i++) {
|
||||||
let url = document.getElementById(selectedItems[i]).dataset.url;
|
let url = document.getElementById(selectedItems[i]).dataset.url
|
||||||
files += url.replace(window.location.pathname, "") + ",";
|
files += url.replace(window.location.pathname, '') + ','
|
||||||
}
|
}
|
||||||
|
|
||||||
files = files.substring(0, files.length - 1);
|
files = files.substring(0, files.length - 1)
|
||||||
files = encodeURIComponent(files);
|
files = encodeURIComponent(files)
|
||||||
|
|
||||||
let links = document.querySelectorAll("#download ul a");
|
let links = document.querySelectorAll('#download ul a')
|
||||||
Array.from(links).forEach(link => {
|
Array.from(links).forEach(link => {
|
||||||
link.href = "?download=" + link.dataset.format + "&files=" + files;
|
link.href = '?download=' + link.dataset.format + '&files=' + files
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.openItem = function (event) {
|
listing.openItem = function (event) {
|
||||||
window.location = event.currentTarget.dataset.url;
|
window.location = event.currentTarget.dataset.url
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.selectItem = function (event) {
|
listing.selectItem = function (event) {
|
||||||
let el = event.currentTarget;
|
let el = event.currentTarget
|
||||||
|
|
||||||
if(selectedItems.length != 0) event.preventDefault();
|
if (selectedItems.length != 0) event.preventDefault()
|
||||||
if(selectedItems.indexOf(el.id) == -1) {
|
if (selectedItems.indexOf(el.id) == -1) {
|
||||||
if(!event.ctrlKey && !listing.selectMultiple) listing.unselectAll();
|
if (!event.ctrlKey && !listing.selectMultiple) listing.unselectAll()
|
||||||
|
|
||||||
el.setAttribute("aria-selected", true);
|
el.setAttribute('aria-selected', true)
|
||||||
selectedItems.push(el.id);
|
selectedItems.push(el.id)
|
||||||
} else {
|
} else {
|
||||||
el.setAttribute("aria-selected", false);
|
el.setAttribute('aria-selected', false)
|
||||||
selectedItems.removeElement(el.id);
|
selectedItems.removeElement(el.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.handleSelectionChange();
|
listing.handleSelectionChange()
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.newFileButton = function (event) {
|
listing.newFileButton = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
|
|
||||||
let clone = document.importNode(templates.question.content, true);
|
let clone = document.importNode(templates.question.content, true)
|
||||||
clone.querySelector('h3').innerHTML = 'New file';
|
clone.querySelector('h3').innerHTML = 'New file'
|
||||||
clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir.';
|
clone.querySelector('p').innerHTML = 'End with a trailing slash to create a dir.'
|
||||||
clone.querySelector('.ok').innerHTML = 'Create';
|
clone.querySelector('.ok').innerHTML = 'Create'
|
||||||
clone.querySelector('form').addEventListener('submit', listing.newFilePrompt);
|
clone.querySelector('form').addEventListener('submit', listing.newFilePrompt)
|
||||||
|
|
||||||
document.querySelector('body').appendChild(clone)
|
document.querySelector('body').appendChild(clone)
|
||||||
document.querySelector('.overlay').classList.add('active');
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector('.prompt').classList.add('active');
|
document.querySelector('.prompt').classList.add('active')
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.newFilePrompt = function (event) {
|
listing.newFilePrompt = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
buttons.setLoading('new');
|
buttons.setLoading('new')
|
||||||
|
|
||||||
let name = event.currentTarget.querySelector('input').value;
|
let name = event.currentTarget.querySelector('input').value
|
||||||
|
|
||||||
webdav.new(window.location.pathname + name)
|
webdav.new(window.location.pathname + name)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
buttons.setDone('new');
|
buttons.setDone('new')
|
||||||
listing.reload();
|
listing.reload()
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e)
|
||||||
buttons.setDone('new', false);
|
buttons.setDone('new', false)
|
||||||
});
|
})
|
||||||
|
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
return false;
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
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 () {
|
||||||
|
@ -307,273 +307,272 @@ listing.addDoubleTapEvent = function () {
|
||||||
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 => {
|
||||||
if(touches.id != file.id) {
|
if (touches.id != file.id) {
|
||||||
touches.id = file.id;
|
touches.id = file.id
|
||||||
touches.count = 1;
|
touches.count = 1
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
touches.count = 0;
|
touches.count = 0
|
||||||
}, 300)
|
}, 300)
|
||||||
|
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
touches.count++;
|
touches.count++
|
||||||
|
|
||||||
if(touches.count > 1) {
|
if (touches.count > 1) {
|
||||||
window.location = file.dataset.url;
|
window.location = file.dataset.url
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Keydown events
|
// Keydown events
|
||||||
window.addEventListener('keydown', (event) => {
|
window.addEventListener('keydown', (event) => {
|
||||||
if(event.keyCode == 27) {
|
if (event.keyCode == 27) {
|
||||||
listing.unselectAll();
|
listing.unselectAll()
|
||||||
|
|
||||||
if(document.querySelectorAll('.prompt').length) {
|
if (document.querySelectorAll('.prompt').length) {
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.keyCode == 113) {
|
if (event.keyCode == 113) {
|
||||||
listing.rename();
|
listing.rename()
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event.ctrlKey || event.metaKey) {
|
if (event.ctrlKey || event.metaKey) {
|
||||||
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'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
window.addEventListener("resize", () => {
|
window.addEventListener('resize', () => {
|
||||||
listing.updateColumns();
|
listing.updateColumns()
|
||||||
});
|
})
|
||||||
|
|
||||||
listing.selectMoveFolder = function (event) {
|
listing.selectMoveFolder = function (event) {
|
||||||
if(event.target.getAttribute("aria-selected") === "true") {
|
if (event.target.getAttribute('aria-selected') === 'true') {
|
||||||
event.target.setAttribute("aria-selected", false);
|
event.target.setAttribute('aria-selected', false)
|
||||||
return;
|
return
|
||||||
} else {
|
} else {
|
||||||
if(document.querySelector(".file-list li[aria-selected=true]")) {
|
if (document.querySelector('.file-list li[aria-selected=true]')) {
|
||||||
document.querySelector(".file-list li[aria-selected=true]").setAttribute("aria-selected", false);
|
document.querySelector('.file-list li[aria-selected=true]').setAttribute('aria-selected', false)
|
||||||
}
|
}
|
||||||
event.target.setAttribute("aria-selected", true);
|
event.target.setAttribute('aria-selected', true)
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.getJSON = function (link) {
|
listing.getJSON = function (link) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let request = new XMLHttpRequest();
|
let request = new XMLHttpRequest()
|
||||||
request.open("GET", link);
|
request.open('GET', link)
|
||||||
request.setRequestHeader("Accept", "application/json");
|
request.setRequestHeader('Accept', 'application/json')
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if(request.status == 200) {
|
if (request.status == 200) {
|
||||||
resolve(request.responseText);
|
resolve(request.responseText)
|
||||||
} else {
|
} else {
|
||||||
reject(request.statusText);
|
reject(request.statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
request.onerror = () => reject(request.statusText);
|
request.onerror = () => reject(request.statusText)
|
||||||
request.send();
|
request.send()
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.moveMakeItem = function (url, name) {
|
listing.moveMakeItem = function (url, name) {
|
||||||
let node = document.createElement("li"),
|
let node = document.createElement('li'),
|
||||||
count = 0;
|
count = 0
|
||||||
|
|
||||||
node.dataset.url = url;
|
node.dataset.url = url
|
||||||
node.innerHTML = name;
|
node.innerHTML = name
|
||||||
node.setAttribute("aria-selected", false);
|
node.setAttribute('aria-selected', false)
|
||||||
|
|
||||||
node.addEventListener("dblclick", listing.moveDialogNext);
|
node.addEventListener('dblclick', listing.moveDialogNext)
|
||||||
node.addEventListener("click", listing.selectMoveFolder);
|
node.addEventListener('click', listing.selectMoveFolder)
|
||||||
node.addEventListener('touchstart', event => {
|
node.addEventListener('touchstart', event => {
|
||||||
count++;
|
count++
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
count = 0;
|
count = 0
|
||||||
}, 300)
|
}, 300)
|
||||||
|
|
||||||
if(count > 1) {
|
if (count > 1) {
|
||||||
listing.moveDialogNext(event);
|
listing.moveDialogNext(event)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
return node;
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.moveDialogNext = function (event) {
|
listing.moveDialogNext = function (event) {
|
||||||
let request = new XMLHttpRequest(),
|
let request = new XMLHttpRequest(),
|
||||||
prompt = document.querySelector("form.prompt.active"),
|
prompt = document.querySelector('form.prompt.active'),
|
||||||
list = prompt.querySelector("div.file-list ul");
|
list = prompt.querySelector('div.file-list ul')
|
||||||
|
|
||||||
prompt.addEventListener("submit", listing.moveSelected);
|
prompt.addEventListener('submit', listing.moveSelected)
|
||||||
|
|
||||||
listing.getJSON(event.target.dataset.url)
|
listing.getJSON(event.target.dataset.url)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let dirs = 0;
|
let dirs = 0
|
||||||
|
|
||||||
prompt.querySelector("ul").innerHTML = "";
|
prompt.querySelector('ul').innerHTML = ''
|
||||||
prompt.querySelector('code').innerHTML = event.target.dataset.url;
|
prompt.querySelector('code').innerHTML = event.target.dataset.url
|
||||||
|
|
||||||
if(event.target.dataset.url != baseURL + "/") {
|
if (event.target.dataset.url != baseURL + '/') {
|
||||||
let node = listing.moveMakeItem(removeLastDirectoryPartOf(event.target.dataset.url) + "/", "..")
|
let node = listing.moveMakeItem(removeLastDirectoryPartOf(event.target.dataset.url) + '/', '..')
|
||||||
list.appendChild(node);
|
list.appendChild(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(JSON.parse(data) == null) {
|
if (JSON.parse(data) == null) {
|
||||||
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
|
prompt.querySelector('p').innerHTML = `There aren't any folders in this directory.`
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let f of JSON.parse(data)) {
|
for (let f of JSON.parse(data)) {
|
||||||
if(f.IsDir === true) {
|
if (f.IsDir === true) {
|
||||||
dirs++;
|
dirs++
|
||||||
list.appendChild(listing.moveMakeItem(f.URL, f.Name));
|
list.appendChild(listing.moveMakeItem(f.URL, f.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dirs === 0)
|
if (dirs === 0)
|
||||||
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
|
prompt.querySelector('p').innerHTML = `There aren't any folders in this directory.`
|
||||||
})
|
})
|
||||||
.catch(e => console.log(e));
|
.catch(e => console.log(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.moveSelected = function (event) {
|
listing.moveSelected = function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
|
|
||||||
let promises = [];
|
let promises = []
|
||||||
buttons.setLoading("move");
|
buttons.setLoading('move')
|
||||||
|
|
||||||
for(let file of selectedItems) {
|
for (let file of selectedItems) {
|
||||||
let fileElement = document.getElementById(file),
|
let fileElement = document.getElementById(file),
|
||||||
destFolder = event.target.querySelector("p code").innerHTML;
|
destFolder = event.target.querySelector('p code').innerHTML
|
||||||
|
|
||||||
if(event.currentTarget.querySelector("li[aria-selected=true]") != null) {
|
if (event.currentTarget.querySelector('li[aria-selected=true]') != null) {
|
||||||
destFolder = event.currentTarget.querySelector("li[aria-selected=true]").dataset.url;
|
destFolder = event.currentTarget.querySelector('li[aria-selected=true]').dataset.url
|
||||||
}
|
}
|
||||||
|
|
||||||
let destPath = "/" + destFolder + "/" + fileElement.querySelector(".name").innerHTML;
|
let destPath = '/' + destFolder + '/' + fileElement.querySelector('.name').innerHTML
|
||||||
destPath = destPath.replace('//', '/');
|
destPath = destPath.replace('//', '/')
|
||||||
|
|
||||||
promises.push(webdav.move(fileElement.dataset.url, destPath));
|
promises.push(webdav.move(fileElement.dataset.url, destPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closePrompt(event);
|
closePrompt(event)
|
||||||
buttons.setDone("move");
|
buttons.setDone('move')
|
||||||
listing.reload();
|
listing.reload()
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.log(e)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
listing.moveEvent = function (event) {
|
listing.moveEvent = function (event) {
|
||||||
if(event.currentTarget.classList.contains("disabled"))
|
if (event.currentTarget.classList.contains('disabled'))
|
||||||
return;
|
return
|
||||||
|
|
||||||
listing.getJSON(window.location.pathname)
|
listing.getJSON(window.location.pathname)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let prompt = document.importNode(templates.move.content, true),
|
let prompt = document.importNode(templates.move.content, true),
|
||||||
list = prompt.querySelector("div.file-list ul"),
|
list = prompt.querySelector('div.file-list ul'),
|
||||||
dirs = 0;
|
dirs = 0
|
||||||
|
|
||||||
prompt.querySelector("form").addEventListener("submit", listing.moveSelected);
|
prompt.querySelector('form').addEventListener('submit', listing.moveSelected)
|
||||||
prompt.querySelector('code').innerHTML = window.location.pathname;
|
prompt.querySelector('code').innerHTML = window.location.pathname
|
||||||
|
|
||||||
if(window.location.pathname !== baseURL + "/") {
|
if (window.location.pathname !== baseURL + '/') {
|
||||||
list.appendChild(listing.moveMakeItem(removeLastDirectoryPartOf(window.location.pathname) + "/", ".."));
|
list.appendChild(listing.moveMakeItem(removeLastDirectoryPartOf(window.location.pathname) + '/', '..'))
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let f of JSON.parse(data)) {
|
for (let f of JSON.parse(data)) {
|
||||||
if(f.IsDir === true) {
|
if (f.IsDir === true) {
|
||||||
dirs++;
|
dirs++
|
||||||
list.appendChild(listing.moveMakeItem(f.URL, f.Name));
|
list.appendChild(listing.moveMakeItem(f.URL, f.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dirs === 0) {
|
if (dirs === 0) {
|
||||||
prompt.querySelector("p").innerHTML = `There aren't any folders in this directory.`;
|
prompt.querySelector('p').innerHTML = `There aren't any folders in this directory.`
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.appendChild(prompt);
|
document.body.appendChild(prompt)
|
||||||
document.querySelector(".overlay").classList.add("active");
|
document.querySelector('.overlay').classList.add('active')
|
||||||
document.querySelector(".prompt").classList.add("active");
|
document.querySelector('.prompt').classList.add('active')
|
||||||
})
|
})
|
||||||
.catch(e => console.log(e));
|
.catch(e => console.log(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', event => {
|
document.addEventListener('DOMContentLoaded', event => {
|
||||||
listing.updateColumns();
|
listing.updateColumns()
|
||||||
listing.addDoubleTapEvent();
|
listing.addDoubleTapEvent()
|
||||||
|
|
||||||
buttons.rename = document.getElementById("rename");
|
buttons.rename = document.getElementById('rename')
|
||||||
buttons.upload = document.getElementById("upload");
|
buttons.upload = document.getElementById('upload')
|
||||||
buttons.new = document.getElementById('new');
|
buttons.new = document.getElementById('new')
|
||||||
buttons.download = document.getElementById('download');
|
buttons.download = document.getElementById('download')
|
||||||
buttons.move = document.getElementById("move");
|
buttons.move = document.getElementById('move')
|
||||||
|
|
||||||
buttons.move.addEventListener("click", listing.moveEvent);
|
buttons.move.addEventListener('click', listing.moveEvent)
|
||||||
|
|
||||||
document.getElementById('multiple-selection-activate').addEventListener('click', event => {
|
document.getElementById('multiple-selection-activate').addEventListener('click', event => {
|
||||||
listing.selectMultiple = true;
|
listing.selectMultiple = true
|
||||||
clickOverlay.click();
|
clickOverlay.click()
|
||||||
|
|
||||||
document.getElementById('multiple-selection').classList.add('active');
|
document.getElementById('multiple-selection').classList.add('active')
|
||||||
document.querySelector('body').style.paddingBottom = "4em";
|
document.querySelector('body').style.paddingBottom = '4em'
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('multiple-selection-cancel').addEventListener('click', event => {
|
document.getElementById('multiple-selection-cancel').addEventListener('click', event => {
|
||||||
listing.selectMultiple = false;
|
listing.selectMultiple = false
|
||||||
|
|
||||||
document.querySelector('body').style.paddingBottom = "0";
|
document.querySelector('body').style.paddingBottom = '0'
|
||||||
document.getElementById('multiple-selection').classList.remove('active');
|
document.getElementById('multiple-selection').classList.remove('active')
|
||||||
})
|
})
|
||||||
|
|
||||||
if(user.AllowEdit) {
|
if (user.AllowEdit) {
|
||||||
buttons.rename.addEventListener("click", listing.rename);
|
buttons.rename.addEventListener('click', listing.rename)
|
||||||
}
|
}
|
||||||
|
|
||||||
let items = document.getElementsByClassName('item');
|
let items = document.getElementsByClassName('item')
|
||||||
|
|
||||||
if(user.AllowNew) {
|
if (user.AllowNew) {
|
||||||
buttons.upload.addEventListener("click", (event) => {
|
buttons.upload.addEventListener('click', (event) => {
|
||||||
document.getElementById("upload-input").click();
|
document.getElementById('upload-input').click()
|
||||||
});
|
})
|
||||||
|
|
||||||
buttons.new.addEventListener('click', listing.newFileButton);
|
buttons.new.addEventListener('click', listing.newFileButton)
|
||||||
|
|
||||||
// Drag and Drop
|
// Drag and Drop
|
||||||
document.addEventListener("dragover", function (event) {
|
document.addEventListener('dragover', function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault()
|
||||||
}, false);
|
}, false)
|
||||||
|
|
||||||
document.addEventListener("dragenter", (event) => {
|
document.addEventListener('dragenter', (event) => {
|
||||||
Array.from(items).forEach(file => {
|
Array.from(items).forEach(file => {
|
||||||
file.style.opacity = 0.5;
|
file.style.opacity = 0.5
|
||||||
});
|
})
|
||||||
}, false);
|
}, false)
|
||||||
|
|
||||||
document.addEventListener("dragend", (event) => {
|
document.addEventListener('dragend', (event) => {
|
||||||
Array.from(items).forEach(file => {
|
Array.from(items).forEach(file => {
|
||||||
file.style.opacity = 1;
|
file.style.opacity = 1
|
||||||
});
|
})
|
||||||
}, false);
|
}, false)
|
||||||
|
|
||||||
document.addEventListener("drop", listing.documentDrop, false);
|
document.addEventListener('drop', listing.documentDrop, false)
|
||||||
}
|
}
|
||||||
|
})
|
||||||
});
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
75755022adfcafcbf6d563ce4af52fc022e6f163
|
407ca3a29b2bf1bf0e7fb611b732dffd77ed0083
|
|
@ -1,8 +1,3 @@
|
||||||
//go:generate go get github.com/jteeuwen/go-bindata/go-bindata
|
|
||||||
//go:generate go get github.com/bountylabs/gitversion
|
|
||||||
//go:generate go-bindata -pkg assets -prefix "_embed" -o assets/binary.go _embed/templates/... _embed/public/js/... _embed/public/css/... _embed/public/ace/src-min/...
|
|
||||||
//go:generate gitversion -s -o page/version.go -p page
|
|
||||||
|
|
||||||
// Package filemanager provides middleware for managing files in a directory
|
// Package filemanager provides middleware for managing files in a directory
|
||||||
// when directory path is requested instead of a specific file. Based on browse
|
// when directory path is requested instead of a specific file. Based on browse
|
||||||
// middleware.
|
// middleware.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package page
|
package page
|
||||||
|
|
||||||
var GIT_COMMIT_HASH = "6b261bb"
|
var GIT_COMMIT_HASH = "df081c8"
|
||||||
var CIRCLE_BUILD_NUM = ""
|
var CIRCLE_BUILD_NUM = ""
|
||||||
var GENERATED int64 = 1490520061033206900
|
var GENERATED int64 = 1490523864386631900
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
go get github.com/jteeuwen/go-bindata/go-bindata
|
||||||
|
go get github.com/bountylabs/gitversion
|
||||||
|
|
||||||
|
go-bindata -pkg assets -prefix "_embed" \
|
||||||
|
-o assets/binary.go -ignore "^.*theme-([^g]|g[^i]|gi[^t]|git[^h]|gith[^u]|githu[^b]).*\.js$" \
|
||||||
|
_embed/templates/... _embed/public/js/... _embed/public/css/... _embed/public/ace/src-min/...
|
||||||
|
|
||||||
|
gitversion -s -o page/version.go -p page
|
||||||
|
git add -A
|
Loading…
Reference in New Issue