summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorChristopher Lenz <cmlenz@apache.org>2009-01-16 10:04:18 +0000
committerChristopher Lenz <cmlenz@apache.org>2009-01-16 10:04:18 +0000
commited46f6d82b80825695ee7d951721c759dc7d1103 (patch)
tree533f3406cc45383efab41408337ec61936e743ab /share
parent1c13d302c9bfa4e6532fab6fd9c210acd64b962f (diff)
Update jquery.form to 2.18 in order to fix compatibility issues with jQuery 1.3, in particular COUCHDB-211.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@734953 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r--share/www/script/jquery.form.js77
1 files changed, 54 insertions, 23 deletions
diff --git a/share/www/script/jquery.form.js b/share/www/script/jquery.form.js
index 659baa98..91eb688d 100644
--- a/share/www/script/jquery.form.js
+++ b/share/www/script/jquery.form.js
@@ -1,6 +1,6 @@
/*
* jQuery Form Plugin
- * version: 2.12 (06/07/2008)
+ * version: 2.18 (06-JAN-2009)
* @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?
@@ -145,12 +157,13 @@ $.fn.ajaxSubmit = function(options) {
function fileUpload() {
var form = $form[0];
- if ($(':input[@name=submit]', form).length) {
+ if ($(':input[name=submit]', form).length) {
alert('Error: Form elements must not be named "submit".');
return;
}
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;
}
@@ -598,4 +629,4 @@ function log() {
window.console.log('[jquery.form] ' + Array.prototype.join.call(arguments,''));
};
-})(jQuery);
+})(jQuery); \ No newline at end of file