js cleaning
Former-commit-id: 9bcc591d7198b05a80208bf2f0ea886dbb0d20ef [formerly d839fcb715067f316de578009c491f5bc8bd4d26] [formerly 6d3d299a509857f18c40b2ac8216b670175cb982 [formerly 1fb4fab095
]]
Former-commit-id: fe8cfe5dcf92995224b4f8c6bf5552f56e25c790 [formerly b7f7f69d5c94b44cfa8acb00af9b4d7dab1eb42b]
Former-commit-id: 17de9bc37c2e5b1fb1d5d7fc07018242dd114e99
pull/726/head
parent
7200072cd8
commit
a2d66f44ea
|
@ -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'
|
||||
|
|
|
@ -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')
|
||||
}
|
||||
|
|
|
@ -83,13 +83,6 @@
|
|||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{- if .IsDir }}
|
||||
<div tabindex="0" role="button" aria-label="See raw" class="action" id="open">
|
||||
<i class="material-icons" title="See raw">open_in_new</i>
|
||||
<span>See raw</span>
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{- if and (.User.AllowEdit) (.IsDir) }}
|
||||
<div tabindex="0" role="button" aria-label="Move" class="action" id="move">
|
||||
<i class="material-icons" title="Move">forward</i>
|
||||
|
@ -139,13 +132,6 @@
|
|||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{- if not .IsDir }}
|
||||
<div tabindex="0" role="button" aria-label="See raw" class="action" id="open">
|
||||
<i class="material-icons" title="See raw">open_in_new</i>
|
||||
<span>See raw</span>
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
{{- if and .User.AllowEdit (not .IsDir) }}
|
||||
<div tabindex="0" role="button" aria-label="Delete" class="action" id="delete">
|
||||
<i class="material-icons" title="Delete">delete</i><span>Delete</span>
|
||||
|
|
Loading…
Reference in New Issue