wp/wp-includes/js/jquery/jquery.form.js
changeset 18 be944660c56a
parent 7 cf61fcea0001
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     1 /*!
     1 /*!
     2  * jQuery Form Plugin
     2  * jQuery Form Plugin
     3  * version: 4.2.1
     3  * version: 4.3.0
     4  * Requires jQuery v1.7 or later
     4  * Requires jQuery v1.7.2 or later
       
     5  * Project repository: https://github.com/jquery-form/form
       
     6 
     5  * Copyright 2017 Kevin Morris
     7  * Copyright 2017 Kevin Morris
     6  * Copyright 2006 M. Alsup
     8  * Copyright 2006 M. Alsup
     7  * Project repository: https://github.com/jquery-form/form
     9 
     8  * Dual licensed under the MIT and LGPLv3 licenses.
    10  * Dual licensed under the LGPL-2.1+ or MIT licenses
     9  * https://github.com/jquery-form/form#license
    11  * https://github.com/jquery-form/form#license
       
    12 
       
    13  * This library is free software; you can redistribute it and/or
       
    14  * modify it under the terms of the GNU Lesser General Public
       
    15  * License as published by the Free Software Foundation; either
       
    16  * version 2.1 of the License, or (at your option) any later version.
       
    17  * This library is distributed in the hope that it will be useful,
       
    18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    20  * Lesser General Public License for more details.
    10  */
    21  */
    11 /* global ActiveXObject */
    22 /* global ActiveXObject */
    12 
    23 
    13 /* eslint-disable */
    24 /* eslint-disable */
    14 (function (factory) {
    25 (function (factory) {
   123 
   134 
   124 			return this;
   135 			return this;
   125 		}
   136 		}
   126 
   137 
   127 		/* eslint consistent-this: ["error", "$form"] */
   138 		/* eslint consistent-this: ["error", "$form"] */
   128 		var method, action, url, $form = this;
   139 		var method, action, url, isMsie, iframeSrc, $form = this;
   129 
   140 
   130 		if (typeof options === 'function') {
   141 		if (typeof options === 'function') {
   131 			options = {success: options};
   142 			options = {success: options};
   132 
   143 
   133 		} else if (typeof options === 'string' || (options === false && arguments.length > 0)) {
   144 		} else if (typeof options === 'string' || (options === false && arguments.length > 0)) {
   152 		url = url || window.location.href || '';
   163 		url = url || window.location.href || '';
   153 		if (url) {
   164 		if (url) {
   154 			// clean url (don't include hash vaue)
   165 			// clean url (don't include hash vaue)
   155 			url = (url.match(/^([^#]+)/) || [])[1];
   166 			url = (url.match(/^([^#]+)/) || [])[1];
   156 		}
   167 		}
       
   168 		// IE requires javascript:false in https, but this breaks chrome >83 and goes against spec.
       
   169 		// Instead of using javascript:false always, let's only apply it for IE.
       
   170 		isMsie = /(MSIE|Trident)/.test(navigator.userAgent || '');
       
   171 		iframeSrc = (isMsie && /^https/i.test(window.location.href || '')) ? 'javascript:false' : 'about:blank'; // eslint-disable-line no-script-url
   157 
   172 
   158 		options = $.extend(true, {
   173 		options = $.extend(true, {
   159 			url       : url,
   174 			url       : url,
   160 			success   : $.ajaxSettings.success,
   175 			success   : $.ajaxSettings.success,
   161 			type      : method || $.ajaxSettings.type,
   176 			type      : method || $.ajaxSettings.type,
   162 			iframeSrc : /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'		// eslint-disable-line no-script-url
   177 			iframeSrc : iframeSrc
   163 		}, options);
   178 		}, options);
   164 
   179 
   165 		// hook for manipulating the form data before it is extracted;
   180 		// hook for manipulating the form data before it is extracted;
   166 		// convenient for use with rich editors like tinyMCE or FCKEditor
   181 		// convenient for use with rich editors like tinyMCE or FCKEditor
   167 		var veto = {};
   182 		var veto = {};
   652 						for (var n in s.extraData) {
   667 						for (var n in s.extraData) {
   653 							if (s.extraData.hasOwnProperty(n)) {
   668 							if (s.extraData.hasOwnProperty(n)) {
   654 								// if using the $.param format that allows for multiple values with the same name
   669 								// if using the $.param format that allows for multiple values with the same name
   655 								if ($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
   670 								if ($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
   656 									extraInputs.push(
   671 									extraInputs.push(
   657 									$('<input type="hidden" name="' + s.extraData[n].name + '">', ownerDocument).val(s.extraData[n].value)
   672 										$('<input type="hidden" name="' + s.extraData[n].name + '">', ownerDocument).val(s.extraData[n].value)
   658 										.appendTo(form)[0]);
   673 											.appendTo(form)[0]);
   659 								} else {
   674 								} else {
   660 									extraInputs.push(
   675 									extraInputs.push(
   661 									$('<input type="hidden" name="' + n + '">', ownerDocument).val(s.extraData[n])
   676 										$('<input type="hidden" name="' + n + '">', ownerDocument).val(s.extraData[n])
   662 										.appendTo(form)[0]);
   677 											.appendTo(form)[0]);
   663 								}
   678 								}
   664 							}
   679 							}
   665 						}
   680 						}
   666 					}
   681 					}
   667 
   682 
   723 					xhr.abort('timeout');
   738 					xhr.abort('timeout');
   724 					deferred.reject(xhr, 'timeout');
   739 					deferred.reject(xhr, 'timeout');
   725 
   740 
   726 					return;
   741 					return;
   727 
   742 
   728 				} else if (e === SERVER_ABORT && xhr) {
   743 				}
       
   744 				if (e === SERVER_ABORT && xhr) {
   729 					xhr.abort('server abort');
   745 					xhr.abort('server abort');
   730 					deferred.reject(xhr, 'error', 'server abort');
   746 					deferred.reject(xhr, 'error', 'server abort');
   731 
   747 
   732 					return;
   748 					return;
   733 				}
   749 				}
   996 				.off('click.form-plugin', this.selector, captureSubmittingElement)
  1012 				.off('click.form-plugin', this.selector, captureSubmittingElement)
   997 				.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
  1013 				.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
   998 				.on('click.form-plugin', this.selector, options, captureSubmittingElement);
  1014 				.on('click.form-plugin', this.selector, options, captureSubmittingElement);
   999 
  1015 
  1000 			return this;
  1016 			return this;
       
  1017 		}
       
  1018 
       
  1019 		if (options.beforeFormUnbind) {
       
  1020 			options.beforeFormUnbind(this, options);
  1001 		}
  1021 		}
  1002 
  1022 
  1003 		return this.ajaxFormUnbind()
  1023 		return this.ajaxFormUnbind()
  1004 			.on('submit.form-plugin', options, doAjaxSubmit)
  1024 			.on('submit.form-plugin', options, doAjaxSubmit)
  1005 			.on('click.form-plugin', options, captureSubmittingElement);
  1025 			.on('click.form-plugin', options, captureSubmittingElement);
  1392 			var tag = this.tagName.toLowerCase();
  1412 			var tag = this.tagName.toLowerCase();
  1393 
  1413 
  1394 			switch (tag) {
  1414 			switch (tag) {
  1395 			case 'input':
  1415 			case 'input':
  1396 				this.checked = this.defaultChecked;
  1416 				this.checked = this.defaultChecked;
  1397 					// fall through
  1417 				// fall through
  1398 
  1418 
  1399 			case 'textarea':
  1419 			case 'textarea':
  1400 				this.value = this.defaultValue;
  1420 				this.value = this.defaultValue;
  1401 
  1421 
  1402 				return true;
  1422 				return true;
  1440 				list.resetForm();
  1460 				list.resetForm();
  1441 
  1461 
  1442 				return true;
  1462 				return true;
  1443 
  1463 
  1444 			case 'form':
  1464 			case 'form':
  1445 					// guard against an input with the name of 'reset'
  1465 				// guard against an input with the name of 'reset'
  1446 					// note that IE reports the reset function as an 'object'
  1466 				// note that IE reports the reset function as an 'object'
  1447 				if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
  1467 				if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
  1448 					this.reset();
  1468 					this.reset();
  1449 				}
  1469 				}
  1450 
  1470 
  1451 				return true;
  1471 				return true;