PageSourceSearch

https://www.taaze.tw/include/js/jquery.form.js

js taaze.tw collected 2026-10-01 11:26:19 UTC 26,066 bytes, 885 lines download raw bytes

1/*!
2* jQuery Form Plugin
3* version: 2.95 (30-JAN-2012)
4* @requires jQuery v1.3.2 or later
5*
6* Examples and documentation at: http://malsup.com/jquery/form/
7* Dual licensed under the MIT and GPL licenses:
8*	http://www.opensource.org/licenses/mit-license.php
9*	http://www.gnu.org/licenses/gpl.html
10*/
11;(function($) {
12/*
13Usage Note:
14-----------
15Do not use both ajaxSubmit and ajaxForm on the same form.  These
16functions are intended to be exclusive.  Use ajaxSubmit if you want
17to bind your own submit handler to the form.  For example,
18$(document).ready(function() {
19$('#myForm').bind('submit', function(e) {
20e.preventDefault(); // <-- important
21$(this).ajaxSubmit({
22target: '#output'
23});
24});
25});
26Use ajaxForm when you want the plugin to manage all the event binding
27for you.  For example,
28$(document).ready(function() {
29$('#myForm').ajaxForm({
30target: '#output'
31});
32});
33When using ajaxForm, the ajaxSubmit function will be invoked for you
34at the appropriate time.
35*/
36/**
37* ajaxSubmit() provides a mechanism for immediately submitting
38* an HTML form using AJAX.
39*/
40$.fn.ajaxSubmit = function(options) {
41// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
42if (!this.length) {
43log('ajaxSubmit: skipping submit process - no element selected');
44return this;
45}
46var method, action, url, $form = this;
47if (typeof options == 'function') {
48options = { success: options };
49}
50method = this.attr('method');
51action = this.attr('action');
52url = (typeof action === 'string') ? $.trim(action) : '';
53url = url || window.location.href || '';
54if (url) {
55// clean url (don't include hash vaue)
56url = (url.match(/^([^#]+)/)||[])[1];
57}
58options = $.extend(true, {
59url:  url,
60success: $.ajaxSettings.success,
61type: method || 'GET',
62iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
63}, options);
64// hook for manipulating the form data before it is extracted;
65// convenient for use with rich editors like tinyMCE or FCKEditor
66var veto = {};
67this.trigger('form-pre-serialize', [this, options, veto]);
68if (veto.veto) {
69log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
70return this;
71}
72// provide opportunity to alter form data before it is serialized
73if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
74log('ajaxSubmit: submit aborted via beforeSerialize callback');
75return this;
76}
77var traditional = options.traditional;
78if ( traditional === undefined ) {
79traditional = $.ajaxSettings.traditional;
80}
81var qx,n,v,a = this.formToArray(options.semantic);
82if (options.data) {
83options.extraData = options.data;
84qx = $.param(options.data, traditional);
85}
86// give pre-submit callback an opportunity to abort the submit
87if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
88log('ajaxSubmit: submit aborted via beforeSubmit callback');
89return this;
90}
91// fire vetoable 'validate' event
92this.trigger('form-submit-validate', [a, this, options, veto]);
93if (veto.veto) {
94log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
95return this;
96}
97var q = $.param(a, traditional);
98if (qx) {
99q = ( q ? (q + '&' + qx) : qx );
100}
101if (options.type.toUpperCase() == 'GET') {
102options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
103options.data = null;  // data is null for 'get'
104}
105else {
106options.data = q; // data is the query string for 'post'
107}
108var callbacks = [];
109if (options.resetForm) {
110callbacks.push(function() { $form.resetForm(); });
111}
112if (options.clearForm) {
113callbacks.push(function() { $form.clearForm(options.includeHidden); });
114}
115// perform a load on the target only if dataType is not provided
116if (!options.dataType && options.target) {
117var oldSuccess = options.success || function(){};
118callbacks.push(function(data) {
119var fn = options.replaceTarget ? 'replaceWith' : 'html';
120$(options.target)[fn](data).each(oldSuccess, arguments);
121});
122}
123else if (options.success) {
124callbacks.push(options.success);
125}
126options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
127var context = options.context || options;	// jQuery 1.4+ supports scope context
128for (var i=0, max=callbacks.length; i < max; i++) {
129callbacks[i].apply(context, [data, status, xhr || $form, $form]);
130}
131};
132// are there files to upload?
133var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
134var hasFileInputs = fileInputs.length > 0;
135var mp = 'multipart/form-data';
136var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
137var fileAPI = !!(hasFileInputs && fileInputs.get(0).files && window.FormData);
138log("fileAPI :" + fileAPI);
139var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
140// options.iframe allows user to force iframe mode
141// 06-NOV-09: now defaulting to iframe mode if file input is detected
142if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
143// hack to fix Safari hang (thanks to Tim Molendijk for this)
144// see:  http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
145if (options.closeKeepAlive) {
146$.get(options.closeKeepAlive, function() {
147fileUploadIframe(a);
148});
149}
150else {
151fileUploadIframe(a);
152}
153}
154else if ((hasFileInputs || multipart) && fileAPI) {
155options.progress = options.progress || $.noop;
156fileUploadXhr(a);
157}
158else {
159$.ajax(options);
160}
161// fire 'notify' event
162this.trigger('form-submit-notify', [this, options]);
163return this;
164// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
165function fileUploadXhr(a) {
166var formdata = new FormData();
167for (var i=0; i < a.length; i++) {
168if (a[i].type == 'file')
169continue;
170formdata.append(a[i].name, a[i].value);
171}
172$form.find('input:file:enabled').each(function(){
173var name = $(this).attr('name'), files = this.files;
174if (name) {
175for (var i=0; i < files.length; i++)
176formdata.append(name, files[i]);
177}
178});
179if (options.extraData) {
180for (var k in options.extraData)
181formdata.append(k, options.extraData[k])
182}
183options.data = null;
184var s = $.extend(true, {}, $.ajaxSettings, options, {
185contentType: false,
186processData: false,
187cache: false,
188type: 'POST'
189});
190//s.context = s.context || s;
191s.data = null;
192var beforeSend = s.beforeSend;
193s.beforeSend = function(xhr, o) {
194o.data = formdata;
195if(xhr.upload) { // unfortunately, jQuery doesn't expose this prop (http://bugs.jquery.com/ticket/10190)
196xhr.upload.onprogress = function(event) {
197o.progress(event.position, event.total);
198};
199}
200if(beforeSend)
201beforeSend.call(o, xhr, options);
202};
203$.ajax(s);
204}
205// private function for handling file uploads (hat tip to YAHOO!)
206function fileUploadIframe(a) {
207var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
208var useProp = !!$.fn.prop;
209if (a) {
210if ( useProp ) {
211// ensure that every serialized input is still enabled
212for (i=0; i < a.length; i++) {
213el = $(form[a[i].name]);
214el.prop('disabled', false);
215}
216} else {
217for (i=0; i < a.length; i++) {
218el = $(form[a[i].name]);
219el.removeAttr('disabled');
220}
221};
222}
223if ($(':input[name=submit],:input[id=submit]', form).length) {
224// if there is an input with a name or id of 'submit' then we won't be
225// able to invoke the submit fn on the form (at least not x-browser)
226alert('Error: Form elements must not have name or id of "submit".');
227return;
228}
229s = $.extend(true, {}, $.ajaxSettings, options);
230s.context = s.context || s;
231id = 'jqFormIO' + (new Date().getTime());
232if (s.iframeTarget) {
233$io = $(s.iframeTarget);
234n = $io.attr('name');
235if (n == null)
236$io.attr('name', id);
237else
238id = n;
239}
240else {
241$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
242$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
243}
244io = $io[0];
245xhr = { // mock object
246aborted: 0,
247responseText: null,
248responseXML: null,
249status: 0,
250statusText: 'n/a',
251getAllResponseHeaders: function() {},
252getResponseHeader: function() {},
253setRequestHeader: function() {},
254abort: function(status) {
255var e = (status === 'timeout' ? 'timeout' : 'aborted');
256log('aborting upload... ' + e);
257this.aborted = 1;
258$io.attr('src', s.iframeSrc); // abort op in progress
259xhr.error = e;
260s.error && s.error.call(s.context, xhr, e, status);
261g && $.event.trigger("ajaxError", [xhr, s, e]);
262s.complete && s.complete.call(s.context, xhr, e);
263}
264};
265g = s.global;
266// trigger ajax global events so that activity/block indicators work like normal
267if (g && ! $.active++) {
268$.event.trigger("ajaxStart");
269}
270if (g) {
271$.event.trigger("ajaxSend", [xhr, s]);
272}
273if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
274if (s.global) {
275$.active--;
276}
277return;
278}
279if (xhr.aborted) {
280return;
281}
282// add submitting element to data if we know it
283sub = form.clk;
284if (sub) {
285n = sub.name;
286if (n && !sub.disabled) {
287s.extraData = s.extraData || {};
288s.extraData[n] = sub.value;
289if (sub.type == "image") {
290s.extraData[n+'.x'] = form.clk_x;
291s.extraData[n+'.y'] = form.clk_y;
292}
293}
294}
295var CLIENT_TIMEOUT_ABORT = 1;
296var SERVER_ABORT = 2;
297function getDoc(frame) {
298var doc = frame.contentWindow ? frame.contentWindow.document : frame.contentDocument ? frame.contentDocument : frame.document;
299return doc;
300}
301// Rails CSRF hack (thanks to Yvan Barthelemy)
302var csrf_token = $('meta[name=csrf-token]').attr('content');
303var csrf_param = $('meta[name=csrf-param]').attr('content');
304if (csrf_param && csrf_token) {
305s.extraData = s.extraData || {};
306s.extraData[csrf_param] = csrf_token;
307}
308// take a breath so that pending repaints get some cpu time before the upload starts
309function doSubmit() {
310// make sure form attrs are set
311var t = $form.attr('target'), a = $form.attr('action');
312// update form attrs in IE friendly way
313form.setAttribute('target',id);
314if (!method) {
315form.setAttribute('method', 'POST');
316}
317if (a != s.url) {
318form.setAttribute('action', s.url);
319}
320// ie borks in some cases when setting encoding
321if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
322$form.attr({
323encoding: 'multipart/form-data',
324enctype:  'multipart/form-data'
325});
326}
327// support timout
328if (s.timeout) {
329timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
330}
331// look for server aborts
332function checkState() {
333try {
334var state = getDoc(io).readyState;
335log('state = ' + state);
336if (state.toLowerCase() == 'uninitialized')
337setTimeout(checkState,50);
338}
339catch(e) {
340log('Server abort: ' , e, ' (', e.name, ')');
341cb(SERVER_ABORT);
342timeoutHandle && clearTimeout(timeoutHandle);
343timeoutHandle = undefined;
344}
345}
346// add "extra" data to form if provided in options
347var extraInputs = [];
348try {
349if (s.extraData) {
350for (var n in s.extraData) {
351extraInputs.push(
352$('<input type="hidden" name="'+n+'">').attr('value',s.extraData[n])
353.appendTo(form)[0]);
354}
355}
356if (!s.iframeTarget) {
357// add iframe to doc and submit the form
358$io.appendTo('body');
359io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
360}
361setTimeout(checkState,15);
362form.submit();
363}
364finally {
365// reset attrs and remove "extra" input elements
366form.setAttribute('action',a);
367if(t) {
368form.setAttribute('target', t);
369} else {
370$form.removeAttr('target');
371}
372$(extraInputs).remove();
373}
374}
375if (s.forceSync) {
376doSubmit();
377}
378else {
379setTimeout(doSubmit, 10); // this lets dom updates render
380}
381var data, doc, domCheckCount = 50, callbackProcessed;
382function cb(e) {
383if (xhr.aborted || callbackProcessed) {
384return;
385}
386try {
387doc = getDoc(io);
388}
389catch(ex) {
390log('cannot access response document: ', ex);
391e = SERVER_ABORT;
392}
393if (e === CLIENT_TIMEOUT_ABORT && xhr) {
394xhr.abort('timeout');
395return;
396}
397else if (e == SERVER_ABORT && xhr) {
398xhr.abort('server abort');
399return;
400}
401if (!doc || doc.location.href == s.iframeSrc) {
402// response not received yet
403if (!timedOut)
404return;
405}
406io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
407var status = 'success', errMsg;
408try {
409if (timedOut) {
410throw 'timeout';
411}
412var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
413log('isXml='+isXml);
414if (!isXml && window.opera && (doc.body == null || doc.body.innerHTML == '')) {
415if (--domCheckCount) {
416// in some browsers (Opera) the iframe DOM is not always traversable when
417// the onload callback fires, so we loop a bit to accommodate
418log('requeing onLoad callback, DOM not available');
419setTimeout(cb, 250);
420return;
421}
422// let this fall through because server response could be an empty document
423//log('Could not access iframe DOM after mutiple tries.');
424//throw 'DOMException: not available';
425}
426//log('response detected');
427var docRoot = doc.body ? doc.body : doc.documentElement;
428xhr.responseText = docRoot ? docRoot.innerHTML : null;
429xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
430if (isXml)
431s.dataType = 'xml';
432xhr.getResponseHeader = function(header){
433var headers = {'content-type': s.dataType};
434return headers[header];
435};
436// support for XHR 'status' & 'statusText' emulation :
437if (docRoot) {
438xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
439xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
440}
441var dt = (s.dataType || '').toLowerCase();
442var scr = /(json|script|text)/.test(dt);
443if (scr || s.textarea) {
444// see if user embedded response in textarea
445var ta = doc.getElementsByTagName('textarea')[0];
446if (ta) {
447xhr.responseText = ta.value;
448// support for XHR 'status' & 'statusText' emulation :
449xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
450xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
451}
452else if (scr) {
453// account for browsers injecting pre around json response
454var pre = doc.getElementsByTagName('pre')[0];
455var b = doc.getElementsByTagName('body')[0];
456if (pre) {
457xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
458}
459else if (b) {
460xhr.responseText = b.textContent ? b.textContent : b.innerText;
461}
462}
463}
464else if (dt == 'xml' && !xhr.responseXML && xhr.responseText != null) {
465xhr.responseXML = toXml(xhr.responseText);
466}
467try {
468data = httpData(xhr, dt, s);
469}
470catch (e) {
471status = 'parsererror';
472xhr.error = errMsg = (e || status);
473}
474}
475catch (e) {
476log('error caught: ',e);
477status = 'error';
478xhr.error = errMsg = (e || status);
479}
480if (xhr.aborted) {
481log('upload aborted');
482status = null;
483}
484if (xhr.status) { // we've set xhr.status
485status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
486}
487// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
488if (status === 'success') {
489s.success && s.success.call(s.context, data, 'success', xhr);
490g && $.event.trigger("ajaxSuccess", [xhr, s]);
491}
492else if (status) {
493if (errMsg == undefined)
494errMsg = xhr.statusText;
495s.error && s.error.call(s.context, xhr, status, errMsg);
496g && $.event.trigger("ajaxError", [xhr, s, errMsg]);
497}
498g && $.event.trigger("ajaxComplete", [xhr, s]);
499if (g && ! --$.active) {
500$.event.trigger("ajaxStop");
501}
502s.complete && s.complete.call(s.context, xhr, status);
503callbackProcessed = true;
504if (s.timeout)
505clearTimeout(timeoutHandle);
506// clean up
507setTimeout(function() {
508if (!s.iframeTarget)
509$io.remove();
510xhr.responseXML = null;
511}, 100);
512}
513var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
514if (window.ActiveXObject) {
515doc = new ActiveXObject('Microsoft.XMLDOM');
516doc.async = 'false';
517doc.loadXML(s);
518}
519else {
520doc = (new DOMParser()).parseFromString(s, 'text/xml');
521}
522return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
523};
524var parseJSON = $.parseJSON || function(s) {
525return window['eval']('(' + s + ')');
526};
527var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
528var ct = xhr.getResponseHeader('content-type') || '',
529xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
530data = xml ? xhr.responseXML : xhr.responseText;
531if (xml && data.documentElement.nodeName === 'parsererror') {
532$.error && $.error('parsererror');
533}
534if (s && s.dataFilter) {
535data = s.dataFilter(data, type);
536}
537if (typeof data === 'string') {
538if (type === 'json' || !type && ct.indexOf('json') >= 0) {
539data = parseJSON(data);
540} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
541$.globalEval(data);
542}
543}
544return data;
545};
546}
547};
548/**
549* ajaxForm() provides a mechanism for fully automating form submission.
550*
551* The advantages of using this method instead of ajaxSubmit() are:
552*
553* 1: This method will include coordinates for <input type="image" /> elements (if the element
554*	is used to submit the form).
555* 2. This method will include the submit element's name/value data (for the element that was
556*	used to submit the form).
557* 3. This method binds the submit() method to the form for you.
558*
559* The options argument for ajaxForm works exactly as it does for ajaxSubmit.  ajaxForm merely
560* passes the options argument along after properly binding events for submit elements and
561* the form itself.
562*/
563$.fn.ajaxForm = function(options) {
564// in jQuery 1.3+ we can fix mistakes with the ready state
565if (this.length === 0) {
566var o = { s: this.selector, c: this.context };
567if (!$.isReady && o.s) {
568log('DOM not ready, queuing ajaxForm');
569$(function() {
570$(o.s,o.c).ajaxForm(options);
571});
572return this;
573}
574// is your DOM ready?  http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
575log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
576return this;
577}
578return this.ajaxFormUnbind().bind('submit.form-plugin', function(e) {
579if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
580e.preventDefault();
581$(this).ajaxSubmit(options);
582}
583}).bind('click.form-plugin', function(e) {
584var target = e.target;
585var $el = $(target);
586if (!($el.is(":submit,input:image"))) {
587// is this a child element of the submit el?  (ex: a span within a button)
588var t = $el.closest(':submit');
589if (t.length == 0) {
590return;
591}
592target = t[0];
593}
594var form = this;
595form.clk = target;
596if (target.type == 'image') {
597if (e.offsetX != undefined) {
598form.clk_x = e.offsetX;
599form.clk_y = e.offsetY;
600} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
601var offset = $el.offset();
602form.clk_x = e.pageX - offset.left;
603form.clk_y = e.pageY - offset.top;
604} else {
605form.clk_x = e.pageX - target.offsetLeft;
606form.clk_y = e.pageY - target.offsetTop;
607}
608}
609// clear form vars
610setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
611});
612};
613// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
614$.fn.ajaxFormUnbind = function() {
615return this.unbind('submit.form-plugin click.form-plugin');
616};
617/**
618* formToArray() gathers form element data into an array of objects that can
619* be passed to any of the following ajax functions: $.get, $.post, or load.
620* Each object in the array has both a 'name' and 'value' property.  An example of
621* an array for a simple login form might be:
622*
623* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
624*
625* It is this array that is passed to pre-submit callback functions provided to the
626* ajaxSubmit() and ajaxForm() methods.
627*/
628$.fn.formToArray = function(semantic) {
629var a = [];
630if (this.length === 0) {
631return a;
632}
633var form = this[0];
634var els = semantic ? form.getElementsByTagName('*') : form.elements;
635if (!els) {
636return a;
637}
638var i,j,n,v,el,max,jmax;
639for(i=0, max=els.length; i < max; i++) {
640el = els[i];
641n = el.name;
642if (!n) {
643continue;
644}
645if (semantic && form.clk && el.type == "image") {
646// handle image inputs on the fly when semantic == true
647if(!el.disabled && form.clk == el) {
648a.push({name: n, value: $(el).val(), type: el.type });
649a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
650}
651continue;
652}
653v = $.fieldValue(el, true);
654if (v && v.constructor == Array) {
655for(j=0, jmax=v.length; j < jmax; j++) {
656a.push({name: n, value: v[j]});
657}
658}
659else if (v !== null && typeof v != 'undefined') {
660a.push({name: n, value: v, type: el.type});
661}
662}
663if (!semantic && form.clk) {
664// input type=='image' are not found in elements array! handle it here
665var $input = $(form.clk), input = $input[0];
666n = input.name;
667if (n && !input.disabled && input.type == 'image') {
668a.push({name: n, value: $input.val()});
669a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
670}
671}
672return a;
673};
674/**
675* Serializes form data into a 'submittable' string. This method will return a string
676* in the format: name1=value1&amp;name2=value2
677*/
678$.fn.formSerialize = function(semantic) {
679//hand off to jQuery.param for proper encoding
680return $.param(this.formToArray(semantic));
681};
682/**
683* Serializes all field elements in the jQuery object into a query string.
684* This method will return a string in the format: name1=value1&amp;name2=value2
685*/
686$.fn.fieldSerialize = function(successful) {
687var a = [];
688this.each(function() {
689var n = this.name;
690if (!n) {
691return;
692}
693var v = $.fieldValue(this, successful);
694if (v && v.constructor == Array) {
695for (var i=0,max=v.length; i < max; i++) {
696a.push({name: n, value: v[i]});
697}
698}
699else if (v !== null && typeof v != 'undefined') {
700a.push({name: this.name, value: v});
701}
702});
703//hand off to jQuery.param for proper encoding
704return $.param(a);
705};
706/**
707* Returns the value(s) of the element in the matched set.  For example, consider the following form:
708*
709*  <form><fieldset>
710*	  <input name="A" type="text" />
711*	  <input name="A" type="text" />
712*	  <input name="B" type="checkbox" value="B1" />
713*	  <input name="B" type="checkbox" value="B2"/>
714*	  <input name="C" type="radio" value="C1" />
715*	  <input name="C" type="radio" value="C2" />
716*  </fieldset></form>
717*
718*  var v = $(':text').fieldValue();
719*  // if no values are entered into the text inputs
720*  v == ['','']
721*  // if values entered into the text inputs are 'foo' and 'bar'
722*  v == ['foo','bar']
723*
724*  var v = $(':checkbox').fieldValue();
725*  // if neither checkbox is checked
726*  v === undefined
727*  // if both checkboxes are checked
728*  v == ['B1', 'B2']
729*
730*  var v = $(':radio').fieldValue();
731*  // if neither radio is checked
732*  v === undefined
733*  // if first radio is checked
734*  v == ['C1']
735*
736* The successful argument controls whether or not the field element must be 'successful'
737* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
738* The default value of the successful argument is true.  If this value is false the value(s)
739* for each element is returned.
740*
741* Note: This method *always* returns an array.  If no valid value can be determined the
742*	array will be empty, otherwise it will contain one or more values.
743*/
744$.fn.fieldValue = function(successful) {
745for (var val=[], i=0, max=this.length; i < max; i++) {
746var el = this[i];
747var v = $.fieldValue(el, successful);
748if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
749continue;
750}
751v.constructor == Array ? $.merge(val, v) : val.push(v);
752}
753return val;
754};
755/**
756* Returns the value of the field element.
757*/
758$.fieldValue = function(el, successful) {
759var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
760if (successful === undefined) {
761successful = true;
762}
763if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
764(t == 'checkbox' || t == 'radio') && !el.checked ||
765(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
766tag == 'select' && el.selectedIndex == -1)) {
767return null;
768}
769if (tag == 'select') {
770var index = el.selectedIndex;
771if (index < 0) {
772return null;
773}
774var a = [], ops = el.options;
775var one = (t == 'select-one');
776var max = (one ? index+1 : ops.length);
777for(var i=(one ? index : 0); i < max; i++) {
778var op = ops[i];
779if (op.selected) {
780var v = op.value;
781if (!v) { // extra pain for IE...
782v = (op.attributes && op.attributes['value'] && !(op.attributes['value'].specified)) ? op.text : op.value;
783}
784if (one) {
785return v;
786}
787a.push(v);
788}
789}
790return a;
791}
792return $(el).val();
793};
794/**
795* Clears the form data.  Takes the following actions on the form's input fields:
796*  - input text fields will have their 'value' property set to the empty string
797*  - select elements will have their 'selectedIndex' property set to -1
798*  - checkbox and radio inputs will have their 'checked' property set to false
799*  - inputs of type submit, button, reset, and hidden will *not* be effected
800*  - button elements will *not* be effected
801*/
802$.fn.clearForm = function(includeHidden) {
803return this.each(function() {
804$('input,select,textarea', this).clearFields(includeHidden);
805});
806};
807/**
808* Clears the selected form elements.
809*/
810$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
811var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
812return this.each(function() {
813var t = this.type, tag = this.tagName.toLowerCase();
814if (re.test(t) || tag == 'textarea' || (includeHidden && /hidden/.test(t)) ) {
815this.value = '';
816}
817else if (t == 'checkbox' || t == 'radio') {
818this.checked = false;
819}
820else if (tag == 'select') {
821this.selectedIndex = -1;
822}
823});
824};
825/**
826* Resets the form data.  Causes all form elements to be reset to their original value.
827*/
828$.fn.resetForm = function() {
829return this.each(function() {
830// guard against an input with the name of 'reset'
831// note that IE reports the reset function as an 'object'
832if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
833this.reset();
834}
835});
836};
837/**
838* Enables or disables any matching elements.
839*/
840$.fn.enable = function(b) {
841if (b === undefined) {
842b = true;
843}
844return this.each(function() {
845this.disabled = !b;
846});
847};
848/**
849* Checks/unchecks any matching checkboxes or radio buttons and
850* selects/deselects and matching option elements.
851*/
852$.fn.selected = function(select) {
853if (select === undefined) {
854select = true;
855}
856return this.each(function() {
857var t = this.type;
858if (t == 'checkbox' || t == 'radio') {
859this.checked = select;
860}
861else if (this.tagName.toLowerCase() == 'option') {
862var $sel = $(this).parent('select');
863if (select && $sel[0] && $sel[0].type == 'select-one') {
864// deselect all other options
865$sel.find('option').selected(false);
866}
867this.selected = select;
868}
869});
870};
871// expose debug var
872$.fn.ajaxSubmit.debug = false;
873// helper fn for console logging
874function log() {
875if (!$.fn.ajaxSubmit.debug)
876return;
877var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
878if (window.console && window.console.log) {
879window.console.log(msg);
880}
881else if (window.opera && window.opera.postError) {
882window.opera.postError(msg);
883}
884};
885})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.