wp/wp-includes/js/jquery/jquery.form.js
author ymh <ymh.work@gmail.com>
Tue, 15 Dec 2020 13:49:49 +0100
changeset 16 a86126ab1dd4
parent 7 cf61fcea0001
child 18 be944660c56a
permissions -rw-r--r--
update enmi-conf
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
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     3
 * version: 4.2.1
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     4
 * Requires jQuery v1.7 or later
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
 * Copyright 2017 Kevin Morris
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
 * Copyright 2006 M. Alsup
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
 * Project repository: https://github.com/jquery-form/form
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
 * Dual licensed under the MIT and LGPLv3 licenses.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
 * https://github.com/jquery-form/form#license
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
/* global ActiveXObject */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
/* eslint-disable */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
(function (factory) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
	if (typeof define === 'function' && define.amd) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
		// AMD. Register as an anonymous module.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
		define(['jquery'], factory);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	} else if (typeof module === 'object' && module.exports) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
		// Node/CommonJS
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
		module.exports = function( root, jQuery ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
			if (typeof jQuery === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
				// 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
    23
				// 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
    24
				if (typeof window !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
					jQuery = require('jquery');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
				else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
					jQuery = require('jquery')(root);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
			factory(jQuery);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
			return jQuery;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
		};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
		// Browser globals
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
		factory(jQuery);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
}(function ($) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
/* eslint-enable */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	'use strict';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
	/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
		Usage Note:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
		-----------
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
		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
    47
		functions are mutually exclusive. Use ajaxSubmit if you want
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
		to bind your own submit handler to the form. For example,
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
		$(document).ready(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
			$('#myForm').on('submit', function(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
				e.preventDefault(); // <-- important
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
				$(this).ajaxSubmit({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
					target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
				});
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
		});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    59
		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
    60
		for you. For example,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
		$(document).ready(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
			$('#myForm').ajaxForm({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
				target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
			});
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
		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
    69
		form does not have to exist when you invoke ajaxForm:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
		$('#myForm').ajaxForm({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
			delegation: true,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
			target: '#output'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
		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
    77
		at the appropriate time.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
	*/
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	var rCRLF = /\r?\n/g;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
	 * Feature detection
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
	var feature = {};
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
	feature.fileapi = $('<input type="file">').get(0).files !== undefined;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
	feature.formdata = (typeof window.FormData !== 'undefined');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
	var hasProp = !!$.fn.prop;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    92
	// 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
    93
	// 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
    94
	// 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
    95
	// cases "prop" returns the element
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
	$.fn.attr2 = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    97
		if (!hasProp) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
			return this.attr.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   101
		var val = this.prop.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   102
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
		if ((val && val.jquery) || typeof val === 'string') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
			return val;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
		return this.attr.apply(this, arguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	 * ajaxSubmit() provides a mechanism for immediately submitting
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
	 * an HTML form using AJAX.
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
	 * @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
   115
	 * @param	{object}		data		extraData
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
	 * @param	{string}		dataType	ajax dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
	 * @param	{function}		onSuccess	ajax success callback function
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
	$.fn.ajaxSubmit = function(options, data, dataType, onSuccess) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
		// 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
   121
		if (!this.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
			log('ajaxSubmit: skipping submit process - no element selected');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
		/* eslint consistent-this: ["error", "$form"] */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		var method, action, url, $form = this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
		if (typeof options === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
			options = {success: options};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		} 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
   134
			options = {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
				'url'      : options,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
				'data'     : data,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
				'dataType' : dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
			if (typeof onSuccess === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
				options.success = onSuccess;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
			}
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 === 'undefined') {
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
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   147
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   148
		method = options.method || options.type || this.attr2('method');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
		action = options.url || this.attr2('action');
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
		url = (typeof action === 'string') ? $.trim(action) : '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
		url = url || window.location.href || '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
		if (url) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
			// clean url (don't include hash vaue)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
			url = (url.match(/^([^#]+)/) || [])[1];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
		options = $.extend(true, {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   159
			url       : url,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
			success   : $.ajaxSettings.success,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
			type      : method || $.ajaxSettings.type,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
			iframeSrc : /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'		// eslint-disable-line no-script-url
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
		}, options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   165
		// 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
   166
		// 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
   167
		var veto = {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
		this.trigger('form-pre-serialize', [this, options, veto]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
		if (veto.veto) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
			log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   176
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   177
		// 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
   178
		if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   179
			log('ajaxSubmit: submit aborted via beforeSerialize callback');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   180
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   181
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   184
		var traditional = options.traditional;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   185
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
		if (typeof traditional === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   187
			traditional = $.ajaxSettings.traditional;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   188
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
		var elements = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
		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
   192
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
		if (options.data) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
			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
   195
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   196
			options.extraData = optionsData;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   197
			qx = $.param(optionsData, traditional);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   198
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   200
		// 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
   201
		if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   202
			log('ajaxSubmit: submit aborted via beforeSubmit callback');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   203
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   204
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   205
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   206
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   207
		// fire vetoable 'validate' event
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   208
		this.trigger('form-submit-validate', [a, this, options, veto]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   209
		if (veto.veto) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   210
			log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   214
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
		var q = $.param(a, traditional);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
		if (qx) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
			q = (q ? (q + '&' + qx) : qx);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   219
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   221
		if (options.type.toUpperCase() === 'GET') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
			options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			options.data = null;	// data is null for 'get'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   224
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			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
   226
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   228
		var callbacks = [];
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
		if (options.resetForm) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
			callbacks.push(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
				$form.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   233
			});
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.clearForm) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
			callbacks.push(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
				$form.clearForm(options.includeHidden);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
			});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
		}
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
		// 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
   243
		if (!options.dataType && options.target) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
			var oldSuccess = options.success || function(){};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
			callbacks.push(function(data, textStatus, jqXHR) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   247
				var successArguments = arguments,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   248
					fn = options.replaceTarget ? 'replaceWith' : 'html';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   250
				$(options.target)[fn](data).each(function(){
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
					oldSuccess.apply(this, successArguments);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
			});
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
		} else if (options.success) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
			if ($.isArray(options.success)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
				$.merge(callbacks, options.success);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   258
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
				callbacks.push(options.success);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   260
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   261
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
		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
   264
			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
   265
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
			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
   267
				callbacks[i].apply(context, [data, status, xhr || $form, $form]);
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   271
		if (options.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
			var oldError = options.error;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
			options.error = function(xhr, status, error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
				var context = options.context || this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
				oldError.apply(context, [xhr, status, error, $form]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
		}
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
		if (options.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
			var oldComplete = options.complete;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   284
			options.complete = function(xhr, status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
				var context = options.context || this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
				oldComplete.apply(context, [xhr, status, $form]);
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
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
		// are there files to upload?
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   293
		// [value] (issue #113), also see comment:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
		// https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
		var fileInputs = $('input[type=file]:enabled', this).filter(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
			return $(this).val() !== '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   298
		var hasFileInputs = fileInputs.length > 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   299
		var mp = 'multipart/form-data';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   300
		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
   301
		var fileAPI = feature.fileapi && feature.formdata;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
		log('fileAPI :' + fileAPI);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   304
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
		var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   306
		var jqxhr;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   308
		// options.iframe allows user to force iframe mode
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
		// 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
   310
		if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
			// 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
   312
			// 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
   313
			if (options.closeKeepAlive) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
				$.get(options.closeKeepAlive, function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
					jqxhr = fileUploadIframe(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
				});
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
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   319
				jqxhr = fileUploadIframe(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   322
		} else if ((hasFileInputs || multipart) && fileAPI) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   323
			jqxhr = fileUploadXhr(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   324
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   325
		} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   326
			jqxhr = $.ajax(options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   327
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
		$form.removeData('jqxhr').data('jqxhr', jqxhr);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   331
		// clear element array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   332
		for (var k = 0; k < elements.length; k++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   333
			elements[k] = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   334
		}
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
		// fire 'notify' event
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   337
		this.trigger('form-submit-notify', [this, options]);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   339
		return this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   341
		// utility fn for deep serialization
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   342
		function deepSerialize(extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   343
			var serialized = $.param(extraData, options.traditional).split('&');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   344
			var len = serialized.length;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   345
			var result = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   346
			var i, part;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   348
			for (i = 0; i < len; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   349
				// #252; undo param space replacement
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   350
				serialized[i] = serialized[i].replace(/\+/g, ' ');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   351
				part = serialized[i].split('=');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   352
				// #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
   353
				result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   354
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   355
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   356
			return result;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
		// 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
   360
		function fileUploadXhr(a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
			var formdata = new FormData();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
			for (var i = 0; i < a.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
				formdata.append(a[i].name, a[i].value);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
			if (options.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   368
				var serializedData = deepSerialize(options.extraData);
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
				for (i = 0; i < serializedData.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
					if (serializedData[i]) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   372
						formdata.append(serializedData[i][0], serializedData[i][1]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   373
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   374
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   375
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
			options.data = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   378
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
			var s = $.extend(true, {}, $.ajaxSettings, options, {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
				contentType : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
				processData : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
				cache       : false,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
				type        : method || 'POST'
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
			if (options.uploadProgress) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
				// workaround because jqXHR does not expose upload property
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
				s.xhr = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
					var xhr = $.ajaxSettings.xhr();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   391
					if (xhr.upload) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   392
						xhr.upload.addEventListener('progress', function(event) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   393
							var percent = 0;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   394
							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
   395
							var total = event.total;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   397
							if (event.lengthComputable) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   398
								percent = Math.ceil(position / total * 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   399
							}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   401
							options.uploadProgress(event, position, total, percent);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   402
						}, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   403
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   404
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   405
					return xhr;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   406
				};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
			s.data = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
			var beforeSend = s.beforeSend;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
			s.beforeSend = function(xhr, o) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
				// Send FormData() provided by user
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   415
				if (options.formData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   416
					o.data = options.formData;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   417
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
					o.data = formdata;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   419
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   421
				if (beforeSend) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   422
					beforeSend.call(this, xhr, o);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   423
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   424
			};
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
			return $.ajax(s);
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   429
		// 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
   430
		function fileUploadIframe(a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   431
			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
   432
			var deferred = $.Deferred();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   433
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   434
			// #341
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   435
			deferred.abort = function(status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   436
				xhr.abort(status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   437
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   439
			if (a) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
				// ensure that every serialized input is still enabled
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
				for (i = 0; i < elements.length; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
					el = $(elements[i]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
					if (hasProp) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
						el.prop('disabled', false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   446
						el.removeAttr('disabled');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
					}
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
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
			s = $.extend(true, {}, $.ajaxSettings, options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
			s.context = s.context || s;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
			id = 'jqFormIO' + new Date().getTime();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
			var ownerDocument = form.ownerDocument;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
			var $body = $form.closest('body');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
			if (s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
				$io = $(s.iframeTarget, ownerDocument);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
				n = $io.attr2('name');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
				if (!n) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
					$io.attr2('name', id);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   463
					id = n;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
				$io = $('<iframe name="' + id + '" src="' + s.iframeSrc + '" />', ownerDocument);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
				$io.css({position: 'absolute', top: '-1000px', left: '-1000px'});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
			io = $io[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
			xhr = { // mock object
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
				aborted               : 0,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
				responseText          : null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
				responseXML           : null,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
				status                : 0,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
				statusText            : 'n/a',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
				getAllResponseHeaders : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
				getResponseHeader     : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
				setRequestHeader      : function() {},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
				abort                 : function(status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
					var e = (status === 'timeout' ? 'timeout' : 'aborted');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
					log('aborting upload... ' + e);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
					this.aborted = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
					try { // #214, #257
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
						if (io.contentWindow.document.execCommand) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
							io.contentWindow.document.execCommand('Stop');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
					} catch (ignore) {}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
					$io.attr('src', s.iframeSrc); // abort op in progress
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
					xhr.error = e;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
					if (s.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
						s.error.call(s.context, xhr, e, status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   498
					}
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
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   501
						$.event.trigger('ajaxError', [xhr, s, e]);
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   504
					if (s.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   505
						s.complete.call(s.context, xhr, e);
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
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   508
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
			g = s.global;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
			// 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
   512
			if (g && $.active++ === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
				$.event.trigger('ajaxStart');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   514
			}
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('ajaxSend', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
			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
   520
				if (s.global) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
					$.active--;
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
				deferred.reject();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
				return deferred;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   528
			if (xhr.aborted) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   529
				deferred.reject();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   530
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
				return deferred;
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
			// add submitting element to data if we know it
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
			sub = form.clk;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
			if (sub) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
				n = sub.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
				if (n && !sub.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
					s.extraData = s.extraData || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
					s.extraData[n] = sub.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
					if (sub.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
						s.extraData[n + '.x'] = form.clk_x;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
						s.extraData[n + '.y'] = form.clk_y;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
					}
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
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   548
			var CLIENT_TIMEOUT_ABORT = 1;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   549
			var SERVER_ABORT = 2;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   551
			function getDoc(frame) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   552
				/* it looks like contentWindow or contentDocument do not
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
				 * 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
   554
				 * frame.document is the only valid response document, since
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   555
				 * 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
   556
				 * "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
   557
				 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   559
				var doc = null;
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
				// IE8 cascading access check
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   562
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
					if (frame.contentWindow) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   564
						doc = frame.contentWindow.document;
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
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
					// IE8 access denied under ssl & missing protocol
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
					log('cannot get iframe.contentWindow document: ' + err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
				if (doc) { // successful getting content
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
					return doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
				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
   576
					doc = frame.contentDocument ? frame.contentDocument : frame.document;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
					// last attempt
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
					log('cannot get iframe.contentDocument: ' + err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
					doc = frame.document;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
				return doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
			// Rails CSRF hack (thanks to Yvan Barthelemy)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
			var csrf_token = $('meta[name=csrf-token]').attr('content');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
			var csrf_param = $('meta[name=csrf-param]').attr('content');
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
			if (csrf_param && csrf_token) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
				s.extraData = s.extraData || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   592
				s.extraData[csrf_param] = csrf_token;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   595
			// 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
   596
			function doSubmit() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   597
				// make sure form attrs are set
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
				var t = $form.attr2('target'),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
					a = $form.attr2('action'),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
					mp = 'multipart/form-data',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
					et = $form.attr('enctype') || $form.attr('encoding') || mp;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
				// update form attrs in IE friendly way
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
				form.setAttribute('target', id);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   605
				if (!method || /post/i.test(method)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   606
					form.setAttribute('method', 'POST');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   607
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   608
				if (a !== s.url) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   609
					form.setAttribute('action', s.url);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   610
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   612
				// ie borks in some cases when setting encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   613
				if (!s.skipEncodingOverride && (!method || /post/i.test(method))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   614
					$form.attr({
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   615
						encoding : 'multipart/form-data',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   616
						enctype  : 'multipart/form-data'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
					});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
				// support timout
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
				if (s.timeout) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
					timeoutHandle = setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
						timedOut = true; cb(CLIENT_TIMEOUT_ABORT);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
					}, s.timeout);
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
				// look for server aborts
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
				function checkState() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
						var state = getDoc(io).readyState;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   631
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
						log('state = ' + state);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   633
						if (state && state.toLowerCase() === 'uninitialized') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
							setTimeout(checkState, 50);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   635
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
					} catch (e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
						log('Server abort: ', e, ' (', e.name, ')');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
						cb(SERVER_ABORT);				// eslint-disable-line callback-return
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
						if (timeoutHandle) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   641
							clearTimeout(timeoutHandle);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
						timeoutHandle = undefined;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
				}
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
				// add "extra" data to form if provided in options
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
				var extraInputs = [];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
					if (s.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
						for (var n in s.extraData) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
							if (s.extraData.hasOwnProperty(n)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   654
								// 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
   655
								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
   656
									extraInputs.push(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   657
									$('<input type="hidden" name="' + s.extraData[n].name + '">', ownerDocument).val(s.extraData[n].value)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   658
										.appendTo(form)[0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   659
								} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   660
									extraInputs.push(
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   661
									$('<input type="hidden" name="' + n + '">', ownerDocument).val(s.extraData[n])
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   662
										.appendTo(form)[0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   663
								}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   664
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   665
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   666
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   668
					if (!s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   669
						// add iframe to doc and submit the form
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   670
						$io.appendTo($body);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   671
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   672
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   673
					if (io.attachEvent) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   674
						io.attachEvent('onload', cb);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   675
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   676
						io.addEventListener('load', cb, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   677
					}
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
					setTimeout(checkState, 15);
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
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
						form.submit();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   683
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   684
					} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
						// 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
   686
						var submitFn = document.createElement('form').submit;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   688
						submitFn.apply(form);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   689
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   691
				} finally {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   692
					// reset attrs and remove "extra" input elements
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   693
					form.setAttribute('action', a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   694
					form.setAttribute('enctype', et); // #380
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   695
					if (t) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   696
						form.setAttribute('target', t);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   697
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   698
						$form.removeAttr('target');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   699
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   700
					$(extraInputs).remove();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   701
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   702
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   704
			if (s.forceSync) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   705
				doSubmit();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   706
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   707
				setTimeout(doSubmit, 10); // this lets dom updates render
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   708
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   709
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   710
			var data, doc, domCheckCount = 50, callbackProcessed;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   712
			function cb(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   713
				if (xhr.aborted || callbackProcessed) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   714
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   715
				}
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
				doc = getDoc(io);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   718
				if (!doc) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   719
					log('cannot access response document');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   720
					e = SERVER_ABORT;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   721
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   722
				if (e === CLIENT_TIMEOUT_ABORT && xhr) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   723
					xhr.abort('timeout');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   724
					deferred.reject(xhr, 'timeout');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   726
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
				} else if (e === SERVER_ABORT && xhr) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
					xhr.abort('server abort');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
					deferred.reject(xhr, 'error', 'server abort');
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
					return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   733
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
				if (!doc || doc.location.href === s.iframeSrc) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
					// response not received yet
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
					if (!timedOut) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   738
						return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   739
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   740
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   742
				if (io.detachEvent) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   743
					io.detachEvent('onload', cb);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   744
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
					io.removeEventListener('load', cb, false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   746
				}
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
				var status = 'success', errMsg;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
				try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
					if (timedOut) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
						throw 'timeout';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
					var isXml = s.dataType === 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   757
					log('isXml=' + isXml);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   758
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   759
					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
   760
						if (--domCheckCount) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   761
							// 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
   762
							// 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
   763
							log('requeing onLoad callback, DOM not available');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
							setTimeout(cb, 250);
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
							return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
						}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
						// 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
   769
						// log('Could not access iframe DOM after mutiple tries.');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
						// throw 'DOMException: not available';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
					}
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('response detected');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
					var docRoot = doc.body ? doc.body : doc.documentElement;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
					xhr.responseText = docRoot ? docRoot.innerHTML : null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
					xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
					if (isXml) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
						s.dataType = 'xml';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
					xhr.getResponseHeader = function(header){
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
						var headers = {'content-type': s.dataType};
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
						return headers[header.toLowerCase()];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
					};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
					// support for XHR 'status' & 'statusText' emulation :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
					if (docRoot) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
						xhr.status = Number(docRoot.getAttribute('status')) || xhr.status;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
						xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
					}
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
					var dt = (s.dataType || '').toLowerCase();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
					var scr = /(json|script|text)/.test(dt);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
					if (scr || s.textarea) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
						// see if user embedded response in textarea
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
						var ta = doc.getElementsByTagName('textarea')[0];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
						if (ta) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
							xhr.responseText = ta.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
							// support for XHR 'status' & 'statusText' emulation :
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
							xhr.status = Number(ta.getAttribute('status')) || xhr.status;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
							xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   804
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
						} else if (scr) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
							// account for browsers injecting pre around json response
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
							var pre = doc.getElementsByTagName('pre')[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
							var b = doc.getElementsByTagName('body')[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
							if (pre) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
								xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
							} else if (b) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   813
								xhr.responseText = b.textContent ? b.textContent : b.innerText;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   814
							}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   815
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   817
					} else if (dt === 'xml' && !xhr.responseXML && xhr.responseText) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   818
						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
   819
					}
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
					try {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
						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
   823
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   824
					} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
						status = 'parsererror';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   826
						xhr.error = errMsg = (err || status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   828
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
				} catch (err) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
					log('error caught: ', err);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
					status = 'error';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
					xhr.error = errMsg = (err || status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
				if (xhr.aborted) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
					log('upload aborted');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
					status = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
				}
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
				if (xhr.status) { // we've set xhr.status
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
					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
   842
				}
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
				// 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
   845
				if (status === 'success') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
					if (s.success) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
						s.success.call(s.context, data, 'success', xhr);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   850
					deferred.resolve(xhr.responseText, 'success', xhr);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
						$.event.trigger('ajaxSuccess', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
				} else if (status) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
					if (typeof errMsg === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
						errMsg = xhr.statusText;
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
					if (s.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
						s.error.call(s.context, xhr, status, errMsg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
					deferred.reject(xhr, 'error', errMsg);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
					if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
						$.event.trigger('ajaxError', [xhr, s, errMsg]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
				if (g) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
					$.event.trigger('ajaxComplete', [xhr, s]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
				if (g && !--$.active) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
					$.event.trigger('ajaxStop');
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
				if (s.complete) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
					s.complete.call(s.context, xhr, status);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
				callbackProcessed = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
				if (s.timeout) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
					clearTimeout(timeoutHandle);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
				// clean up
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
				setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
					if (!s.iframeTarget) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
						$io.remove();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
					} else { // adding else to clean up existing iframe response.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
						$io.attr('src', s.iframeSrc);
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
					xhr.responseXML = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   894
				}, 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   895
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   897
			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
   898
				if (window.ActiveXObject) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
					doc = new ActiveXObject('Microsoft.XMLDOM');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
					doc.async = 'false';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   901
					doc.loadXML(s);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   904
					doc = (new DOMParser()).parseFromString(s, 'text/xml');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   907
				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
   908
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
			var parseJSON = $.parseJSON || function(s) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
				/* jslint evil:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   911
				return window['eval']('(' + s + ')');			// eslint-disable-line dot-notation
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   912
			};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   914
			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
   915
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   916
				var ct = xhr.getResponseHeader('content-type') || '',
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   917
					xml = ((type === 'xml' || !type) && ct.indexOf('xml') >= 0),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   918
					data = xml ? xhr.responseXML : xhr.responseText;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
				if (xml && data.documentElement.nodeName === 'parsererror') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
					if ($.error) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   922
						$.error('parsererror');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
					}
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
				if (s && s.dataFilter) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   926
					data = s.dataFilter(data, type);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   928
				if (typeof data === 'string') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
					if ((type === 'json' || !type) && ct.indexOf('json') >= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
						data = parseJSON(data);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
					} else if ((type === 'script' || !type) && ct.indexOf('javascript') >= 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
						$.globalEval(data);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   934
				}
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
				return data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
			return deferred;
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
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
7
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
	 * ajaxForm() provides a mechanism for fully automating form submission.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
	 * 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
   947
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   948
	 * 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
   949
	 *	is used to submit the form).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
	 * 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
   951
	 *	used to submit the form).
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
	 * 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
   953
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
	 * 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
   955
	 * 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
   956
	 * the form itself.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   958
	$.fn.ajaxForm = function(options, data, dataType, onSuccess) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
		if (typeof options === 'string' || (options === false && arguments.length > 0)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
			options = {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
				'url'      : options,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
				'data'     : data,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
				'dataType' : dataType
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
			};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   966
			if (typeof onSuccess === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   967
				options.success = onSuccess;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   968
			}
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
		options = options || {};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   972
		options.delegation = options.delegation && $.isFunction($.fn.on);
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
		// 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
   975
		if (!options.delegation && this.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
			var o = {s: this.selector, c: this.context};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
			if (!$.isReady && o.s) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   979
				log('DOM not ready, queuing ajaxForm');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   980
				$(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   981
					$(o.s, o.c).ajaxForm(options);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   982
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   983
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   984
				return this;
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
			// 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
   988
			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
   989
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   990
			return this;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   991
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   993
		if (options.delegation) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   994
			$(document)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
				.off('submit.form-plugin', this.selector, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   996
				.off('click.form-plugin', this.selector, captureSubmittingElement)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   997
				.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   998
				.on('click.form-plugin', this.selector, options, captureSubmittingElement);
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
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1003
		return this.ajaxFormUnbind()
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1004
			.on('submit.form-plugin', options, doAjaxSubmit)
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1005
			.on('click.form-plugin', options, captureSubmittingElement);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1006
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1007
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1008
	// private event handlers
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1009
	function doAjaxSubmit(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1010
		/* jshint validthis:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
		var options = e.data;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
		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
  1014
			e.preventDefault();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1015
			$(e.target).closest('form').ajaxSubmit(options); // #365
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
		}
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
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1019
	function captureSubmittingElement(e) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1020
		/* jshint validthis:true */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1021
		var target = e.target;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1022
		var $el = $(target);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1023
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1024
		if (!$el.is('[type=submit],[type=image]')) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1025
			// 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
  1026
			var t = $el.closest('[type=submit]');
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
			if (t.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1031
			target = t[0];
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
		var form = target.form;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
		form.clk = target;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
		if (target.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
			if (typeof e.offsetX !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
				form.clk_x = e.offsetX;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
				form.clk_y = e.offsetY;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
			} else if (typeof $.fn.offset === 'function') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
				var offset = $el.offset();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
				form.clk_x = e.pageX - offset.left;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
				form.clk_y = e.pageY - offset.top;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
			} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
				form.clk_x = e.pageX - target.offsetLeft;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
				form.clk_y = e.pageY - target.offsetTop;
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
		// clear form vars
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
		setTimeout(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
			form.clk = form.clk_x = form.clk_y = null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
		}, 100);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1059
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
	// 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
  1062
	$.fn.ajaxFormUnbind = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
		return this.off('submit.form-plugin click.form-plugin');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1065
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
	 * 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
  1068
	 * 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
  1069
	 * 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
  1070
	 * an array for a simple login form might be:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
	 * [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
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
	 * 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
  1075
	 * ajaxSubmit() and ajaxForm() methods.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
	$.fn.formToArray = function(semantic, elements, filtering) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
		var a = [];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1079
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1080
		if (this.length === 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1081
			return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
		var form = this[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1085
		var formId = this.attr('id');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
		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
  1087
		var els2;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
		if (els) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
			els = $.makeArray(els); // convert to standard array
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1091
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1093
		// #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
  1094
		// 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
  1095
		if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1096
			els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
			if (els2.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
				els = (els || []).concat(els2);
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
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1102
		if (!els || !els.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1103
			return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1104
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
		if ($.isFunction(filtering)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1107
			els = $.map(els, filtering);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
		var i, j, n, v, el, max, jmax;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1112
		for (i = 0, max = els.length; i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
			el = els[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
			n = el.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1115
			if (!n || el.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1116
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1117
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1119
			if (semantic && form.clk && el.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
				// handle image inputs on the fly when semantic == true
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1121
				if (form.clk === el) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
					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
  1123
					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
  1124
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1127
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
			v = $.fieldValue(el, true);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
			if (v && v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1130
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1133
				for (j = 0, jmax = v.length; j < jmax; j++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1134
					a.push({name: n, value: v[j]});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1135
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1136
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
			} else if (feature.fileapi && el.type === 'file') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
				var files = el.files;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1143
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
				if (files.length) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
					for (j = 0; j < files.length; j++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
						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
  1147
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
					// #180
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
					a.push({name: n, value: '', type: el.type});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
				}
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
			} else if (v !== null && typeof v !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
				if (elements) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
					elements.push(el);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
				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
  1158
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1159
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1161
		if (!semantic && form.clk) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1162
			// 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
  1163
			var $input = $(form.clk), input = $input[0];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
			n = input.name;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
			if (n && !input.disabled && input.type === 'image') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
				a.push({name: n, value: $input.val()});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
				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
  1170
			}
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
		return a;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
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
	 * 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
  1178
	 * in the format: name1=value1&amp;name2=value2
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
	$.fn.formSerialize = function(semantic) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
		// hand off to jQuery.param for proper encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
		return $.param(this.formToArray(semantic));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1184
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
	 * 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
  1187
	 * 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
  1188
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
	$.fn.fieldSerialize = function(successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
		var a = [];
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
		this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
			var n = this.name;
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
			if (!n) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
				return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1197
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1198
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
			var v = $.fieldValue(this, successful);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1200
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
			if (v && v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1202
				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
  1203
					a.push({name: n, value: v[i]});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1204
				}
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
			} else if (v !== null && typeof v !== 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1207
				a.push({name: this.name, value: v});
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
		});
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1210
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
		// hand off to jQuery.param for proper encoding
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
		return $.param(a);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1214
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
	 * 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
  1217
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
	 *	<form><fieldset>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
	 *		<input name="A" type="text">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
	 *		<input name="A" type="text">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
	 *		<input name="B" type="checkbox" value="B1">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
	 *		<input name="B" type="checkbox" value="B2">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
	 *		<input name="C" type="radio" value="C1">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
	 *		<input name="C" type="radio" value="C2">
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
	 *	</fieldset></form>
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
	 *	var v = $('input[type=text]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
	 *	// if no values are entered into the text inputs
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
	 *	v === ['','']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
	 *	// 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
  1231
	 *	v === ['foo','bar']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
	 *	var v = $('input[type=checkbox]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
	 *	// if neither checkbox is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
	 *	v === undefined
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
	 *	// if both checkboxes are checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
	 *	v === ['B1', 'B2']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
	 *	var v = $('input[type=radio]').fieldValue();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
	 *	// if neither radio is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1241
	 *	v === undefined
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
	 *	// if first radio is checked
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
	 *	v === ['C1']
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
	 * 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
  1246
	 * (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
  1247
	 * 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
  1248
	 * for each element is returned.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1250
	 * 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
  1251
	 *	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
  1252
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1253
	$.fn.fieldValue = function(successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
		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
  1255
			var el = this[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
			var v = $.fieldValue(el, successful);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1258
			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
  1259
				continue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1260
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1262
			if (v.constructor === Array) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
				$.merge(val, v);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
			} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
				val.push(v);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
		return val;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
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
	 * Returns the value of the field element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
	$.fieldValue = function(el, successful) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
		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
  1277
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1278
		if (typeof successful === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1279
			successful = true;
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
		/* eslint-disable no-mixed-operators */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1283
		if (successful && (!n || el.disabled || t === 'reset' || t === 'button' ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1284
			(t === 'checkbox' || t === 'radio') && !el.checked ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
			(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
  1286
			tag === 'select' && el.selectedIndex === -1)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1287
		/* eslint-enable no-mixed-operators */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1288
			return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
		}
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
		if (tag === 'select') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1292
			var index = el.selectedIndex;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1293
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
			if (index < 0) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1295
				return null;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1296
			}
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
			var a = [], ops = el.options;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
			var one = (t === 'select-one');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
			var max = (one ? index + 1 : ops.length);
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
			for (var i = (one ? index : 0); i < max; i++) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1303
				var op = ops[i];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1304
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1305
				if (op.selected && !op.disabled) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1306
					var v = op.value;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1307
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1308
					if (!v) { // extra pain for IE...
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1309
						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
  1310
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1311
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1312
					if (one) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1313
						return v;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1314
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1315
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1316
					a.push(v);
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
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1319
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1320
			return a;
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1323
		return $(el).val().replace(rCRLF, '\r\n');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1324
	};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1326
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1327
	 * 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
  1328
	 *  - 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
  1329
	 *  - 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
  1330
	 *  - 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
  1331
	 *  - 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
  1332
	 *  - button elements will *not* be effected
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1333
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1334
	$.fn.clearForm = function(includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1335
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1336
			$('input,select,textarea', this).clearFields(includeHidden);
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
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1341
	 * Clears the selected form elements.
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
	$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1344
		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
  1345
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1346
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1347
			var t = this.type, tag = this.tagName.toLowerCase();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1348
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1349
			if (re.test(t) || tag === 'textarea') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1350
				this.value = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1351
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1352
			} else if (t === 'checkbox' || t === 'radio') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1353
				this.checked = false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1354
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1355
			} else if (tag === 'select') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1356
				this.selectedIndex = -1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1358
			} else if (t === 'file') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1359
				if (/MSIE/.test(navigator.userAgent)) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1360
					$(this).replaceWith($(this).clone(true));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1361
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1362
					$(this).val('');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1363
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1364
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1365
			} else if (includeHidden) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1366
				// 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
  1367
				// indicating a special test; for example:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1368
				// $('#myForm').clearForm('.special:hidden')
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1369
				// 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
  1370
				if ((includeHidden === true && /hidden/.test(t)) ||
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1371
					(typeof includeHidden === 'string' && $(this).is(includeHidden))) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1372
					this.value = '';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1373
				}
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
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
	};
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1377
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1378
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1379
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1380
	 * 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
  1381
	 * on the selected tags:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1382
	 * - 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
  1383
	 * - 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
  1384
	 * - option / optgroup fields (for multi-selects) will defaulted individually
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
	 * - 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
  1386
	 * - label elements will be searched against its 'for' attribute
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1387
	 * - 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
  1388
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1389
	$.fn.resetForm = function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1390
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1391
			var el = $(this);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1392
			var tag = this.tagName.toLowerCase();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1394
			switch (tag) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1395
			case 'input':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1396
				this.checked = this.defaultChecked;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1397
					// fall through
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
			case 'textarea':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1400
				this.value = this.defaultValue;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1401
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1402
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1403
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1404
			case 'option':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1405
			case 'optgroup':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
				var select = el.parents('select');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
				if (select.length && select[0].multiple) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
					if (tag === 'option') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1410
						this.selected = this.defaultSelected;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1411
					} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1412
						el.find('option').resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1413
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
				} else {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1415
					select.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1416
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1417
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1418
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1419
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1420
			case 'select':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1421
				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
  1422
					this.selected = this.defaultSelected;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1423
					if (this.defaultSelected && !el[0].multiple) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1424
						el[0].selectedIndex = i;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1425
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1426
						return false;
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
				});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1429
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1430
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1431
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1432
			case 'label':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1433
				var forEl = $(el.attr('for'));
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1434
				var list = el.find('input,select,textarea');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1435
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1436
				if (forEl[0]) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1437
					list.unshift(forEl[0]);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1438
				}
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
				list.resetForm();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1441
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1442
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
			case 'form':
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1445
					// guard against an input with the name of 'reset'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
					// note that IE reports the reset function as an 'object'
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
				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
  1448
					this.reset();
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1451
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1452
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
			default:
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
				el.find('form,input,label,select,textarea').resetForm();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1455
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
				return true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
			}
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
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
	 * Enables or disables any matching elements.
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
	$.fn.enable = function(b) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1465
		if (typeof b === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1466
			b = true;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1468
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
			this.disabled = !b;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
		});
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1474
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
	 * Checks/unchecks any matching checkboxes or radio buttons and
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
	 * selects/deselects and matching option elements.
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
	$.fn.selected = function(select) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
		if (typeof select === 'undefined') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
			select = true;
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
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
		return this.each(function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
			var t = this.type;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1486
			if (t === 'checkbox' || t === 'radio') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
				this.checked = select;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1488
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
			} else if (this.tagName.toLowerCase() === 'option') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
				var $sel = $(this).parent('select');
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
				if (select && $sel[0] && $sel[0].type === 'select-one') {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
					// deselect all other options
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1494
					$sel.find('option').selected(false);
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
				}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
				this.selected = select;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
		});
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
	};
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
	// expose debug var
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
	$.fn.ajaxSubmit.debug = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1504
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1505
	// helper fn for console logging
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1506
	function log() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1507
		if (!$.fn.ajaxSubmit.debug) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1508
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1509
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1510
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1511
		var msg = '[jquery.form] ' + Array.prototype.join.call(arguments, '');
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1512
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1513
		if (window.console && window.console.log) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1514
			window.console.log(msg);
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
		} else if (window.opera && window.opera.postError) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1517
			window.opera.postError(msg);
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
}));