Skip to content

Commit d7330a7

Browse files
committed
Increase old browser support and switch to es2015
1 parent d08a4bd commit d7330a7

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

s3file/static/s3file/js/s3file.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict';
22

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

1010
function addHiddenInput (body, name, form) {
11-
const key = parseURL(body)
12-
const input = document.createElement('input')
11+
var key = parseURL(body)
12+
var input = document.createElement('input')
1313
input.type = 'hidden'
1414
input.value = key
1515
input.name = name
@@ -18,7 +18,7 @@
1818

1919
function waitForAllFiles (form) {
2020
if (window.uploading !== 0) {
21-
setTimeout(() => {
21+
setTimeout(function () {
2222
waitForAllFiles(form)
2323
}, 100)
2424
} else {
@@ -27,29 +27,32 @@
2727
}
2828

2929
function request (method, url, data) {
30-
return new Promise((resolve, reject) => {
31-
const xhr = new window.XMLHttpRequest()
30+
return new Promise(function (resolve, reject) {
31+
var xhr = new window.XMLHttpRequest()
3232
xhr.open(method, url)
33-
xhr.onload = () => {
33+
34+
xhr.onload = function () {
3435
if (xhr.status === 201) {
3536
resolve(xhr.responseText)
3637
} else {
3738
reject(xhr.statusText)
3839
}
3940
}
40-
xhr.onerror = () => {
41+
42+
xhr.onerror = function () {
4143
reject(xhr.statusText)
4244
}
4345
xhr.send(data)
4446
})
4547
}
4648

4749
function uploadFiles (form, fileInput, name) {
48-
const url = fileInput.getAttribute('data-url')
49-
const promises = Array.from(fileInput.files).map((file) => {
50-
const s3Form = new window.FormData()
51-
Array.from(fileInput.attributes).forEach(attr => {
52-
let name = attr.name
50+
var url = fileInput.getAttribute('data-url')
51+
var promises = Array.from(fileInput.files).map(function (file) {
52+
var s3Form = new window.FormData()
53+
Array.from(fileInput.attributes).forEach(function (attr) {
54+
var name = attr.name
55+
5356
if (name.startsWith('data-fields')) {
5457
name = name.replace('data-fields-', '')
5558
s3Form.append(name, attr.value)
@@ -60,29 +63,28 @@
6063
s3Form.append('file', file)
6164
return request('POST', url, s3Form)
6265
})
63-
Promise.all(promises).then((results) => {
64-
results.forEach((result) => {
66+
Promise.all(promises).then(function (results) {
67+
results.forEach(function (result) {
6568
addHiddenInput(result, name, form)
6669
})
67-
68-
const input = document.createElement('input')
70+
var input = document.createElement('input')
6971
input.type = 'hidden'
7072
input.name = 's3file'
7173
input.value = fileInput.name
7274
fileInput.name = ''
7375
form.appendChild(input)
7476
window.uploading -= 1
75-
}, (err) => {
77+
}, function (err) {
7678
console.log(err)
7779
fileInput.setCustomValidity(err)
7880
fileInput.reportValidity()
7981
})
8082
}
8183

8284
function clickSubmit (e) {
83-
let submitButton = e.target
84-
let form = submitButton.closest('form')
85-
const submitInput = document.createElement('input')
85+
var submitButton = e.target
86+
var form = submitButton.closest('form')
87+
var submitInput = document.createElement('input')
8688
submitInput.type = 'hidden'
8789
submitInput.value = submitButton.value || '1'
8890
submitInput.name = submitButton.name
@@ -91,30 +93,28 @@
9193

9294
function uploadS3Inputs (form) {
9395
window.uploading = 0
94-
const inputs = form.querySelectorAll('.s3file')
95-
Array.from(inputs).forEach(input => {
96+
var inputs = form.querySelectorAll('.s3file')
97+
Array.from(inputs).forEach(function (input) {
9698
window.uploading += 1
9799
uploadFiles(form, input, input.name)
98-
}
99-
)
100+
})
100101
waitForAllFiles(form)
101102
}
102103

103-
document.addEventListener('DOMContentLoaded', () => {
104-
let forms = Array.from(document.querySelectorAll('.s3file')).map(input => {
104+
document.addEventListener('DOMContentLoaded', function () {
105+
var forms = Array.from(document.querySelectorAll('.s3file')).map(function (input) {
105106
return input.closest('form')
106107
})
107108
forms = new Set(forms)
108-
forms.forEach(form => {
109-
form.addEventListener('submit', (e) => {
109+
forms.forEach(function (form) {
110+
form.addEventListener('submit', function (e) {
110111
e.preventDefault()
111112
uploadS3Inputs(e.target)
112113
})
113-
let submitButtons = form.querySelectorAll('input[type=submit], button[type=submit]')
114-
Array.from(submitButtons).forEach(submitButton => {
114+
var submitButtons = form.querySelectorAll('input[type=submit], button[type=submit]')
115+
Array.from(submitButtons).forEach(function (submitButton) {
115116
submitButton.addEventListener('click', clickSubmit)
116-
}
117-
)
117+
})
118118
})
119119
})
120120
})()

0 commit comments

Comments
 (0)