/*\r
* jQuery Form Plugin\r
- * version: 2.12 (06/07/2008)\r
+ * version: 2.17 (06-NOV-2008)\r
* @requires jQuery v1.2.2 or later\r
*\r
* Examples and documentation at: http://malsup.com/jquery/form/\r
*\r
* Revision: $Id$\r
*/\r
-(function($) {\r
+;(function($) {\r
\r
/*\r
Usage Note: \r
if (veto.veto) {\r
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');\r
return this;\r
- }\r
+ }\r
\r
+ // provide opportunity to alter form data before it is serialized\r
+ if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {\r
+ log('ajaxSubmit: submit aborted via beforeSerialize callback');\r
+ return this;\r
+ } \r
+ \r
var a = this.formToArray(options.semantic);\r
if (options.data) {\r
options.extraData = options.data;\r
- for (var n in options.data)\r
- a.push( { name: n, value: options.data[n] } );\r
+ for (var n in options.data) {\r
+ if(options.data[n] instanceof Array) {\r
+ for (var k in options.data[n])\r
+ a.push( { name: n, value: options.data[n][k] } )\r
+ } \r
+ else\r
+ a.push( { name: n, value: options.data[n] } );\r
+ }\r
}\r
\r
// give pre-submit callback an opportunity to abort the submit\r
\r
options.success = function(data, status) {\r
for (var i=0, max=callbacks.length; i < max; i++)\r
- callbacks[i](data, status, $form);\r
+ callbacks[i].apply(options, [data, status, $form]);\r
};\r
\r
// are there files to upload?\r
}\r
\r
var opts = $.extend({}, $.ajaxSettings, options);\r
+ var s = jQuery.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts);\r
\r
var id = 'jqFormIO' + (new Date().getTime());\r
var $io = $('<iframe id="' + id + '" name="' + id + '" />');\r
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });\r
\r
var xhr = { // mock object\r
+ aborted: 0,\r
responseText: null,\r
responseXML: null,\r
status: 0,\r
statusText: 'n/a',\r
getAllResponseHeaders: function() {},\r
getResponseHeader: function() {},\r
- setRequestHeader: function() {}\r
+ setRequestHeader: function() {},\r
+ abort: function() { \r
+ this.aborted = 1; \r
+ $io.attr('src','about:blank'); // abort op in progress\r
+ }\r
};\r
\r
var g = opts.global;\r
if (g && ! $.active++) $.event.trigger("ajaxStart");\r
if (g) $.event.trigger("ajaxSend", [xhr, opts]);\r
\r
+ if (s.beforeSend && s.beforeSend(xhr, s) === false) {\r
+ s.global && jQuery.active--;\r
+ return;\r
+ }\r
+ if (xhr.aborted)\r
+ return;\r
+ \r
var cbInvoked = 0;\r
var timedOut = 0;\r
\r
}\r
}\r
}\r
- \r
+\r
// take a breath so that pending repaints get some cpu time before the upload starts\r
setTimeout(function() {\r
// make sure form attrs are set\r
var t = $form.attr('target'), a = $form.attr('action');\r
$form.attr({\r
target: id,\r
- encoding: 'multipart/form-data',\r
- enctype: 'multipart/form-data',\r
method: 'POST',\r
action: opts.url\r
});\r
+ \r
+ // ie borks in some cases when setting encoding\r
+ if (! options.skipEncodingOverride) {\r
+ $form.attr({\r
+ encoding: 'multipart/form-data',\r
+ enctype: 'multipart/form-data'\r
+ });\r
+ }\r
\r
// support timout\r
if (opts.timeout)\r
}).each(function() {\r
// store options in hash\r
$(":submit,input:image", this).bind('click.form-plugin',function(e) {\r
- var $form = this.form;\r
- $form.clk = this;\r
+ var form = this.form;\r
+ form.clk = this;\r
if (this.type == 'image') {\r
if (e.offsetX != undefined) {\r
- $form.clk_x = e.offsetX;\r
- $form.clk_y = e.offsetY;\r
+ form.clk_x = e.offsetX;\r
+ form.clk_y = e.offsetY;\r
} else if (typeof $.fn.offset == 'function') { // try to use dimensions plugin\r
var offset = $(this).offset();\r
- $form.clk_x = e.pageX - offset.left;\r
- $form.clk_y = e.pageY - offset.top;\r
+ form.clk_x = e.pageX - offset.left;\r
+ form.clk_y = e.pageY - offset.top;\r
} else {\r
- $form.clk_x = e.pageX - this.offsetLeft;\r
- $form.clk_y = e.pageY - this.offsetTop;\r
+ form.clk_x = e.pageX - this.offsetLeft;\r
+ form.clk_y = e.pageY - this.offsetTop;\r
}\r
}\r
// clear form vars\r
- setTimeout(function() { $form.clk = $form.clk_x = $form.clk_y = null; }, 10);\r
+ setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 10);\r
});\r
});\r
};\r
* Checks/unchecks any matching checkboxes or radio buttons and\r
* selects/deselects and matching option elements.\r
*/\r
-$.fn.select = function(select) {\r
+$.fn.selected = function(select) {\r
if (select == undefined) select = true;\r
return this.each(function() { \r
var t = this.type;\r
var $sel = $(this).parent('select');\r
if (select && $sel[0] && $sel[0].type == 'select-one') {\r
// deselect all other options\r
- $sel.find('option').select(false);\r
+ $sel.find('option').selected(false);\r
}\r
this.selected = select;\r
}\r