Skip to content

Commit 10c44fc

Browse files
committed
Refactor -- gather form mutation code together
1 parent 998c334 commit 10c44fc

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

s3file/static/s3file/js/s3file.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,6 @@
104104
})
105105
}
106106

107-
function clickSubmit (e) {
108-
var submitButton = e.currentTarget
109-
var form = submitButton.closest('form')
110-
var submitInput = document.createElement('input')
111-
submitInput.type = 'hidden'
112-
submitInput.value = submitButton.value || '1'
113-
submitInput.name = submitButton.name
114-
form.appendChild(submitInput)
115-
}
116-
117107
function uploadS3Inputs (form, submitter) {
118108
window.uploading = 0
119109
form.loaded = 0
@@ -136,13 +126,20 @@
136126
window.uploading += 1
137127
uploadFiles(form, input, input.name)
138128
})
139-
// override form attributes with submit button attributes
129+
140130
if (submitter) {
131+
// override form attributes with submit button attributes
141132
form.action = submitter.getAttribute('formaction') || form.action
142133
form.method = submitter.getAttribute('formmethod') || form.method
143134
form.enctype = submitter.getAttribute('formEnctype') || form.enctype
144135
form.formnovalidate = submitter.getAttribute('formnovalidate') || form.novalidate
145136
form.target = submitter.getAttribute('formtarget') || form.target
137+
// add submit button value to form
138+
var submitInput = document.createElement('input')
139+
submitInput.type = 'hidden'
140+
submitInput.value = submitter.value || '1'
141+
submitInput.name = submitter.name
142+
form.appendChild(submitInput)
146143
}
147144

148145
waitForAllFiles(form)
@@ -158,10 +155,6 @@
158155
e.preventDefault()
159156
uploadS3Inputs(e.target, e.submitter)
160157
})
161-
var submitButtons = form.querySelectorAll('input[type=submit], button[type=submit]')
162-
Array.from(submitButtons).forEach(function (submitButton) {
163-
submitButton.addEventListener('click', clickSubmit)
164-
})
165158
})
166159
})
167160
})()

0 commit comments

Comments
 (0)