27 lines
727 B
JavaScript
27 lines
727 B
JavaScript
const Sortable = require('sortablejs').Sortable
|
|
|
|
class FilesCollectionSorter {
|
|
constructor () {
|
|
const collections = document.querySelectorAll('div[data-collection^="collection-files"]')
|
|
|
|
for (const collection of collections) {
|
|
return new Sortable(collection, {
|
|
handle: '*[data-collection-item]',
|
|
sort: true,
|
|
animation: 150,
|
|
fallbackTolerance: 3,
|
|
onEnd: (e) => {
|
|
const positions = collection.querySelectorAll('*[data-collection-item] input[type=hidden]')
|
|
console.log(positions)
|
|
|
|
for (let u = 0; u < positions.length; u++) {
|
|
positions[u].value = u
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = FilesCollectionSorter
|