wp/wp-includes/js/jquery/jquery.form.js
author ymh <ymh.work@gmail.com>
Mon, 08 Sep 2025 19:44:41 +0200
changeset 23 417f20492bf7
parent 18 be944660c56a
permissions -rw-r--r--
Update Docker configuration and plugin versions - Upgrade MariaDB from 10.6 to 11 with auto-upgrade support - Add WordPress debug environment variable to FPM container - Update PHP-FPM Dockerfile base image - Update Include Mastodon Feed plugin with bug fixes and improvements - Update Portfolio plugin (v2.58) with latest translations and demo data enhancements - Remove old README.md from Mastodon Feed plugin 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
/*!
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
 * jQuery Form Plugin
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     3
 * version: 4.3.0
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     4
 * Requires jQuery v1.7.2 or later
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
 * Project repository: https://github.com/jquery-form/form
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     6
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
 * Copyright 2017 Kevin Morris
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
 * Copyright 2006 M. Alsup
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     9
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    10
 * Dual licensed under the LGPL-2.1+ or MIT licenses
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
 * https://github.com/jquery-form/form#license
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    12
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    13
 * This library is free software; you can redistribute it and/or
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    14
 * modify it under the terms of the GNU Lesser General Public
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    15
 * License as published by the Free Software Foundation; either
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    16
 * version 2.1 of the License, or (at your option) any later version.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    17
 * This library is distributed in the hope that it will be useful,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    20
 * Lesser General Public License for more details.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
/* global ActiveXObject */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
/* eslint-disable */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
(function (factory) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	if (typeof define === 'function' && define.amd) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
		// AMD. Register as an anonymous module.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
		define(['jquery'], factory);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	} else if (typeof module === 'object' && module.exports) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
		// Node/CommonJS
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
		module.exports = function( root, jQuery ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
			if (typeof jQuery === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
				// require('jQuery') returns a factory that requires window to build a jQuery instance, we normalize how we use modules
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
				// that require this pattern but the window provided is a noop if it's defined (how jquery works)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
				if (typeof window !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
					jQuery = require('jquery');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
				else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
					jQuery = require('jquery')(root);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
			factory(jQuery);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
			return jQuery;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
		};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
		// Browser globals
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
		factory(jQuery);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
}(function ($) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
/* eslint-enable */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
	'use strict';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
		Usage Note:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
		-----------
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    57
		Do not use both ajaxSubmit and ajaxForm on the same form. These
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
		functions are mutually exclusive. Use ajaxSubmit if you want
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
		to bind your own submit handler to the form. For example,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
		$(document).ready(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
			$('#myForm').on('submit', function(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
				e.preventDefault(); // <-- important
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
				$(this).ajaxSubmit({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
					target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
		});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
		Use ajaxForm when you want the plugin to manage all the event binding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
		for you. For example,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
		$(document).ready(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
			$('#myForm').ajaxForm({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
				target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    77
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
		You can also use ajaxForm with delegation (requires jQuery v1.7+), so the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
		form does not have to exist when you invoke ajaxForm:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
		$('#myForm').ajaxForm({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
			delegation: true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
			target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
		When using ajaxForm, the ajaxSubmit function will be invoked for you
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		at the appropriate time.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
	*/
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    91
	var rCRLF = /\r?\n/g;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
	 * Feature detection
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	var feature = {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
	feature.fileapi = $('<input type="file">').get(0).files !== undefined;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	feature.formdata = (typeof window.FormData !== 'undefined');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
	var hasProp = !!$.fn.prop;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
	// attr2 uses prop when it can but checks the return type for
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
	// an expected string. This accounts for the case where a form
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	// contains inputs with names like "action" or "method"; in those
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
	// cases "prop" returns the element
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
	$.fn.attr2 = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
		if (!hasProp) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
			return this.attr.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		var val = this.prop.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
		if ((val && val.jquery) || typeof val === 'string') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
			return val;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
		return this.attr.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	 * ajaxSubmit() provides a mechanism for immediately submitting
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
	 * an HTML form using AJAX.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	 * @param	{object|string}	options		jquery.form.js parameters or custom url for submission
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
	 * @param	{object}		data		extraData
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	 * @param	{string}		dataType	ajax dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
	 * @param	{function}		onSuccess	ajax success callback function
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
	$.fn.ajaxSubmit = function(options, data, dataType, onSuccess) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
		// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
		if (!this.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
			log('ajaxSubmit: skipping submit process - no element selected');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
		/* eslint consistent-this: ["error", "$form"] */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
		var method, action, url, isMsie, iframeSrc, $form = this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		if (typeof options === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			options = {success: options};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   143
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
		} else if (typeof options === 'string' || (options === false && arguments.length > 0)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   145
			options = {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
				'url'      : options,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
				'data'     : data,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
				'dataType' : dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
			if (typeof onSuccess === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
				options.success = onSuccess;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
		} else if (typeof options === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
			options = {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
		method = options.method || options.type || this.attr2('method');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
		action = options.url || this.attr2('action');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
		url = (typeof action === 'string') ? $.trim(action) : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
		url = url || window.location.href || '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
		if (url) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
			// clean url (don't include hash vaue)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   166
			url = (url.match(/^([^#]+)/) || [])[1];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
		}
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   168
		// IE requires javascript:false in https, but this breaks chrome >83 and goes against spec.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   169
		// Instead of using javascript:false always, let's only apply it for IE.
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   170
		isMsie = /(MSIE|Trident)/.test(navigator.userAgent || '');
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   171
		iframeSrc = (isMsie && /^https/i.test(window.location.href || '')) ? 'javascript:false' : 'about:blank'; // eslint-disable-line no-script-url
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
		options = $.extend(true, {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
			url       : url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
			success   : $.ajaxSettings.success,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
			type      : method || $.ajaxSettings.type,
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   177
			iframeSrc : iframeSrc
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   178
		}, options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
		// hook for manipulating the form data before it is extracted;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
		// convenient for use with rich editors like tinyMCE or FCKEditor
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
		var veto = {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   183
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
		this.trigger('form-pre-serialize', [this, options, veto]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
		if (veto.veto) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   189
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
		// provide opportunity to alter form data before it is serialized
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
		if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
			log('ajaxSubmit: submit aborted via beforeSerialize callback');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
		var traditional = options.traditional;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
		if (typeof traditional === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			traditional = $.ajaxSettings.traditional;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
		var elements = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
		var qx, a = this.formToArray(options.semantic, elements, options.filtering);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
		if (options.data) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
			var optionsData = $.isFunction(options.data) ? options.data(a) : options.data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
			options.extraData = optionsData;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
			qx = $.param(optionsData, traditional);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
		// give pre-submit callback an opportunity to abort the submit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   216
		if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
			log('ajaxSubmit: submit aborted via beforeSubmit callback');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
		// fire vetoable 'validate' event
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
		this.trigger('form-submit-validate', [a, this, options, veto]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
		if (veto.veto) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   226
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   230
		var q = $.param(a, traditional);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
		if (qx) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
			q = (q ? (q + '&' + qx) : qx);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   234
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
		if (options.type.toUpperCase() === 'GET') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
			options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
			options.data = null;	// data is null for 'get'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
			options.data = q;		// data is the query string for 'post'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   242
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
		var callbacks = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
		if (options.resetForm) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
			callbacks.push(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
				$form.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
		if (options.clearForm) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
			callbacks.push(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
				$form.clearForm(options.includeHidden);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
		// perform a load on the target only if dataType is not provided
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
		if (!options.dataType && options.target) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
			var oldSuccess = options.success || function(){};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
			callbacks.push(function(data, textStatus, jqXHR) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   262
				var successArguments = arguments,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
					fn = options.replaceTarget ? 'replaceWith' : 'html';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   264
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
				$(options.target)[fn](data).each(function(){
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
					oldSuccess.apply(this, successArguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   269
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
		} else if (options.success) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
			if ($.isArray(options.success)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
				$.merge(callbacks, options.success);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
				callbacks.push(options.success);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
		options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
			var context = options.context || this;		// jQuery 1.4+ supports scope context
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
			for (var i = 0, max = callbacks.length; i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
				callbacks[i].apply(context, [data, status, xhr || $form, $form]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   283
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
		};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   286
		if (options.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
			var oldError = options.error;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
			options.error = function(xhr, status, error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
				var context = options.context || this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
				oldError.apply(context, [xhr, status, error, $form]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
		if (options.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
			var oldComplete = options.complete;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
			options.complete = function(xhr, status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
				var context = options.context || this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
				oldComplete.apply(context, [xhr, status, $form]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
		// are there files to upload?
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
		// [value] (issue #113), also see comment:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
		// https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
		var fileInputs = $('input[type=file]:enabled', this).filter(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
			return $(this).val() !== '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
		var hasFileInputs = fileInputs.length > 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
		var mp = 'multipart/form-data';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
		var multipart = ($form.attr('enctype') === mp || $form.attr('encoding') === mp);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
		var fileAPI = feature.fileapi && feature.formdata;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
		log('fileAPI :' + fileAPI);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
		var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
		var jqxhr;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
		// options.iframe allows user to force iframe mode
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
		// 06-NOV-09: now defaulting to iframe mode if file input is detected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
		if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
			// hack to fix Safari hang (thanks to Tim Molendijk for this)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
			// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
			if (options.closeKeepAlive) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
				$.get(options.closeKeepAlive, function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
					jqxhr = fileUploadIframe(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
				});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
				jqxhr = fileUploadIframe(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   335
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   336
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
		} else if ((hasFileInputs || multipart) && fileAPI) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   338
			jqxhr = fileUploadXhr(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   340
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
			jqxhr = $.ajax(options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
		$form.removeData('jqxhr').data('jqxhr', jqxhr);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
		// clear element array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   347
		for (var k = 0; k < elements.length; k++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
			elements[k] = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
		// fire 'notify' event
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
		this.trigger('form-submit-notify', [this, options]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
		return this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
		// utility fn for deep serialization
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
		function deepSerialize(extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
			var serialized = $.param(extraData, options.traditional).split('&');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
			var len = serialized.length;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
			var result = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
			var i, part;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
			for (i = 0; i < len; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
				// #252; undo param space replacement
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
				serialized[i] = serialized[i].replace(/\+/g, ' ');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
				part = serialized[i].split('=');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
				// #278; use array instead of object storage, favoring array serializations
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
				result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   369
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   370
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
			return result;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
		// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
		function fileUploadXhr(a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   376
			var formdata = new FormData();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
			for (var i = 0; i < a.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
				formdata.append(a[i].name, a[i].value);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
			if (options.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
				var serializedData = deepSerialize(options.extraData);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
				for (i = 0; i < serializedData.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
					if (serializedData[i]) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
						formdata.append(serializedData[i][0], serializedData[i][1]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
			options.data = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
			var s = $.extend(true, {}, $.ajaxSettings, options, {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   395
				contentType : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   396
				processData : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
				cache       : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
				type        : method || 'POST'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   400
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
			if (options.uploadProgress) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
				// workaround because jqXHR does not expose upload property
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
				s.xhr = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
					var xhr = $.ajaxSettings.xhr();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
					if (xhr.upload) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
						xhr.upload.addEventListener('progress', function(event) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
							var percent = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
							var position = event.loaded || event.position;			/* event.position is deprecated */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
							var total = event.total;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
							if (event.lengthComputable) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
								percent = Math.ceil(position / total * 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
							}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
							options.uploadProgress(event, position, total, percent);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
						}, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
					return xhr;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
				};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
			s.data = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   425
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   426
			var beforeSend = s.beforeSend;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   427
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
			s.beforeSend = function(xhr, o) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
				// Send FormData() provided by user
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   430
				if (options.formData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
					o.data = options.formData;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   432
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
					o.data = formdata;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
				if (beforeSend) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
					beforeSend.call(this, xhr, o);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   438
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
			return $.ajax(s);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
		// private function for handling file uploads (hat tip to YAHOO!)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
		function fileUploadIframe(a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
			var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
			var deferred = $.Deferred();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
			// #341
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
			deferred.abort = function(status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
				xhr.abort(status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
			if (a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
				// ensure that every serialized input is still enabled
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
				for (i = 0; i < elements.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
					el = $(elements[i]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
					if (hasProp) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
						el.prop('disabled', false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
						el.removeAttr('disabled');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
			s = $.extend(true, {}, $.ajaxSettings, options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
			s.context = s.context || s;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
			id = 'jqFormIO' + new Date().getTime();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
			var ownerDocument = form.ownerDocument;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
			var $body = $form.closest('body');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
			if (s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
				$io = $(s.iframeTarget, ownerDocument);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
				n = $io.attr2('name');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
				if (!n) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
					$io.attr2('name', id);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
					id = n;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
				$io = $('<iframe name="' + id + '" src="' + s.iframeSrc + '" />', ownerDocument);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
				$io.css({position: 'absolute', top: '-1000px', left: '-1000px'});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
			io = $io[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
			xhr = { // mock object
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
				aborted               : 0,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
				responseText          : null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
				responseXML           : null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
				status                : 0,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
				statusText            : 'n/a',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
				getAllResponseHeaders : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
				getResponseHeader     : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
				setRequestHeader      : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
				abort                 : function(status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
					var e = (status === 'timeout' ? 'timeout' : 'aborted');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   500
					log('aborting upload... ' + e);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
					this.aborted = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   502
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
					try { // #214, #257
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
						if (io.contentWindow.document.execCommand) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
							io.contentWindow.document.execCommand('Stop');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
					} catch (ignore) {}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   509
					$io.attr('src', s.iframeSrc); // abort op in progress
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
					xhr.error = e;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
					if (s.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
						s.error.call(s.context, xhr, e, status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   516
						$.event.trigger('ajaxError', [xhr, s, e]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   518
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
					if (s.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
						s.complete.call(s.context, xhr, e);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
			g = s.global;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
			// trigger ajax global events so that activity/block indicators work like normal
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
			if (g && $.active++ === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
				$.event.trigger('ajaxStart');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
			if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
				$.event.trigger('ajaxSend', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
			if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
				if (s.global) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
					$.active--;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
				deferred.reject();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
				return deferred;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
			if (xhr.aborted) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
				deferred.reject();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
				return deferred;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
			// add submitting element to data if we know it
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
			sub = form.clk;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
			if (sub) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
				n = sub.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
				if (n && !sub.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   554
					s.extraData = s.extraData || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
					s.extraData[n] = sub.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   556
					if (sub.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   557
						s.extraData[n + '.x'] = form.clk_x;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
						s.extraData[n + '.y'] = form.clk_y;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   560
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   561
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
			var CLIENT_TIMEOUT_ABORT = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
			var SERVER_ABORT = 2;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   565
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   566
			function getDoc(frame) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
				/* it looks like contentWindow or contentDocument do not
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
				 * carry the protocol property in ie8, when running under ssl
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
				 * frame.document is the only valid response document, since
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   570
				 * the protocol is know but not on the other two objects. strange?
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
				 * "Same origin policy" http://en.wikipedia.org/wiki/Same_origin_policy
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
				 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
				var doc = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
				// IE8 cascading access check
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
					if (frame.contentWindow) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
						doc = frame.contentWindow.document;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
					// IE8 access denied under ssl & missing protocol
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
					log('cannot get iframe.contentWindow document: ' + err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
				if (doc) { // successful getting content
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
					return doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
				try { // simply checking may throw in ie8 under ssl or mismatched protocol
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
					doc = frame.contentDocument ? frame.contentDocument : frame.document;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
					// last attempt
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   594
					log('cannot get iframe.contentDocument: ' + err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
					doc = frame.document;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   596
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
				return doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
			// Rails CSRF hack (thanks to Yvan Barthelemy)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
			var csrf_token = $('meta[name=csrf-token]').attr('content');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
			var csrf_param = $('meta[name=csrf-param]').attr('content');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
			if (csrf_param && csrf_token) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
				s.extraData = s.extraData || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
				s.extraData[csrf_param] = csrf_token;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
			// take a breath so that pending repaints get some cpu time before the upload starts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   611
			function doSubmit() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
				// make sure form attrs are set
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   613
				var t = $form.attr2('target'),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
					a = $form.attr2('action'),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
					mp = 'multipart/form-data',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
					et = $form.attr('enctype') || $form.attr('encoding') || mp;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
				// update form attrs in IE friendly way
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
				form.setAttribute('target', id);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
				if (!method || /post/i.test(method)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
					form.setAttribute('method', 'POST');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
				if (a !== s.url) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
					form.setAttribute('action', s.url);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
				// ie borks in some cases when setting encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
				if (!s.skipEncodingOverride && (!method || /post/i.test(method))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
					$form.attr({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
						encoding : 'multipart/form-data',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   631
						enctype  : 'multipart/form-data'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
					});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   635
				// support timout
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
				if (s.timeout) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
					timeoutHandle = setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
						timedOut = true; cb(CLIENT_TIMEOUT_ABORT);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
					}, s.timeout);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
				// look for server aborts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
				function checkState() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
						var state = getDoc(io).readyState;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
						log('state = ' + state);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
						if (state && state.toLowerCase() === 'uninitialized') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
							setTimeout(checkState, 50);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
					} catch (e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
						log('Server abort: ', e, ' (', e.name, ')');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   654
						cb(SERVER_ABORT);				// eslint-disable-line callback-return
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   655
						if (timeoutHandle) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   656
							clearTimeout(timeoutHandle);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   657
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   658
						timeoutHandle = undefined;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   659
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   660
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   662
				// add "extra" data to form if provided in options
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   663
				var extraInputs = [];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   665
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
					if (s.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   667
						for (var n in s.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   668
							if (s.extraData.hasOwnProperty(n)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   669
								// if using the $.param format that allows for multiple values with the same name
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
								if ($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
									extraInputs.push(
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   672
										$('<input type="hidden" name="' + s.extraData[n].name + '">', ownerDocument).val(s.extraData[n].value)
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   673
											.appendTo(form)[0]);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   674
								} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
									extraInputs.push(
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   676
										$('<input type="hidden" name="' + n + '">', ownerDocument).val(s.extraData[n])
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   677
											.appendTo(form)[0]);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   678
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   679
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   681
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
					if (!s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
						// add iframe to doc and submit the form
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
						$io.appendTo($body);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   686
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   687
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
					if (io.attachEvent) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   689
						io.attachEvent('onload', cb);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   691
						io.addEventListener('load', cb, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   692
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   693
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   694
					setTimeout(checkState, 15);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   695
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   696
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
						form.submit();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   698
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   699
					} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   700
						// just in case form has element with name/id of 'submit'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   701
						var submitFn = document.createElement('form').submit;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   703
						submitFn.apply(form);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   704
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   705
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   706
				} finally {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   707
					// reset attrs and remove "extra" input elements
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   708
					form.setAttribute('action', a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   709
					form.setAttribute('enctype', et); // #380
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   710
					if (t) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   711
						form.setAttribute('target', t);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   712
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   713
						$form.removeAttr('target');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   715
					$(extraInputs).remove();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   716
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   717
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
			if (s.forceSync) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
				doSubmit();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
				setTimeout(doSubmit, 10); // this lets dom updates render
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
			var data, doc, domCheckCount = 50, callbackProcessed;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
			function cb(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
				if (xhr.aborted || callbackProcessed) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
				doc = getDoc(io);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   733
				if (!doc) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
					log('cannot access response document');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
					e = SERVER_ABORT;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
				if (e === CLIENT_TIMEOUT_ABORT && xhr) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
					xhr.abort('timeout');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
					deferred.reject(xhr, 'timeout');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   741
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   742
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   743
				}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   744
				if (e === SERVER_ABORT && xhr) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
					xhr.abort('server abort');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
					deferred.reject(xhr, 'error', 'server abort');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   747
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   748
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
				if (!doc || doc.location.href === s.iframeSrc) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
					// response not received yet
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
					if (!timedOut) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
						return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
				if (io.detachEvent) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
					io.detachEvent('onload', cb);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   760
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   761
					io.removeEventListener('load', cb, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   763
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
				var status = 'success', errMsg;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
					if (timedOut) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
						throw 'timeout';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
					var isXml = s.dataType === 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
					log('isXml=' + isXml);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
					if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
						if (--domCheckCount) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
							// in some browsers (Opera) the iframe DOM is not always traversable when
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
							// the onload callback fires, so we loop a bit to accommodate
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
							log('requeing onLoad callback, DOM not available');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
							setTimeout(cb, 250);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
							return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
						// let this fall through because server response could be an empty document
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
						// log('Could not access iframe DOM after mutiple tries.');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
						// throw 'DOMException: not available';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
					// log('response detected');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
					var docRoot = doc.body ? doc.body : doc.documentElement;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
					xhr.responseText = docRoot ? docRoot.innerHTML : null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
					xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
					if (isXml) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
						s.dataType = 'xml';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
					xhr.getResponseHeader = function(header){
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
						var headers = {'content-type': s.dataType};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
						return headers[header.toLowerCase()];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
					};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
					// support for XHR 'status' & 'statusText' emulation :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
					if (docRoot) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   804
						xhr.status = Number(docRoot.getAttribute('status')) || xhr.status;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
						xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
					var dt = (s.dataType || '').toLowerCase();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
					var scr = /(json|script|text)/.test(dt);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
					if (scr || s.textarea) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
						// see if user embedded response in textarea
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
						var ta = doc.getElementsByTagName('textarea')[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
						if (ta) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   816
							xhr.responseText = ta.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
							// support for XHR 'status' & 'statusText' emulation :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   818
							xhr.status = Number(ta.getAttribute('status')) || xhr.status;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   819
							xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
						} else if (scr) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
							// account for browsers injecting pre around json response
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   823
							var pre = doc.getElementsByTagName('pre')[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
							var b = doc.getElementsByTagName('body')[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
							if (pre) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
								xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
							} else if (b) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
								xhr.responseText = b.textContent ? b.textContent : b.innerText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
					} else if (dt === 'xml' && !xhr.responseXML && xhr.responseText) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
						xhr.responseXML = toXml(xhr.responseText);			// eslint-disable-line no-use-before-define
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
						data = httpData(xhr, dt, s);						// eslint-disable-line no-use-before-define
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
					} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
						status = 'parsererror';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
						xhr.error = errMsg = (err || status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
					log('error caught: ', err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
					status = 'error';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
					xhr.error = errMsg = (err || status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   851
				if (xhr.aborted) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
					log('upload aborted');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
					status = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
				if (xhr.status) { // we've set xhr.status
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
					status = ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) ? 'success' : 'error';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
				// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
				if (status === 'success') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
					if (s.success) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
						s.success.call(s.context, data, 'success', xhr);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
					deferred.resolve(xhr.responseText, 'success', xhr);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
						$.event.trigger('ajaxSuccess', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
				} else if (status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
					if (typeof errMsg === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
						errMsg = xhr.statusText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
					if (s.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
						s.error.call(s.context, xhr, status, errMsg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
					deferred.reject(xhr, 'error', errMsg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
						$.event.trigger('ajaxError', [xhr, s, errMsg]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
				if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
					$.event.trigger('ajaxComplete', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
				if (g && !--$.active) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
					$.event.trigger('ajaxStop');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   892
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   893
				if (s.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   894
					s.complete.call(s.context, xhr, status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   896
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   897
				callbackProcessed = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   898
				if (s.timeout) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
					clearTimeout(timeoutHandle);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   902
				// clean up
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
				setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
					if (!s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
						$io.remove();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   906
					} else { // adding else to clean up existing iframe response.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
						$io.attr('src', s.iframeSrc);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   908
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
					xhr.responseXML = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
				}, 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
			var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
				if (window.ActiveXObject) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   915
					doc = new ActiveXObject('Microsoft.XMLDOM');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
					doc.async = 'false';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
					doc.loadXML(s);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   919
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
					doc = (new DOMParser()).parseFromString(s, 'text/xml');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
				return (doc && doc.documentElement && doc.documentElement.nodeName !== 'parsererror') ? doc : null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
			var parseJSON = $.parseJSON || function(s) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   926
				/* jslint evil:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
				return window['eval']('(' + s + ')');			// eslint-disable-line dot-notation
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   928
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
			var httpData = function(xhr, type, s) { // mostly lifted from jq1.4.4
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
				var ct = xhr.getResponseHeader('content-type') || '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
					xml = ((type === 'xml' || !type) && ct.indexOf('xml') >= 0),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   934
					data = xml ? xhr.responseXML : xhr.responseText;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
				if (xml && data.documentElement.nodeName === 'parsererror') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
					if ($.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
						$.error('parsererror');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   941
				if (s && s.dataFilter) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
					data = s.dataFilter(data, type);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   943
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
				if (typeof data === 'string') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
					if ((type === 'json' || !type) && ct.indexOf('json') >= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
						data = parseJSON(data);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
					} else if ((type === 'script' || !type) && ct.indexOf('javascript') >= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   948
						$.globalEval(data);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   949
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
				return data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   953
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   955
			return deferred;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
	 * ajaxForm() provides a mechanism for fully automating form submission.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
	 * The advantages of using this method instead of ajaxSubmit() are:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
	 * 1: This method will include coordinates for <input type="image"> elements (if the element
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
	 *	is used to submit the form).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   966
	 * 2. This method will include the submit element's name/value data (for the element that was
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   967
	 *	used to submit the form).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   968
	 * 3. This method binds the submit() method to the form for you.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   969
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   970
	 * The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
	 * passes the options argument along after properly binding events for submit elements and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   972
	 * the form itself.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   973
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
	$.fn.ajaxForm = function(options, data, dataType, onSuccess) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   975
		if (typeof options === 'string' || (options === false && arguments.length > 0)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
			options = {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   977
				'url'      : options,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
				'data'     : data,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
				'dataType' : dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   982
			if (typeof onSuccess === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
				options.success = onSuccess;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   984
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   985
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   986
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
		options = options || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
		options.delegation = options.delegation && $.isFunction($.fn.on);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   989
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
		// in jQuery 1.3+ we can fix mistakes with the ready state
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
		if (!options.delegation && this.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   992
			var o = {s: this.selector, c: this.context};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
			if (!$.isReady && o.s) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
				log('DOM not ready, queuing ajaxForm');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   996
				$(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
					$(o.s, o.c).ajaxForm(options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   998
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   999
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1000
				return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1001
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1002
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
			// is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
			log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1009
		if (options.delegation) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
			$(document)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
				.off('submit.form-plugin', this.selector, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
				.off('click.form-plugin', this.selector, captureSubmittingElement)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
				.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1014
				.on('click.form-plugin', this.selector, options, captureSubmittingElement);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1017
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1019
		if (options.beforeFormUnbind) {
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1020
			options.beforeFormUnbind(this, options);
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1021
		}
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1022
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
		return this.ajaxFormUnbind()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1024
			.on('submit.form-plugin', options, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1025
			.on('click.form-plugin', options, captureSubmittingElement);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1026
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1027
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1028
	// private event handlers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
	function doAjaxSubmit(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
		/* jshint validthis:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
		var options = e.data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1032
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
		if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
			e.preventDefault();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
			$(e.target).closest('form').ajaxSubmit(options); // #365
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
	function captureSubmittingElement(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
		/* jshint validthis:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
		var target = e.target;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
		var $el = $(target);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
		if (!$el.is('[type=submit],[type=image]')) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
			// is this a child element of the submit el?  (ex: a span within a button)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
			var t = $el.closest('[type=submit]');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
			if (t.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
			target = t[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
		var form = target.form;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
		form.clk = target;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1057
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
		if (target.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
			if (typeof e.offsetX !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1060
				form.clk_x = e.offsetX;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
				form.clk_y = e.offsetY;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
			} else if (typeof $.fn.offset === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
				var offset = $el.offset();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
				form.clk_x = e.pageX - offset.left;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
				form.clk_y = e.pageY - offset.top;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1069
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
				form.clk_x = e.pageX - target.offsetLeft;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
				form.clk_y = e.pageY - target.offsetTop;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1073
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1074
		// clear form vars
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
		setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
			form.clk = form.clk_x = form.clk_y = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
		}, 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1081
	// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
	$.fn.ajaxFormUnbind = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1083
		return this.off('submit.form-plugin click.form-plugin');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
	 * formToArray() gathers form element data into an array of objects that can
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
	 * be passed to any of the following ajax functions: $.get, $.post, or load.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
	 * Each object in the array has both a 'name' and 'value' property. An example of
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
	 * an array for a simple login form might be:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1091
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1092
	 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1093
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
	 * It is this array that is passed to pre-submit callback functions provided to the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
	 * ajaxSubmit() and ajaxForm() methods.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1096
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
	$.fn.formToArray = function(semantic, elements, filtering) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
		var a = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1099
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1100
		if (this.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1101
			return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1102
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1104
		var form = this[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
		var formId = this.attr('id');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
		var els = (semantic || typeof form.elements === 'undefined') ? form.getElementsByTagName('*') : form.elements;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1107
		var els2;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1109
		if (els) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
			els = $.makeArray(els); // convert to standard array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
		// #386; account for inputs outside the form which use the 'form' attribute
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
		// FinesseRus: in non-IE browsers outside fields are already included in form.elements.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1115
		if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1116
			els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1117
			if (els2.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
				els = (els || []).concat(els2);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1119
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
		if (!els || !els.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
			return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
		if ($.isFunction(filtering)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
			els = $.map(els, filtering);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1129
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1130
		var i, j, n, v, el, max, jmax;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
		for (i = 0, max = els.length; i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1133
			el = els[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1134
			n = el.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1135
			if (!n || el.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1136
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
			if (semantic && form.clk && el.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
				// handle image inputs on the fly when semantic == true
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
				if (form.clk === el) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
					a.push({name: n, value: $(el).val(), type: el.type});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
					a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1147
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
			v = $.fieldValue(el, true);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
			if (v && v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
				for (j = 0, jmax = v.length; j < jmax; j++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
					a.push({name: n, value: v[j]});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1156
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
			} else if (feature.fileapi && el.type === 'file') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1158
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1159
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1160
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1161
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1162
				var files = el.files;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
				if (files.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
					for (j = 0; j < files.length; j++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
						a.push({name: n, value: files[j], type: el.type});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
					// #180
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1170
					a.push({name: n, value: '', type: el.type});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1172
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
			} else if (v !== null && typeof v !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1176
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1177
				a.push({name: n, value: v, type: el.type, required: el.required});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1178
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1180
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
		if (!semantic && form.clk) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
			// input type=='image' are not found in elements array! handle it here
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
			var $input = $(form.clk), input = $input[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
			n = input.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
			if (n && !input.disabled && input.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
				a.push({name: n, value: $input.val()});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
				a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
		return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1195
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1197
	 * Serializes form data into a 'submittable' string. This method will return a string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1198
	 * in the format: name1=value1&amp;name2=value2
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1200
	$.fn.formSerialize = function(semantic) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
		// hand off to jQuery.param for proper encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1202
		return $.param(this.formToArray(semantic));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1203
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1204
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1205
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1206
	 * Serializes all field elements in the jQuery object into a query string.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1207
	 * This method will return a string in the format: name1=value1&amp;name2=value2
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1208
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1209
	$.fn.fieldSerialize = function(successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
		var a = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
		this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
			var n = this.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
			if (!n) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
			var v = $.fieldValue(this, successful);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
			if (v && v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
				for (var i = 0, max = v.length; i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
					a.push({name: n, value: v[i]});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
			} else if (v !== null && typeof v !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
				a.push({name: this.name, value: v});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
		});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
		// hand off to jQuery.param for proper encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
		return $.param(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
	 * Returns the value(s) of the element in the matched set. For example, consider the following form:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
	 *	<form><fieldset>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
	 *		<input name="A" type="text">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
	 *		<input name="A" type="text">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1241
	 *		<input name="B" type="checkbox" value="B1">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
	 *		<input name="B" type="checkbox" value="B2">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
	 *		<input name="C" type="radio" value="C1">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
	 *		<input name="C" type="radio" value="C2">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
	 *	</fieldset></form>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
	 *	var v = $('input[type=text]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1248
	 *	// if no values are entered into the text inputs
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
	 *	v === ['','']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1250
	 *	// if values entered into the text inputs are 'foo' and 'bar'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1251
	 *	v === ['foo','bar']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1252
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1253
	 *	var v = $('input[type=checkbox]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
	 *	// if neither checkbox is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1255
	 *	v === undefined
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
	 *	// if both checkboxes are checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1257
	 *	v === ['B1', 'B2']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1258
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1259
	 *	var v = $('input[type=radio]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1260
	 *	// if neither radio is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
	 *	v === undefined
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1262
	 *	// if first radio is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
	 *	v === ['C1']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1264
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
	 * The successful argument controls whether or not the field element must be 'successful'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1266
	 * (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
	 * The default value of the successful argument is true. If this value is false the value(s)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
	 * for each element is returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
	 * Note: This method *always* returns an array. If no valid value can be determined the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
	 *	array will be empty, otherwise it will contain one or more values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
	$.fn.fieldValue = function(successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
		for (var val = [], i = 0, max = this.length; i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
			var el = this[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
			var v = $.fieldValue(el, successful);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1278
			if (v === null || typeof v === 'undefined' || (v.constructor === Array && !v.length)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1279
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1280
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1281
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1282
			if (v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1283
				$.merge(val, v);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
				val.push(v);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1288
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
		return val;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1290
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1291
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1292
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1293
	 * Returns the value of the field element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1295
	$.fieldValue = function(el, successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1296
		var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1297
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
		if (typeof successful === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
			successful = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1302
		/* eslint-disable no-mixed-operators */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1303
		if (successful && (!n || el.disabled || t === 'reset' || t === 'button' ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
			(t === 'checkbox' || t === 'radio') && !el.checked ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
			(t === 'submit' || t === 'image') && el.form && el.form.clk !== el ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1306
			tag === 'select' && el.selectedIndex === -1)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1307
		/* eslint-enable no-mixed-operators */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1308
			return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1309
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1310
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1311
		if (tag === 'select') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1312
			var index = el.selectedIndex;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1313
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1314
			if (index < 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1315
				return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1316
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1317
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1318
			var a = [], ops = el.options;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1319
			var one = (t === 'select-one');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1320
			var max = (one ? index + 1 : ops.length);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1321
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1322
			for (var i = (one ? index : 0); i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1323
				var op = ops[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1324
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1325
				if (op.selected && !op.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1326
					var v = op.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1327
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1328
					if (!v) { // extra pain for IE...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1329
						v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1330
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1331
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1332
					if (one) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1333
						return v;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1334
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1335
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1336
					a.push(v);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1337
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1338
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1339
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1340
			return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1341
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1342
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1343
		return $(el).val().replace(rCRLF, '\r\n');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1344
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1346
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1347
	 * Clears the form data. Takes the following actions on the form's input fields:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1348
	 *  - input text fields will have their 'value' property set to the empty string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1349
	 *  - select elements will have their 'selectedIndex' property set to -1
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1350
	 *  - checkbox and radio inputs will have their 'checked' property set to false
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1351
	 *  - inputs of type submit, button, reset, and hidden will *not* be effected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1352
	 *  - button elements will *not* be effected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1353
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1354
	$.fn.clearForm = function(includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1355
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1356
			$('input,select,textarea', this).clearFields(includeHidden);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1357
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1358
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1359
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1360
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1361
	 * Clears the selected form elements.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1362
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1363
	$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
		var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1365
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1367
			var t = this.type, tag = this.tagName.toLowerCase();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1369
			if (re.test(t) || tag === 'textarea') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1370
				this.value = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1371
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1372
			} else if (t === 'checkbox' || t === 'radio') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1373
				this.checked = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1374
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1375
			} else if (tag === 'select') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
				this.selectedIndex = -1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
			} else if (t === 'file') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
				if (/MSIE/.test(navigator.userAgent)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
					$(this).replaceWith($(this).clone(true));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1381
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1382
					$(this).val('');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1383
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1384
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
			} else if (includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1386
				// includeHidden can be the value true, or it can be a selector string
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
				// indicating a special test; for example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1388
				// $('#myForm').clearForm('.special:hidden')
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
				// the above would clean hidden inputs that have the class of 'special'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
				if ((includeHidden === true && /hidden/.test(t)) ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
					(typeof includeHidden === 'string' && $(this).is(includeHidden))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
					this.value = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1393
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1397
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1398
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1399
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
	 * Resets the form data or individual elements. Takes the following actions
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1401
	 * on the selected tags:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1402
	 * - all fields within form elements will be reset to their original value
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1403
	 * - input / textarea / select fields will be reset to their original value
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1404
	 * - option / optgroup fields (for multi-selects) will defaulted individually
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1405
	 * - non-multiple options will find the right select to default
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
	 * - label elements will be searched against its 'for' attribute
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
	 * - all others will be searched for appropriate children to default
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
	$.fn.resetForm = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
			var el = $(this);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
			var tag = this.tagName.toLowerCase();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
			switch (tag) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
			case 'input':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
				this.checked = this.defaultChecked;
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1417
				// fall through
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1418
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1419
			case 'textarea':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1420
				this.value = this.defaultValue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1421
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1422
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
			case 'option':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
			case 'optgroup':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
				var select = el.parents('select');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1427
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1428
				if (select.length && select[0].multiple) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
					if (tag === 'option') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
						this.selected = this.defaultSelected;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1431
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1432
						el.find('option').resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1434
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
					select.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1439
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1440
			case 'select':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
				el.find('option').each(function(i) {				// eslint-disable-line consistent-return
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1442
					this.selected = this.defaultSelected;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
					if (this.defaultSelected && !el[0].multiple) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
						el[0].selectedIndex = i;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1445
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
						return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1449
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1450
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1452
			case 'label':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
				var forEl = $(el.attr('for'));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
				var list = el.find('input,select,textarea');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
				if (forEl[0]) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
					list.unshift(forEl[0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1458
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
				list.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
			case 'form':
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1465
				// guard against an input with the name of 'reset'
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
  1466
				// note that IE reports the reset function as an 'object'
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
				if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1468
					this.reset();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
			default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
				el.find('form,input,label,select,textarea').resetForm();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1475
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
	 * Enables or disables any matching elements.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
	$.fn.enable = function(b) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
		if (typeof b === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
			b = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
			this.disabled = !b;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
	 * Checks/unchecks any matching checkboxes or radio buttons and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
	 * selects/deselects and matching option elements.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
	$.fn.selected = function(select) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
		if (typeof select === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
			select = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
			var t = this.type;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
			if (t === 'checkbox' || t === 'radio') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1507
				this.checked = select;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1509
			} else if (this.tagName.toLowerCase() === 'option') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1510
				var $sel = $(this).parent('select');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
				if (select && $sel[0] && $sel[0].type === 'select-one') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
					// deselect all other options
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
					$sel.find('option').selected(false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1515
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1516
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
				this.selected = select;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1518
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1519
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1520
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1521
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1522
	// expose debug var
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1523
	$.fn.ajaxSubmit.debug = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1525
	// helper fn for console logging
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1526
	function log() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1527
		if (!$.fn.ajaxSubmit.debug) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1529
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1530
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1531
		var msg = '[jquery.form] ' + Array.prototype.join.call(arguments, '');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1532
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1533
		if (window.console && window.console.log) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1534
			window.console.log(msg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1535
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1536
		} else if (window.opera && window.opera.postError) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1537
			window.opera.postError(msg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1538
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1539
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1540
}));