summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2008-11-30 18:16:27 -0500
committerEvan Prodromou <evan@controlyourself.ca>2008-11-30 18:16:27 -0500
commit412e3e27f27dda1ec8a4dffb4117b526ca6cc9df (patch)
treeb7ecf3abfef7747f54d78d1d02c315fc7a18d583
parent70c90b50b01cc9669065acb3b609b464e1227de0 (diff)
new upstream version of jquery form
darcs-hash:20081130231627-5ed1f-7ee35664bf6cf3a35157bd861016a1210dfca79c.gz
-rw-r--r--js/jquery.form.js73
1 files changed, 52 insertions, 21 deletions
diff --git a/js/jquery.form.js b/js/jquery.form.js
index d9266bd64..cb8b5a660 100644
--- a/js/jquery.form.js
+++ b/js/jquery.form.js
@@ -1,6 +1,6 @@
/*
* jQuery Form Plugin
- * version: 2.12 (06/07/2008)
+ * version: 2.17 (06-NOV-2008)
* @requires jQuery v1.2.2 or later
*
* Examples and documentation at: http://malsup.com/jquery/form/
@@ -10,7 +10,7 @@
*
* Revision: $Id$
*/
-(function($) {
+;(function($) {
/*
Usage Note:
@@ -67,13 +67,25 @@ $.fn.ajaxSubmit = function(options) {
if (veto.veto) {
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
return this;
- }
+ }
+ // provide opportunity to alter form data before it is serialized
+ if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
+ log('ajaxSubmit: submit aborted via beforeSerialize callback');
+ return this;
+ }
+
var a = this.formToArray(options.semantic);
if (options.data) {
options.extraData = options.data;
- for (var n in options.data)
- a.push( { name: n, value: options.data[n] } );
+ for (var n in options.data) {
+ if(options.data[n] instanceof Array) {
+ for (var k in options.data[n])
+ a.push( { name: n, value: options.data[n][k] } )
+ }
+ else
+ a.push( { name: n, value: options.data[n] } );
+ }
}
// give pre-submit callback an opportunity to abort the submit
@@ -114,7 +126,7 @@ $.fn.ajaxSubmit = function(options) {
options.success = function(data, status) {
for (var i=0, max=callbacks.length; i < max; i++)
- callbacks[i](data, status, $form);
+ callbacks[i].apply(options, [data, status, $form]);
};
// are there files to upload?
@@ -151,6 +163,7 @@ $.fn.ajaxSubmit = function(options) {
}
var opts = $.extend({}, $.ajaxSettings, options);
+ var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);
var id = 'jqFormIO' + (new Date().getTime());
var $io = $('<iframe id="' + id + '" name="' + id + '" />');
@@ -161,13 +174,18 @@ $.fn.ajaxSubmit = function(options) {
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
var xhr = { // mock object
+ aborted: 0,
responseText: null,
responseXML: null,
status: 0,
statusText: 'n/a',
getAllResponseHeaders: function() {},
getResponseHeader: function() {},
- setRequestHeader: function() {}
+ setRequestHeader: function() {},
+ abort: function() {
+ this.aborted = 1;
+ $io.attr('src','about:blank'); // abort op in progress
+ }
};
var g = opts.global;
@@ -175,6 +193,13 @@ $.fn.ajaxSubmit = function(options) {
if (g && ! $.active++) $.event.trigger("ajaxStart");
if (g) $.event.trigger("ajaxSend", [xhr, opts]);
+ if (s.beforeSend && s.beforeSend(xhr, s) === false) {
+ s.global && jQuery.active--;
+ return;
+ }
+ if (xhr.aborted)
+ return;
+
var cbInvoked = 0;
var timedOut = 0;
@@ -191,18 +216,24 @@ $.fn.ajaxSubmit = function(options) {
}
}
}
-
+
// take a breath so that pending repaints get some cpu time before the upload starts
setTimeout(function() {
// make sure form attrs are set
var t = $form.attr('target'), a = $form.attr('action');
$form.attr({
target: id,
- encoding: 'multipart/form-data',
- enctype: 'multipart/form-data',
method: 'POST',
action: opts.url
});
+
+ // ie borks in some cases when setting encoding
+ if (! options.skipEncodingOverride) {
+ $form.attr({
+ encoding: 'multipart/form-data',
+ enctype: 'multipart/form-data'
+ });
+ }
// support timout
if (opts.timeout)
@@ -325,23 +356,23 @@ $.fn.ajaxForm = function(options) {
}).each(function() {
// store options in hash
$(":submit,input:image", this).bind('click.form-plugin',function(e) {
- var $form = this.form;
- $form.clk = this;
+ var form = this.form;
+ form.clk = this;
if (this.type == 'image') {
if (e.offsetX != undefined) {
- $form.clk_x = e.offsetX;
- $form.clk_y = e.offsetY;
+ form.clk_x = e.offsetX;
+ form.clk_y = e.offsetY;
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin
var offset = $(this).offset();
- $form.clk_x = e.pageX - offset.left;
- $form.clk_y = e.pageY - offset.top;
+ form.clk_x = e.pageX - offset.left;
+ form.clk_y = e.pageY - offset.top;
} else {
- $form.clk_x = e.pageX - this.offsetLeft;
- $form.clk_y = e.pageY - this.offsetTop;
+ form.clk_x = e.pageX - this.offsetLeft;
+ form.clk_y = e.pageY - this.offsetTop;
}
}
// clear form vars
- setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);
+ setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);
});
});
};
@@ -574,7 +605,7 @@ $.fn.enable = function(b) {
* Checks/unchecks any matching checkboxes or radio buttons and
* selects/deselects and matching option elements.
*/
-$.fn.select = function(select) {
+$.fn.selected = function(select) {
if (select == undefined) select = true;
return this.each(function() {
var t = this.type;
@@ -584,7 +615,7 @@ $.fn.select = function(select) {
var $sel = $(this).parent('select');
if (select && $sel[0] && $sel[0].type == 'select-one') {
// deselect all other options
- $sel.find('option').select(false);
+ $sel.find('option').selected(false);
}
this.selected = select;
}