Skip to content

Commit

Permalink
Refactor -- run standard --fix to pass lint check
Browse files Browse the repository at this point in the history
  • Loading branch information
gary02 committed Oct 20, 2024
1 parent c1bfe96 commit 9d41028
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions s3file/static/s3file/js/s3file.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

(function () {
function parseURL (text) {
var xml = new window.DOMParser().parseFromString(text, 'text/xml')
var tag = xml.getElementsByTagName('Key')[0]
const xml = new window.DOMParser().parseFromString(text, 'text/xml')
const tag = xml.getElementsByTagName('Key')[0]
return decodeURI(tag.childNodes[0].nodeValue)
}

Expand All @@ -20,7 +20,7 @@
function request (method, url, data, fileInput, file, form) {
file.loaded = 0
return new Promise(function (resolve, reject) {
var xhr = new window.XMLHttpRequest()
const xhr = new window.XMLHttpRequest()

xhr.onload = function () {
if (xhr.status === 201) {
Expand All @@ -31,11 +31,11 @@
}

xhr.upload.onprogress = function (e) {
var diff = e.loaded - file.loaded
const diff = e.loaded - file.loaded
form.loaded += diff
fileInput.loaded += diff
file.loaded = e.loaded
var defaultEventData = {
const defaultEventData = {
currentFile: file,
currentFileName: file.name,
currentFileProgress: Math.min(e.loaded / e.total, 1),
Expand Down Expand Up @@ -67,15 +67,15 @@
}

function uploadFiles (form, fileInput, name) {
var url = fileInput.getAttribute('data-url')
const url = fileInput.getAttribute('data-url')
fileInput.loaded = 0
fileInput.total = 0
var promises = Array.from(fileInput.files).map(function (file) {
const promises = Array.from(fileInput.files).map(function (file) {
form.total += file.size
fileInput.total += file.size
var s3Form = new window.FormData()
const s3Form = new window.FormData()
Array.from(fileInput.attributes).forEach(function (attr) {
var name = attr.name
let name = attr.name

if (name.startsWith('data-fields')) {
name = name.replace('data-fields-', '')
Expand All @@ -89,7 +89,7 @@
})
Promise.all(promises).then(function (results) {
results.forEach(function (result) {
var hiddenFileInput = document.createElement('input')
const hiddenFileInput = document.createElement('input')
hiddenFileInput.type = 'hidden'
hiddenFileInput.name = name
hiddenFileInput.value = parseURL(result)
Expand All @@ -105,24 +105,23 @@
}

function uploadS3Inputs (event) {

event.preventDefault()

var form = event.target
var submitter = event.submitter
const form = event.target
const submitter = event.submitter

window.uploading = 0
form.loaded = 0
form.total = 0
var inputs = Array.from(form.querySelectorAll('input[type=file].s3file'))
const inputs = Array.from(form.querySelectorAll('input[type=file].s3file'))

inputs.forEach(function (input) {
var hiddenS3Input = document.createElement('input')
const hiddenS3Input = document.createElement('input')
hiddenS3Input.type = 'hidden'
hiddenS3Input.name = 's3file'
hiddenS3Input.value = input.name
form.appendChild(hiddenS3Input)
var hiddenSignatureInput = document.createElement('input')
const hiddenSignatureInput = document.createElement('input')
hiddenSignatureInput.type = 'hidden'
hiddenSignatureInput.name = input.name + '-s3f-signature'
hiddenSignatureInput.value = input.dataset.s3fSignature
Expand All @@ -134,25 +133,25 @@
})

if (submitter) {
// override form attributes with submit button attributes
form.action = submitter.getAttribute('formaction') || form.action
form.method = submitter.getAttribute('formmethod') || form.method
form.enctype = submitter.getAttribute('formEnctype') || form.enctype
form.novalidate = submitter.getAttribute('formnovalidate') || form.novalidate
form.target = submitter.getAttribute('formtarget') || form.target
// add submit button value to form
var submitInput = document.createElement('input')
submitInput.type = 'hidden'
submitInput.value = submitter.value || '1'
submitInput.name = submitter.name
form.appendChild(submitInput)
// override form attributes with submit button attributes
form.action = submitter.getAttribute('formaction') || form.action
form.method = submitter.getAttribute('formmethod') || form.method
form.enctype = submitter.getAttribute('formEnctype') || form.enctype
form.novalidate = submitter.getAttribute('formnovalidate') || form.novalidate
form.target = submitter.getAttribute('formtarget') || form.target
// add submit button value to form
const submitInput = document.createElement('input')
submitInput.type = 'hidden'
submitInput.value = submitter.value || '1'
submitInput.name = submitter.name
form.appendChild(submitInput)
}

waitForAllFiles(form)
}

document.addEventListener('DOMContentLoaded', function () {
var forms = Array.from(document.querySelectorAll('input[type=file].s3file')).map(function (input) {
let forms = Array.from(document.querySelectorAll('input[type=file].s3file')).map(function (input) {
return input.closest('form')
})
forms = new Set(forms)
Expand Down

0 comments on commit 9d41028

Please sign in to comment.