Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 40015 invoked from network); 5 Feb 2011 10:48:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Feb 2011 10:48:59 -0000 Received: (qmail 94227 invoked by uid 500); 5 Feb 2011 10:48:59 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 94094 invoked by uid 500); 5 Feb 2011 10:48:57 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 94083 invoked by uid 99); 5 Feb 2011 10:48:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Feb 2011 10:48:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Feb 2011 10:48:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8374023889FD; Sat, 5 Feb 2011 10:48:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1067425 - /couchdb/trunk/share/www/script/jquery.form.js Date: Sat, 05 Feb 2011 10:48:34 -0000 To: commits@couchdb.apache.org From: jasondavies@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110205104834.8374023889FD@eris.apache.org> Author: jasondavies Date: Sat Feb 5 10:48:34 2011 New Revision: 1067425 URL: http://svn.apache.org/viewvc?rev=1067425&view=rev Log: Upgrade jquery.form.js to v2.63 Modified: couchdb/trunk/share/www/script/jquery.form.js Modified: couchdb/trunk/share/www/script/jquery.form.js URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/jquery.form.js?rev=1067425&r1=1067424&r2=1067425&view=diff ============================================================================== --- couchdb/trunk/share/www/script/jquery.form.js (original) +++ couchdb/trunk/share/www/script/jquery.form.js Sat Feb 5 10:48:34 2011 @@ -1,7 +1,7 @@ -/* +/*! * jQuery Form Plugin - * version: 2.36 (07-NOV-2009) - * @requires jQuery v1.2.6 or later + * version: 2.63 (29-JAN-2011) + * @requires jQuery v1.3.2 or later * * Examples and documentation at: http://malsup.com/jquery/form/ * Dual licensed under the MIT and GPL licenses: @@ -18,11 +18,11 @@ to bind your own submit handler to the form. For example, $(document).ready(function() { - $('#myForm').bind('submit', function() { + $('#myForm').bind('submit', function(e) { + e.preventDefault(); // <-- important $(this).ajaxSubmit({ target: '#output' }); - return false; // <-- important! }); }); @@ -50,21 +50,23 @@ $.fn.ajaxSubmit = function(options) { return this; } - if (typeof options == 'function') + if (typeof options == 'function') { options = { success: options }; + } - var url = $.trim(this.attr('action')); + var action = this.attr('action'); + var url = (typeof action === 'string') ? $.trim(action) : ''; if (url) { // clean url (don't include hash vaue) url = (url.match(/^([^#]+)/)||[])[1]; - } - url = url || window.location.href || ''; + } + url = url || window.location.href || ''; - options = $.extend({ + options = $.extend(true, { url: url, - type: this.attr('method') || 'GET', + type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57) iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' - }, options || {}); + }, options); // hook for manipulating the form data before it is extracted; // convenient for use with rich editors like tinyMCE or FCKEditor @@ -81,16 +83,20 @@ $.fn.ajaxSubmit = function(options) { return this; } - var a = this.formToArray(options.semantic); + var n,v,a = this.formToArray(options.semantic); if (options.data) { options.extraData = options.data; - 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] } ); + for (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 { + v = options.data[n]; + v = $.isFunction(v) ? v() : v; // if value is fn, invoke it + a.push( { name: n, value: v } ); + } } } @@ -113,51 +119,57 @@ $.fn.ajaxSubmit = function(options) { options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q; options.data = null; // data is null for 'get' } - else + else { options.data = q; // data is the query string for 'post' + } var $form = this, callbacks = []; - if (options.resetForm) callbacks.push(function() { $form.resetForm(); }); - if (options.clearForm) callbacks.push(function() { $form.clearForm(); }); + if (options.resetForm) { + callbacks.push(function() { $form.resetForm(); }); + } + if (options.clearForm) { + callbacks.push(function() { $form.clearForm(); }); + } // perform a load on the target only if dataType is not provided if (!options.dataType && options.target) { var oldSuccess = options.success || function(){}; callbacks.push(function(data) { - $(options.target).html(data).each(oldSuccess, arguments); + var fn = options.replaceTarget ? 'replaceWith' : 'html'; + $(options.target)[fn](data).each(oldSuccess, arguments); }); } - else if (options.success) + else if (options.success) { callbacks.push(options.success); + } - options.success = function(data, status) { - for (var i=0, max=callbacks.length; i < max; i++) - callbacks[i].apply(options, [data, status, $form]); + options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg + var context = options.context || options; // jQuery 1.4+ supports scope context + for (var i=0, max=callbacks.length; i < max; i++) { + callbacks[i].apply(context, [data, status, xhr || $form, $form]); + } }; // are there files to upload? - var files = $('input:file', this).fieldValue(); - var found = false; - for (var j=0; j < files.length; j++) - if (files[j]) - found = true; - - var multipart = false; -// var mp = 'multipart/form-data'; -// multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); + var fileInputs = $('input:file', this).length > 0; + var mp = 'multipart/form-data'; + var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp); // options.iframe allows user to force iframe mode // 06-NOV-09: now defaulting to iframe mode if file input is detected - if ((files.length && options.iframe !== false) || options.iframe || found || multipart) { + if (options.iframe !== false && (fileInputs || options.iframe || multipart)) { // hack to fix Safari hang (thanks to Tim Molendijk for this) // see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d - if (options.closeKeepAlive) + if (options.closeKeepAlive) { $.get(options.closeKeepAlive, fileUpload); - else + } + else { fileUpload(); - } - else - $.ajax(options); + } + } + else { + $.ajax(options); + } // fire 'notify' event this.trigger('form-submit-notify', [this, options]); @@ -168,16 +180,17 @@ $.fn.ajaxSubmit = function(options) { function fileUpload() { var form = $form[0]; - if ($(':input[name=submit]', form).length) { - alert('Error: Form elements must not be named "submit".'); + if ($(':input[name=submit],:input[id=submit]', form).length) { + // if there is an input with a name or id of 'submit' then we won't be + // able to invoke the submit fn on the form (at least not x-browser) + alert('Error: Form elements must not have name or id of "submit".'); return; } - - var opts = $.extend({}, $.ajaxSettings, options); - var s = $.extend(true, {}, $.extend(true, {}, $.ajaxSettings), opts); - - var id = 'jqFormIO' + (new Date().getTime()); - var $io = $('