diff --git a/_assets/js/editor.js b/_assets/js/editor.js index 38ff40c7..1bedebee 100644 --- a/_assets/js/editor.js +++ b/_assets/js/editor.js @@ -92,8 +92,8 @@ function addFrontMatterItemPrompt (parent) { closePrompt(event) - let name = value.substring(0, value.lastIndexOf(':')), - type = value.substring(value.lastIndexOf(':') + 1, value.length) + let name = value.substring(0, value.lastIndexOf(':')) + let type = value.substring(value.lastIndexOf(':') + 1, value.length) if (type !== '' && type !== 'array' && type !== 'object') { name = value @@ -131,19 +131,19 @@ function addFrontMatterItemPrompt (parent) { function addFrontMatterItem (event) { event.preventDefault() - let parent = event.currentTarget.parentNode, - type = parent.dataset.type + let parent = event.currentTarget.parentNode + let type = parent.dataset.type // If the block is an array if (type === 'array') { - let id = parent.id + '[]', - count = parent.querySelectorAll('.group > div').length, - fieldsets = parent.getElementsByTagName('fieldset') + let id = parent.id + '[]' + let count = parent.querySelectorAll('.group > div').length + let fieldsets = parent.getElementsByTagName('fieldset') if (fieldsets.length > 0) { - let itemType = fieldsets[0].dataset.type, - itemID = parent.id + '[' + fieldsets.length + ']', - itemName = fieldsets.length + let itemType = fieldsets[0].dataset.type + let itemID = parent.id + '[' + fieldsets.length + ']' + let itemName = fieldsets.length makeFromBaseTemplate(itemID, itemType, itemName, parent) } else { @@ -153,7 +153,7 @@ function addFrontMatterItem (event) { return } - if (type == 'object' || type == 'parent') { + if (type === 'object' || type === 'parent') { let clone = document.importNode(templates.question.content, true) clone.querySelector('form').id = tempID clone.querySelector('h3').innerHTML = 'New field' diff --git a/_assets/js/listing.js b/_assets/js/listing.js index baef101d..19906ba0 100644 --- a/_assets/js/listing.js +++ b/_assets/js/listing.js @@ -1,182 +1,175 @@ 'use strict' var listing = { - selectMultiple: false -} + selectMultiple: false, + reload: function (callback) { + let request = new window.XMLHttpRequest() -listing.reload = function (callback) { - let request = new XMLHttpRequest() + request.open('GET', window.location) + request.setRequestHeader('Minimal', 'true') + request.send() + request.onreadystatechange = function () { + if (request.readyState === 4) { + if (request.status === 200) { + document.querySelector('body main').innerHTML = request.responseText + listing.addDoubleTapEvent() - request.open('GET', window.location) - request.setRequestHeader('Minimal', 'true') - request.send() - request.onreadystatechange = function () { - if (request.readyState === 4) { - if (request.status === 200) { - document.querySelector('body main').innerHTML = request.responseText - listing.addDoubleTapEvent() - - if (typeof callback === 'function') { - callback() + if (typeof callback === 'function') { + callback() + } } } } - } -} + }, + itemDragStart: function (event) { + let el = event.target -listing.itemDragStart = function (event) { - let el = event.target - - for (let i = 0; i < 5; i++) { - if (!el.classList.contains('item')) { - el = el.parentElement - } - } - - event.dataTransfer.setData('id', el.id) - event.dataTransfer.setData('name', el.querySelector('.name').innerHTML) -} - -listing.itemDragOver = function (event) { - event.preventDefault() - let el = event.target - - for (let i = 0; i < 5; i++) { - if (!el.classList.contains('item')) { - el = el.parentElement - } - } - - el.style.opacity = 1 -} - -listing.itemDrop = function (e) { - e.preventDefault() - - let el = e.target, - id = e.dataTransfer.getData('id'), - name = e.dataTransfer.getData('name') - - if (id == '' || name == '') return - - for (let i = 0; i < 5; i++) { - if (!el.classList.contains('item')) { - el = el.parentElement - } - } - - if (el.id === id) return - - let oldLink = document.getElementById(id).dataset.url, - newLink = el.dataset.url + name - - webdav.move(oldLink, newLink) - .then(() => listing.reload()) - .catch(e => console.log(e)) -} - -listing.documentDrop = function (event) { - event.preventDefault() - let dt = event.dataTransfer, - files = dt.files, - el = event.target, - items = document.getElementsByClassName('item') - - for (let i = 0; i < 5; i++) { - if (el != null && !el.classList.contains('item')) { - el = el.parentElement - } - } - - if (files.length > 0) { - if (el != null && el.classList.contains('item') && el.dataset.dir == 'true') { - listing.handleFiles(files, el.querySelector('.name').innerHTML + '/') - return + for (let i = 0; i < 5; i++) { + if (!el.classList.contains('item')) { + el = el.parentElement + } } - listing.handleFiles(files, '') - } else { - Array.from(items).forEach(file => { - file.style.opacity = 1 - }) - } -} - -listing.rename = function (event) { - if (!selectedItems.length || selectedItems.length > 1) { - return false - } - - let item = document.getElementById(selectedItems[0]) - - if (item.classList.contains('disabled')) { - return false - } - - let link = item.dataset.url, - field = item.querySelector('.name'), - name = field.innerHTML - - let submit = (event) => { + event.dataTransfer.setData('id', el.id) + event.dataTransfer.setData('name', el.querySelector('.name').innerHTML) + }, + itemDragOver: function (event) { event.preventDefault() + let el = event.target - let newName = event.currentTarget.querySelector('input').value, - newLink = removeLastDirectoryPartOf(link) + '/' + newName + for (let i = 0; i < 5; i++) { + if (!el.classList.contains('item')) { + el = el.parentElement + } + } - closePrompt(event) - buttons.setLoading('rename') + el.style.opacity = 1 + }, + itemDrop: function (e) { + e.preventDefault() - webdav.move(link, newLink).then(() => { - listing.reload(() => { - newName = btoa(newName) - selectedItems = [newName] - document.getElementById(newName).setAttribute('aria-selected', true) - listing.handleSelectionChange() + let el = e.target, + id = e.dataTransfer.getData('id'), + name = e.dataTransfer.getData('name') + + if (id == '' || name == '') return + + for (let i = 0; i < 5; i++) { + if (!el.classList.contains('item')) { + el = el.parentElement + } + } + + if (el.id === id) return + + let oldLink = document.getElementById(id).dataset.url, + newLink = el.dataset.url + name + + webdav.move(oldLink, newLink) + .then(() => listing.reload()) + .catch(e => console.log(e)) + }, + documentDrop: function (event) { + event.preventDefault() + let dt = event.dataTransfer, + files = dt.files, + el = event.target, + items = document.getElementsByClassName('item') + + for (let i = 0; i < 5; i++) { + if (el != null && !el.classList.contains('item')) { + el = el.parentElement + } + } + + if (files.length > 0) { + if (el != null && el.classList.contains('item') && el.dataset.dir == 'true') { + listing.handleFiles(files, el.querySelector('.name').innerHTML + '/') + return + } + + listing.handleFiles(files, '') + } else { + Array.from(items).forEach(file => { + file.style.opacity = 1 + }) + } + }, + rename: function (event) { + if (!selectedItems.length || selectedItems.length > 1) { + return false + } + + let item = document.getElementById(selectedItems[0]) + + if (item.classList.contains('disabled')) { + return false + } + + let link = item.dataset.url + let field = item.querySelector('.name') + let name = field.innerHTML + + let submit = (event) => { + event.preventDefault() + + let newName = event.currentTarget.querySelector('input').value + let newLink = removeLastDirectoryPartOf(link) + '/' + newName + + closePrompt(event) + buttons.setLoading('rename') + + webdav.move(link, newLink).then(() => { + listing.reload(() => { + newName = btoa(newName) + selectedItems = [newName] + document.getElementById(newName).setAttribute('aria-selected', true) + listing.handleSelectionChange() + }) + + buttons.setDone('rename') + }).catch(error => { + field.innerHTML = name + buttons.setDone('rename', false) + console.log(error) }) - buttons.setDone('rename') - }).catch(error => { - field.innerHTML = name - buttons.setDone('rename', false) - console.log(error) - }) + return false + } + + let clone = document.importNode(templates.question.content, true) + clone.querySelector('h3').innerHTML = 'Rename' + clone.querySelector('input').value = name + clone.querySelector('.ok').innerHTML = 'Rename' + clone.querySelector('form').addEventListener('submit', submit) + + document.querySelector('body').appendChild(clone) + document.querySelector('.overlay').classList.add('active') + document.querySelector('.prompt').classList.add('active') + + return false + }, + handleFiles: function (files, base) { + buttons.setLoading('upload') + + let promises = [] + + for (let file of files) { + promises.push(webdav.put(window.location.pathname + base + file.name, file)) + } + + Promise.all(promises) + .then(() => { + listing.reload() + buttons.setDone('upload') + }) + .catch(e => { + console.log(e) + buttons.setDone('upload', false) + }) return false } - - let clone = document.importNode(templates.question.content, true) - clone.querySelector('h3').innerHTML = 'Rename' - clone.querySelector('input').value = name - clone.querySelector('.ok').innerHTML = 'Rename' - clone.querySelector('form').addEventListener('submit', submit) - - document.querySelector('body').appendChild(clone) - document.querySelector('.overlay').classList.add('active') - document.querySelector('.prompt').classList.add('active') - - return false -} - -listing.handleFiles = function (files, base) { - buttons.setLoading('upload') - - let promises = [] - - for (let file of files) { - promises.push(webdav.put(window.location.pathname + base + file.name, file)) - } - - Promise.all(promises) - .then(() => { - listing.reload() - buttons.setDone('upload') - }) - .catch(e => { - console.log(e) - buttons.setDone('upload', false) - }) - - return false } listing.unselectAll = function () { @@ -201,18 +194,11 @@ listing.handleSelectionChange = function (event) { fileAction.classList.remove('disabled') if (selectedNumber > 1) { - buttons.open.classList.add('disabled') buttons.rename.classList.add('disabled') buttons.info.classList.add('disabled') } if (selectedNumber == 1) { - if (document.getElementById(selectedItems[0]).dataset.dir == 'true') { - buttons.open.classList.add('disabled') - } else { - buttons.open.classList.remove('disabled') - } - buttons.info.classList.remove('disabled') buttons.rename.classList.remove('disabled') } diff --git a/_assets/templates/base.tmpl b/_assets/templates/base.tmpl index e56cbae6..daa9ef0d 100644 --- a/_assets/templates/base.tmpl +++ b/_assets/templates/base.tmpl @@ -83,13 +83,6 @@ {{- end }} - {{- if .IsDir }} -
- open_in_new - See raw -
- {{- end }} - {{- if and (.User.AllowEdit) (.IsDir) }}
forward @@ -139,13 +132,6 @@
{{- end }} - {{- if not .IsDir }} -
- open_in_new - See raw -
- {{- end }} - {{- if and .User.AllowEdit (not .IsDir) }}
deleteDelete