identation and stuff

This commit is contained in:
Henrique Dias 2017-01-03 17:35:13 +00:00
parent f4cad45f04
commit c706998a5a
11 changed files with 1515 additions and 1539 deletions

22
.jsbeautifyrc Normal file
View File

@ -0,0 +1,22 @@
{
"html": {
"brace_style": "collapse",
"indent_scripts": "normal",
"max_preserve_newlines": 1,
"preserve_newlines": true,
"unformatted": ["a", "sub", "sup", "b", "i", "u"],
"wrap_line_length": 0
},
"css": {
"end_with_newline": false,
"newline_between_rules": true,
"selector_separator": " ",
"selector_separator_newline": true
},
"js": {
"indent_with_tabs": false,
"preserve_newlines": true,
"max_preserve_newlines": 2,
"jslint_happy": true
}
}

View File

@ -1,11 +0,0 @@
{
"css": {
"allowed_file_extensions": ["css", "scss", "sass", "less"],
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_size": 4, // Indentation size
"newline_between_rules": true, // Add a new line after every css rule
"selector_separator": " ",
"selector_separator_newline": true // Separate selectors with newline or not (e.g. "a,\nbr" or "a, br")
}
}

View File

@ -1021,6 +1021,7 @@ header .actions {
background-color: #e9eaeb; background-color: #e9eaeb;
} }
/* * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * *
* PROMPT - MOVE * * PROMPT - MOVE *
* * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * */

View File

@ -4,19 +4,22 @@ var tempID = "_fm_internal_temporary_id",
buttons = {}, buttons = {},
templates = {}, templates = {},
selectedItems = [], selectedItems = [],
overlay, clickOverlay, overlay,
clickOverlay,
webdav = {}; webdav = {};
// 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) this.splice(i, 1); if(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) this[i] = newElement; if(i != -1)
this[i] = newElement;
} }
// Sends a costum event to itself // Sends a costum event to itself
@ -54,7 +57,8 @@ Element.prototype.changeToDone = function (error, html) {
this.innerHTML = html; this.innerHTML = html;
this.style.opacity = null; this.style.opacity = null;
if (selectedItems.length == 0 && document.getElementById('listing')) document.sendCostumEvent('changed-selected'); if(selectedItems.length == 0 && document.getElementById('listing'))
document.sendCostumEvent('changed-selected');
} }
let secondStep = () => { let secondStep = () => {
@ -64,7 +68,9 @@ Element.prototype.changeToDone = function (error, html) {
let firstStep = () => { let firstStep = () => {
this.classList.remove('spin'); this.classList.remove('spin');
this.innerHTML = error ? 'close' : 'done'; this.innerHTML = error ?
'close' :
'done';
this.style.opacity = 1; this.style.opacity = 1;
setTimeout(secondStep, 1000); setTimeout(secondStep, 1000);
} }
@ -80,14 +86,14 @@ function toWebDavURL(url) {
// 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();
} }
@ -98,9 +104,10 @@ function getCSSRule(rules) {
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]) found = true; if(cssRule.selectorText.toLowerCase() == rules[i])
found = true;
} }
} }
@ -127,7 +134,7 @@ webdav.move = function (oldLink, newLink) {
request.open('MOVE', toWebDavURL(oldLink), true); request.open('MOVE', toWebDavURL(oldLink), true);
request.setRequestHeader('Destination', toWebDavURL(newLink)); request.setRequestHeader('Destination', toWebDavURL(newLink));
request.onload = () => { request.onload = () => {
if (request.status == 201 || request.status == 204) { if(request.status == 201 || request.status == 204) {
resolve(request.response); resolve(request.response);
} else { } else {
reject(request.statusText); reject(request.statusText);
@ -143,7 +150,7 @@ webdav.put = function (link, body) {
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
request.open('PUT', toWebDavURL(link), true); request.open('PUT', toWebDavURL(link), true);
request.onload = () => { request.onload = () => {
if (request.status == 201) { if(request.status == 201) {
resolve(request.response); resolve(request.response);
} else { } else {
reject(request.statusText); reject(request.statusText);
@ -162,7 +169,8 @@ webdav.put = function (link, body) {
function closePrompt(event) { function closePrompt(event) {
let prompt = document.querySelector('.prompt'); let prompt = document.querySelector('.prompt');
if (!prompt) return; if(!prompt)
return;
event.preventDefault(); event.preventDefault();
document.querySelector('.overlay').classList.remove('active'); document.querySelector('.overlay').classList.remove('active');
@ -196,18 +204,19 @@ function logoutEvent(event) {
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')) return false; if(event.currentTarget.classList.contains('disabled'))
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 + link; link = window.location + link;
@ -218,11 +227,11 @@ function openEvent(event) {
} }
function selectMoveFolder(event) { function selectMoveFolder(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);
@ -240,14 +249,14 @@ function loadNextFolder(event) {
request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Accept", "application/json");
request.send(); request.send();
request.onreadystatechange = function () { request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) { if(request.readyState == 4 && request.status == 200) {
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;
for (let f of JSON.parse(request.response)) { for(let f of JSON.parse(request.response)) {
if (f.IsDir === true) { if(f.IsDir === true) {
dirs++; dirs++;
let newNode = document.createElement("li"); let newNode = document.createElement("li");
@ -262,7 +271,7 @@ function loadNextFolder(event) {
} }
} }
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.`;
} }
} }
@ -283,8 +292,8 @@ function moveSelected(event) {
request.setRequestHeader("Destination", newLink); request.setRequestHeader("Destination", newLink);
request.send(); request.send();
request.onreadystatechange = function () { request.onreadystatechange = function () {
if (request.readyState == 4) { if(request.readyState == 4) {
if (request.status == 200 || request.status == 204) { if(request.status == 200 || request.status == 204) {
window.reload(); window.reload();
} }
} }
@ -292,23 +301,24 @@ function moveSelected(event) {
} }
function moveEvent(event) { function moveEvent(event) {
if (event.currentTarget.classList.contains("disabled")) return; if(event.currentTarget.classList.contains("disabled"))
return;
let request = new XMLHttpRequest(); let request = new XMLHttpRequest();
request.open("GET", window.location.pathname, true); request.open("GET", window.location.pathname, true);
request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Accept", "application/json");
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) {
let prompt = document.importNode(templates.move.content, true), let prompt = document.importNode(templates.move.content, true),
dirs = 0; dirs = 0;
prompt.querySelector("form").addEventListener("submit", moveSelected); prompt.querySelector("form").addEventListener("submit", moveSelected);
prompt.querySelector('code').innerHTML = window.location.pathname; prompt.querySelector('code').innerHTML = window.location.pathname;
for (let f of JSON.parse(request.response)) { for(let f of JSON.parse(request.response)) {
if (f.IsDir === true) { if(f.IsDir === true) {
dirs++; dirs++;
let newNode = document.createElement("li"); let newNode = document.createElement("li");
@ -323,7 +333,7 @@ function moveEvent(event) {
} }
} }
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.`;
} }
@ -342,9 +352,10 @@ function deleteSelected(single) {
Array.from(selectedItems).forEach(id => { Array.from(selectedItems).forEach(id => {
let request = new XMLHttpRequest(), let request = new XMLHttpRequest(),
html = buttons.delete.querySelector('i').changeToLoading(), html = buttons.delete.querySelector('i').changeToLoading(),
el, url; el,
url;
if (single) { if(single) {
url = window.location.pathname; url = window.location.pathname;
} else { } else {
el = document.getElementById(id); el = document.getElementById(id);
@ -353,9 +364,9 @@ function deleteSelected(single) {
request.open('DELETE', toWebDavURL(url)); request.open('DELETE', toWebDavURL(url));
request.onreadystatechange = function () { request.onreadystatechange = function () {
if (request.readyState == 4) { if(request.readyState == 4) {
if (request.status == 204) { if(request.status == 204) {
if (single) { if(single) {
window.location.pathname = removeLastDirectoryPartOf(window.location.pathname); window.location.pathname = removeLastDirectoryPartOf(window.location.pathname);
} else { } else {
el.remove(); el.remove();
@ -378,7 +389,7 @@ function deleteSelected(single) {
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;
} }
@ -386,7 +397,7 @@ function deleteEvent(event) {
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('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('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)?`;
@ -406,7 +417,7 @@ function deleteEvent(event) {
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.";
@ -414,7 +425,7 @@ function resetSearchText() {
} }
function searchEvent(event) { function searchEvent(event) {
if (this.value.length == 0) { if(this.value.length == 0) {
resetSearchText(); resetSearchText();
return; return;
} }
@ -427,28 +438,28 @@ function searchEvent(event) {
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);
} }
if (supported && user.AllowCommands) { if(supported && user.AllowCommands) {
let conn = new WebSocket(`ws://${url}?command=true`); let conn = new WebSocket(`ws://${url}?command=true`);
conn.onopen = function () { conn.onopen = function () {
@ -509,13 +520,15 @@ function setupSearch() {
searchInput.addEventListener('blur', event => { searchInput.addEventListener('blur', event => {
focus = false; focus = false;
if (hover) return; if(hover)
return;
search.classList.remove('active'); search.classList.remove('active');
}); });
search.addEventListener('mouseleave', event => { search.addEventListener('mouseleave', event => {
hover = false; hover = false;
if (focus) return; if(focus)
return;
search.classList.remove('active'); search.classList.remove('active');
}); });
@ -542,17 +555,17 @@ function openHelp(event) {
} }
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);
} }
@ -583,7 +596,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
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);
} }
@ -601,7 +614,7 @@ document.addEventListener("DOMContentLoaded", function (event) {
}); });
overlay.addEventListener('click', event => { overlay.addEventListener('click', event => {
if (document.querySelector('.help.active')) { if(document.querySelector('.help.active')) {
closeHelp(event); closeHelp(event);
return; return;
} }

View File

@ -2,8 +2,8 @@
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';
@ -36,7 +36,7 @@ function makeFromBaseTemplate(id, type, name, parent) {
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
} }
@ -71,11 +71,11 @@ function makeFromObjectItemTemplate(id, name, parent) {
} }
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;
} }
@ -84,7 +84,7 @@ function addFrontMatterItemPrompt(parent) {
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;
} }
@ -92,12 +92,12 @@ function addFrontMatterItemPrompt(parent) {
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;
} }
@ -108,7 +108,7 @@ function addFrontMatterItemPrompt(parent) {
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');
} }
@ -124,12 +124,12 @@ function addFrontMatterItem(event) {
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;
@ -142,7 +142,7 @@ function addFrontMatterItem(event) {
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';
@ -160,7 +160,7 @@ function addFrontMatterItem(event) {
} }
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");
@ -172,7 +172,7 @@ document.addEventListener("DOMContentLoaded", (event) => {
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"]'),
@ -188,11 +188,11 @@ document.addEventListener("DOMContentLoaded", (event) => {
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);
} }
@ -206,14 +206,14 @@ document.addEventListener("DOMContentLoaded", (event) => {
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();
} }
@ -223,8 +223,8 @@ document.addEventListener("DOMContentLoaded", (event) => {
request.open("PUT", toWebDavURL(window.location.pathname)); request.open("PUT", toWebDavURL(window.location.pathname));
request.setRequestHeader('Kind', kind); request.setRequestHeader('Kind', kind);
request.send(JSON.stringify(data)); request.send(JSON.stringify(data));
request.onreadystatechange = function() { request.onreadystatechange = function () {
if (request.readyState == 4) { if(request.readyState == 4) {
buttons.save.querySelector('i').changeToDone((request.status != 201), html); buttons.save.querySelector('i').changeToDone((request.status != 201), html);
} }
} }
@ -241,8 +241,8 @@ document.addEventListener("DOMContentLoaded", (event) => {
}); });
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();

View File

@ -4,19 +4,19 @@ 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();
} }
} }
@ -24,11 +24,11 @@ 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;
} }
} }
@ -37,12 +37,12 @@ listing.itemDragStart = function(event) {
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;
} }
} }
@ -50,22 +50,22 @@ listing.itemDragOver = function(event) {
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;
@ -75,21 +75,21 @@ listing.itemDrop = function(e) {
.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;
} }
@ -102,14 +102,14 @@ listing.documentDrop = function(event) {
} }
} }
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;
} }
@ -157,11 +157,11 @@ listing.rename = function(event) {
return false; return false;
} }
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));
} }
@ -178,7 +178,7 @@ listing.handleFiles = function(files, base) {
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);
@ -190,22 +190,22 @@ listing.unselectAll = function() {
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");
@ -221,10 +221,10 @@ listing.handleSelectionChange = function(event) {
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, "") + ",";
} }
@ -238,16 +238,16 @@ listing.redefineDownloadURLs = function() {
}); });
} }
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);
@ -260,7 +260,7 @@ listing.selectItem = function(event) {
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);
@ -274,7 +274,7 @@ listing.newFileButton = function(event) {
document.querySelector('.prompt').classList.add('active'); document.querySelector('.prompt').classList.add('active');
} }
listing.newFilePrompt = function(event) { listing.newFilePrompt = function (event) {
event.preventDefault(); event.preventDefault();
let button = document.getElementById('new'), let button = document.getElementById('new'),
@ -284,8 +284,8 @@ listing.newFilePrompt = function(event) {
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();
request.onreadystatechange = function() { request.onreadystatechange = function () {
if (request.readyState == 4) { if(request.readyState == 4) {
button.querySelector('i').changeToDone((request.status != 201), html); button.querySelector('i').changeToDone((request.status != 201), html);
listing.reload(); listing.reload();
} }
@ -295,14 +295,14 @@ listing.newFilePrompt = function(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 () {
let items = document.getElementsByClassName('item'), let items = document.getElementsByClassName('item'),
touches = { touches = {
id: '', id: '',
@ -311,7 +311,7 @@ listing.addDoubleTapEvent = function() {
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;
@ -324,7 +324,7 @@ listing.addDoubleTapEvent = function() {
touches.count++; touches.count++;
if (touches.count > 1) { if(touches.count > 1) {
window.location = file.dataset.url; window.location = file.dataset.url;
} }
}); });
@ -333,21 +333,21 @@ listing.addDoubleTapEvent = function() {
// 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) {
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"
@ -383,13 +383,13 @@ document.addEventListener('DOMContentLoaded', event => {
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();
}); });
@ -397,7 +397,7 @@ document.addEventListener('DOMContentLoaded', event => {
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);
@ -416,5 +416,4 @@ document.addEventListener('DOMContentLoaded', event => {
document.addEventListener("drop", listing.documentDrop, false); document.addEventListener("drop", listing.documentDrop, false);
} }
}); });

View File

@ -1,32 +0,0 @@
{
"js": {
"allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"],
// Set brace_style
// collapse: (old default) Put braces on the same line as control statements
// collapse-preserve-inline: (new default) Same as collapse but better support for ES6 destructuring and other features. https://github.com/victorporof/Sublime-HTMLPrettify/issues/231
// expand: Put braces on own line (Allman / ANSI style)
// end-expand: Put end braces on own line
// none: Keep them where they are
"brace_style": "collapse-preserve-inline",
"break_chained_methods": false, // Break chained method calls across subsequent lines
"e4x": false, // Pass E4X xml literals through untouched
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_level": 0, // Initial indentation level
"indent_size": 2, // Indentation size
"indent_with_tabs": false, // Indent with tabs, overrides `indent_size` and `indent_char`
"jslint_happy": false, // If true, then jslint-stricter mode is enforced
"keep_array_indentation": false, // Preserve array indentation
"keep_function_indentation": false, // Preserve function indentation
"max_preserve_newlines": 0, // Maximum number of line breaks to be preserved in one chunk (0 disables)
"preserve_newlines": true, // Whether existing line breaks should be preserved
"space_after_anon_function": false, // Should the space before an anonymous function's parens be added, "function()" vs "function ()"
"space_before_conditional": true, // Should the space before conditional statement be added, "if(true)" vs "if (true)"
"space_in_empty_paren": false, // Add padding spaces within empty paren, "f()" vs "f( )"
"space_in_paren": false, // Add padding spaces within paren, ie. f( a, b )
"unescape_strings": false, // Should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
"wrap_line_length": 0 // Lines should wrap at next opportunity after this number of characters (0 disables)
}
}

View File

@ -1,16 +0,0 @@
{
"html": {
"allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg"],
"brace_style": "collapse", // [collapse|expand|end-expand|none] Put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line, or attempt to keep them where they are
"end_with_newline": false, // End output with newline
"indent_char": " ", // Indentation character
"indent_handlebars": false, // e.g. {{#foo}}, {{/foo}}
"indent_inner_html": false, // Indent <head> and <body> sections
"indent_scripts": "keep", // [keep|separate|normal]
"indent_size": 4, // Indentation size
"max_preserve_newlines": 0, // Maximum number of line breaks to be preserved in one chunk (0 disables)
"preserve_newlines": true, // Whether existing line breaks before elements should be preserved (only works before elements, not inside tags or for text)
"unformatted": ["a", "span", "img", "code", "pre", "sub", "sup", "em", "strong", "b", "i", "u", "strike", "big", "small", "pre", "h1", "h2", "h3", "h4", "h5", "h6"], // List of tags that should not be reformatted
"wrap_line_length": 0 // Lines should wrap at next opportunity after this number of characters (0 disables)
}
}