Skip to content

Commit 9d41028

Browse files
committed
Refactor -- run standard --fix to pass lint check
1 parent c1bfe96 commit 9d41028

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

s3file/static/s3file/js/s3file.js

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
(function () {
44
function parseURL (text) {
5-
var xml = new window.DOMParser().parseFromString(text, 'text/xml')
6-
var tag = xml.getElementsByTagName('Key')[0]
5+
const xml = new window.DOMParser().parseFromString(text, 'text/xml')
6+
const tag = xml.getElementsByTagName('Key')[0]
77
return decodeURI(tag.childNodes[0].nodeValue)
88
}
99

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

2525
xhr.onload = function () {
2626
if (xhr.status === 201) {
@@ -31,11 +31,11 @@
3131
}
3232

3333
xhr.upload.onprogress = function (e) {
34-
var diff = e.loaded - file.loaded
34+
const diff = e.loaded - file.loaded
3535
form.loaded += diff
3636
fileInput.loaded += diff
3737
file.loaded = e.loaded
38-
var defaultEventData = {
38+
const defaultEventData = {
3939
currentFile: file,
4040
currentFileName: file.name,
4141
currentFileProgress: Math.min(e.loaded / e.total, 1),
@@ -67,15 +67,15 @@
6767
}
6868

6969
function uploadFiles (form, fileInput, name) {
70-
var url = fileInput.getAttribute('data-url')
70+
const url = fileInput.getAttribute('data-url')
7171
fileInput.loaded = 0
7272
fileInput.total = 0
73-
var promises = Array.from(fileInput.files).map(function (file) {
73+
const promises = Array.from(fileInput.files).map(function (file) {
7474
form.total += file.size
7575
fileInput.total += file.size
76-
var s3Form = new window.FormData()
76+
const s3Form = new window.FormData()
7777
Array.from(fileInput.attributes).forEach(function (attr) {
78-
var name = attr.name
78+
let name = attr.name
7979

8080
if (name.startsWith('data-fields')) {
8181
name = name.replace('data-fields-', '')
@@ -89,7 +89,7 @@
8989
})
9090
Promise.all(promises).then(function (results) {
9191
results.forEach(function (result) {
92-
var hiddenFileInput = document.createElement('input')
92+
const hiddenFileInput = document.createElement('input')
9393
hiddenFileInput.type = 'hidden'
9494
hiddenFileInput.name = name
9595
hiddenFileInput.value = parseURL(result)
@@ -105,24 +105,23 @@
105105
}
106106

107107
function uploadS3Inputs (event) {
108-
109108
event.preventDefault()
110109

111-
var form = event.target
112-
var submitter = event.submitter
110+
const form = event.target
111+
const submitter = event.submitter
113112

114113
window.uploading = 0
115114
form.loaded = 0
116115
form.total = 0
117-
var inputs = Array.from(form.querySelectorAll('input[type=file].s3file'))
116+
const inputs = Array.from(form.querySelectorAll('input[type=file].s3file'))
118117

119118
inputs.forEach(function (input) {
120-
var hiddenS3Input = document.createElement('input')
119+
const hiddenS3Input = document.createElement('input')
121120
hiddenS3Input.type = 'hidden'
122121
hiddenS3Input.name = 's3file'
123122
hiddenS3Input.value = input.name
124123
form.appendChild(hiddenS3Input)
125-
var hiddenSignatureInput = document.createElement('input')
124+
const hiddenSignatureInput = document.createElement('input')
126125
hiddenSignatureInput.type = 'hidden'
127126
hiddenSignatureInput.name = input.name + '-s3f-signature'
128127
hiddenSignatureInput.value = input.dataset.s3fSignature
@@ -134,25 +133,25 @@
134133
})
135134

136135
if (submitter) {
137-
// override form attributes with submit button attributes
138-
form.action = submitter.getAttribute('formaction') || form.action
139-
form.method = submitter.getAttribute('formmethod') || form.method
140-
form.enctype = submitter.getAttribute('formEnctype') || form.enctype
141-
form.novalidate = submitter.getAttribute('formnovalidate') || form.novalidate
142-
form.target = submitter.getAttribute('formtarget') || form.target
143-
// add submit button value to form
144-
var submitInput = document.createElement('input')
145-
submitInput.type = 'hidden'
146-
submitInput.value = submitter.value || '1'
147-
submitInput.name = submitter.name
148-
form.appendChild(submitInput)
136+
// override form attributes with submit button attributes
137+
form.action = submitter.getAttribute('formaction') || form.action
138+
form.method = submitter.getAttribute('formmethod') || form.method
139+
form.enctype = submitter.getAttribute('formEnctype') || form.enctype
140+
form.novalidate = submitter.getAttribute('formnovalidate') || form.novalidate
141+
form.target = submitter.getAttribute('formtarget') || form.target
142+
// add submit button value to form
143+
const submitInput = document.createElement('input')
144+
submitInput.type = 'hidden'
145+
submitInput.value = submitter.value || '1'
146+
submitInput.name = submitter.name
147+
form.appendChild(submitInput)
149148
}
150149

151150
waitForAllFiles(form)
152151
}
153152

154153
document.addEventListener('DOMContentLoaded', function () {
155-
var forms = Array.from(document.querySelectorAll('input[type=file].s3file')).map(function (input) {
154+
let forms = Array.from(document.querySelectorAll('input[type=file].s3file')).map(function (input) {
156155
return input.closest('form')
157156
})
158157
forms = new Set(forms)

0 commit comments

Comments
 (0)