|
147 | 147 | } |
148 | 148 |
|
149 | 149 | /* eslint consistent-this: ["error", "$form"] */ |
150 | | - let url; |
151 | 150 | const $form = this; |
152 | 151 |
|
153 | 152 | if (typeof options === 'function') { |
|
171 | 170 | const method = options.method || options.type || this.attr2('method'); |
172 | 171 | const action = options.url || this.attr2('action'); |
173 | 172 |
|
174 | | - url = typeof action === 'string' ? $.trim(action) : ''; |
| 173 | + let url = typeof action === 'string' ? $.trim(action) : ''; |
| 174 | + |
175 | 175 | url = url || window.location.href || ''; |
176 | 176 | if (url) { |
177 | 177 | // clean url (don't include hash vaue) |
|
208 | 208 | return this; |
209 | 209 | } |
210 | 210 |
|
211 | | - let traditional = options.traditional; |
212 | | - |
213 | | - if (typeof traditional === 'undefined') { |
214 | | - traditional = $.ajaxSettings.traditional; |
215 | | - } |
| 211 | + const { |
| 212 | + traditional = $.ajaxSettings.traditional |
| 213 | + } = options; |
216 | 214 |
|
217 | 215 | const elements = []; |
218 | | - let qx; |
219 | 216 | const arr = this.formToArray(options.semantic, elements, options.filtering); |
220 | 217 |
|
| 218 | + let qx; |
| 219 | + |
221 | 220 | if (options.data) { |
222 | 221 | const optionsData = $.isFunction(options.data) ? options.data(arr) : options.data; |
223 | 222 |
|
|
291 | 290 | options.success = function(dta, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg |
292 | 291 | const context = options.context || this; // jQuery 1.4+ supports scope context |
293 | 292 |
|
294 | | - for (let i = 0, max = callbacks.length; i < max; i++) { |
295 | | - callbacks[i].apply(context, [dta, status, xhr || $form, $form]); |
| 293 | + for (const callback of callbacks) { |
| 294 | + callback.apply(context, [dta, status, xhr || $form, $form]); |
296 | 295 | } |
297 | 296 | }; |
298 | 297 |
|
|
368 | 367 | // utility fn for deep serialization |
369 | 368 | function deepSerialize(extraData) { |
370 | 369 | const serialized = $.param(extraData, options.traditional).split('&'); |
371 | | - const len = serialized.length; |
372 | 370 | const result = []; |
373 | | - let i, part; |
374 | 371 |
|
375 | | - for (i = 0; i < len; i++) { |
| 372 | + for (const ser of serialized) { |
376 | 373 | // #252; undo param space replacement |
377 | | - serialized[i] = serialized[i].replace(/\+/g, ' '); |
378 | | - part = serialized[i].split('='); |
| 374 | + const part = ser.replace(/\+/g, ' ').split('='); |
| 375 | + |
379 | 376 | // #278; use array instead of object storage, favoring array serializations |
380 | 377 | result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]); |
381 | 378 | } |
|
387 | 384 | function fileUploadXhr(array) { |
388 | 385 | const formdata = new FormData(); |
389 | 386 |
|
390 | | - for (let i = 0; i < array.length; i++) { |
391 | | - formdata.append(array[i].name, array[i].value); |
| 387 | + for (const {name, value} of array) { |
| 388 | + formdata.append(name, value); |
392 | 389 | } |
393 | 390 |
|
394 | 391 | if (options.extraData) { |
395 | 392 | const serializedData = deepSerialize(options.extraData); |
396 | 393 |
|
397 | | - for (let i = 0; i < serializedData.length; i++) { |
398 | | - if (serializedData[i]) { |
399 | | - formdata.append(serializedData[i][0], serializedData[i][1]); |
| 394 | + for (const serData of serializedData) { |
| 395 | + if (serData) { |
| 396 | + formdata.append(serData[0], serData[1]); |
400 | 397 | } |
401 | 398 | } |
402 | 399 | } |
|
458 | 455 | // private function for handling file uploads (hat tip to YAHOO!) |
459 | 456 | function fileUploadIframe(array) { |
460 | 457 | const form = $form[0]; |
461 | | - let $io, el, id, timedOut, timeoutHandle; |
462 | 458 |
|
463 | 459 | if (array) { |
464 | 460 | // ensure that every serialized input is still enabled |
465 | | - for (let i = 0; i < elements.length; i++) { |
466 | | - el = $(elements[i]); |
| 461 | + for (const element of elements) { |
| 462 | + const el = $(element); |
| 463 | + |
467 | 464 | if (hasProp) { |
468 | 465 | el.prop('disabled', false); |
469 | 466 | } else { |
|
475 | 472 | const settings = $.extend(true, {}, $.ajaxSettings, options); |
476 | 473 |
|
477 | 474 | settings.context = settings.context || settings; |
478 | | - id = 'jqFormIO' + new Date().getTime(); |
| 475 | + let id = 'jqFormIO' + new Date().getTime(); |
479 | 476 | const ownerDocument = form.ownerDocument; |
480 | 477 | const $body = $form.closest('body'); |
481 | 478 |
|
482 | | - let name; |
| 479 | + let $io; |
483 | 480 |
|
484 | 481 | if (settings.iframeTarget) { |
485 | 482 | $io = $(settings.iframeTarget, ownerDocument); |
486 | | - name = $io.attr2('name'); |
| 483 | + const name = $io.attr2('name'); |
| 484 | + |
487 | 485 | if (name) { |
488 | 486 | id = name; |
489 | 487 | } else { |
|
569 | 567 | const sub = form.clk; |
570 | 568 |
|
571 | 569 | if (sub) { |
572 | | - name = sub.name; |
| 570 | + const {name} = sub; |
| 571 | + |
573 | 572 | if (name && !sub.disabled) { |
574 | 573 | settings.extraData = settings.extraData || {}; |
575 | 574 | settings.extraData[name] = sub.value; |
|
627 | 626 | settings.extraData[csrfParam] = csrfToken; |
628 | 627 | } |
629 | 628 |
|
| 629 | + let timedOut, timeoutHandle; |
| 630 | + |
630 | 631 | // take a breath so that pending repaints get some cpu time before the upload starts |
631 | 632 | function doSubmit() { |
632 | 633 | // make sure form attrs are set |
|
746 | 747 | setTimeout(doSubmit, timeout); // this lets dom updates render |
747 | 748 | } |
748 | 749 |
|
749 | | - let callbackProcessed, doc, domCheckCount = 50; |
750 | | - |
751 | | - // eslint-disable-next-line prefer-const |
752 | | - let httpData; |
753 | | - |
754 | 750 | const toXml = $.parseXML || function(str, docum) { // use parseXML if available (jQuery 1.5+) |
755 | 751 | if (window.ActiveXObject) { |
756 | 752 | docum = new ActiveXObject('Microsoft.XMLDOM'); |
|
764 | 760 | return docum && docum.documentElement && docum.documentElement.nodeName !== 'parsererror' ? docum : null; |
765 | 761 | }; |
766 | 762 |
|
| 763 | + // eslint-disable-next-line prefer-const |
| 764 | + let httpData; |
| 765 | + let callbackProcessed, domCheckCount = 50; |
| 766 | + |
767 | 767 | function cb(e) { |
768 | 768 | if (xhr.aborted || callbackProcessed) { |
769 | 769 | return; |
770 | 770 | } |
771 | 771 |
|
772 | | - doc = getDoc(io); |
| 772 | + const doc = getDoc(io); |
| 773 | + |
773 | 774 | if (!doc) { |
774 | 775 | log('cannot access response document'); |
775 | 776 | e = SERVER_ABORT; |
|
801 | 802 | io.removeEventListener('load', cb, false); |
802 | 803 | } |
803 | 804 |
|
804 | | - let errMsg, status = 'success'; |
805 | | - |
806 | | - let dta; |
| 805 | + let dta, errMsg, status = 'success'; |
807 | 806 |
|
808 | 807 | try { |
809 | 808 | if (timedOut) { |
|
1072 | 1071 | } |
1073 | 1072 |
|
1074 | 1073 | function captureSubmittingElement(e) { |
1075 | | - let target = e.target; |
| 1074 | + let {target} = e; |
1076 | 1075 | const $el = $(target); |
1077 | 1076 |
|
1078 | 1077 | if (!$el.is('[type=submit],[type=image]')) { |
|
1143 | 1142 | const form = this[0]; |
1144 | 1143 | const formId = this.attr('id'); |
1145 | 1144 | let els = semantic || typeof form.elements === 'undefined' ? form.getElementsByTagName('*') : form.elements; |
1146 | | - let els2; |
1147 | 1145 |
|
1148 | 1146 | if (els) { |
1149 | 1147 | els = $.makeArray(els); // convert to standard array |
|
1152 | 1150 | // #386; account for inputs outside the form which use the 'form' attribute |
1153 | 1151 | // FinesseRus: in non-IE browsers outside fields are already included in form.elements. |
1154 | 1152 | if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) { |
1155 | | - els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet |
| 1153 | + const els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet |
| 1154 | + |
1156 | 1155 | if (els2.length) { |
1157 | 1156 | els = (els || []).concat(els2); |
1158 | 1157 | } |
|
1166 | 1165 | els = $.map(els, filtering); |
1167 | 1166 | } |
1168 | 1167 |
|
1169 | | - let el, i, j, jmax, max, name; |
| 1168 | + for (const el of els) { |
| 1169 | + const {name} = el; |
1170 | 1170 |
|
1171 | | - for (i = 0, max = els.length; i < max; i++) { |
1172 | | - el = els[i]; |
1173 | | - name = el.name; |
1174 | 1171 | if (!name || el.disabled) { |
1175 | 1172 | // eslint-disable-next-line no-continue |
1176 | 1173 | continue; |
|
1188 | 1185 |
|
1189 | 1186 | const val = $.fieldValue(el, true); |
1190 | 1187 |
|
1191 | | - if (val && val.constructor === Array) { |
| 1188 | + if (val && Array.isArray(val)) { |
1192 | 1189 | if (elements) { |
1193 | 1190 | elements.push(el); |
1194 | 1191 | } |
1195 | | - for (j = 0, jmax = val.length; j < jmax; j++) { |
1196 | | - arr.push({name: name, value: val[j]}); |
| 1192 | + for (const value of val) { |
| 1193 | + arr.push({name: name, value: value}); |
1197 | 1194 | } |
1198 | 1195 |
|
1199 | 1196 | } else if (feature.fileapi && el.type === 'file') { |
|
1204 | 1201 | const files = el.files; |
1205 | 1202 |
|
1206 | 1203 | if (files.length) { |
1207 | | - for (j = 0; j < files.length; j++) { |
1208 | | - arr.push({name: name, type: el.type, value: files[j]}); |
| 1204 | + for (const file of files) { |
| 1205 | + arr.push({name: name, type: el.type, value: file}); |
1209 | 1206 | } |
1210 | 1207 | } else { |
1211 | 1208 | // #180 |
|
1224 | 1221 | // input type=='image' are not found in elements array! handle it here |
1225 | 1222 | const $input = $(form.clk), input = $input[0]; |
1226 | 1223 |
|
1227 | | - name = input.name; |
| 1224 | + const {name} = input; |
1228 | 1225 |
|
1229 | 1226 | if (name && !input.disabled && input.type === 'image') { |
1230 | 1227 | arr.push({name: name, value: $input.val()}); |
|
1261 | 1258 |
|
1262 | 1259 | const val = $.fieldValue(this, successful); |
1263 | 1260 |
|
1264 | | - if (val && val.constructor === Array) { |
1265 | | - for (let i = 0, max = val.length; i < max; i++) { |
1266 | | - arr.push({name: name, value: val[i]}); |
| 1261 | + if (val && Array.isArray(val)) { |
| 1262 | + for (const value of val) { |
| 1263 | + arr.push({name: name, value: value}); |
1267 | 1264 | } |
1268 | 1265 |
|
1269 | 1266 | } else if (val !== null && typeof val !== 'undefined') { |
|
1320 | 1317 | const el = this[i]; |
1321 | 1318 | const value = $.fieldValue(el, successful); |
1322 | 1319 |
|
1323 | | - if (value === null || typeof value === 'undefined' || (value.constructor === Array && !value.length)) { |
| 1320 | + if (value === null || typeof value === 'undefined' || (Array.isArray(value) && !value.length)) { |
1324 | 1321 | // eslint-disable-next-line no-continue |
1325 | 1322 | continue; |
1326 | 1323 | } |
1327 | 1324 |
|
1328 | | - if (value.constructor === Array) { |
| 1325 | + if (Array.isArray(value)) { |
1329 | 1326 | $.merge(val, value); |
1330 | 1327 | } else { |
1331 | 1328 | val.push(value); |
|
1370 | 1367 | const op = ops[i]; |
1371 | 1368 |
|
1372 | 1369 | if (op.selected && !op.disabled) { |
1373 | | - let val = op.value; |
1374 | | - |
1375 | | - if (!val) { // extra pain for IE... |
1376 | | - val = op.attributes && op.attributes.value && !op.attributes.value.specified ? op.text : op.value; |
1377 | | - } |
| 1370 | + const val = op.value || |
| 1371 | + // extra pain for IE... |
| 1372 | + (op.attributes && op.attributes.value && !op.attributes.value.specified ? op.text : op.value); |
1378 | 1373 |
|
1379 | 1374 | if (one) { |
1380 | 1375 | return val; |
|
0 commit comments