From 81b67318aa45ac086cf5e128ec70f25aea2744bc Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 12 Aug 2011 14:05:12 +0000 Subject: [PATCH] Updating jquery.form from upstream * Source: https://github.com/malsup/form/commit/e77e287c8024d200909a7b4f4a1224503814e660 --- resources/jquery/jquery.form.js | 310 ++++++++++++++++++++++---------- 1 file changed, 215 insertions(+), 95 deletions(-) diff --git a/resources/jquery/jquery.form.js b/resources/jquery/jquery.form.js index 53c078f9f5..fdcdd15ac3 100644 --- a/resources/jquery/jquery.form.js +++ b/resources/jquery/jquery.form.js @@ -1,6 +1,6 @@ /*! * jQuery Form Plugin - * version: 2.52 (07-DEC-2010) + * version: 2.84 (12-AUG-2011) * @requires jQuery v1.3.2 or later * * Examples and documentation at: http://malsup.com/jquery/form/ @@ -8,7 +8,7 @@ * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl.html */ -(function($) { +;(function($) { /* Usage Note: @@ -49,22 +49,26 @@ $.fn.ajaxSubmit = function(options) { log('ajaxSubmit: skipping submit process - no element selected'); return this; } + + var method, action, url, $form = this; if (typeof options == 'function') { options = { success: options }; } - var action = this.attr('action'); - var url = (typeof action === 'string') ? $.trim(action) : ''; + method = this.attr('method'); + action = this.attr('action'); + url = (typeof action === 'string') ? $.trim(action) : ''; + url = url || window.location.href || ''; if (url) { // clean url (don't include hash vaue) url = (url.match(/^([^#]+)/)||[])[1]; } - url = url || window.location.href || ''; options = $.extend(true, { url: url, - type: this.attr('method') || 'GET', + success: $.ajaxSettings.success, + type: method || 'GET', iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank' }, options); @@ -87,7 +91,7 @@ $.fn.ajaxSubmit = function(options) { if (options.data) { options.extraData = options.data; for (n in options.data) { - if(options.data[n] instanceof Array) { + if( $.isArray(options.data[n]) ) { for (var k in options.data[n]) { a.push( { name: n, value: options.data[n][k] } ); } @@ -123,7 +127,7 @@ $.fn.ajaxSubmit = function(options) { options.data = q; // data is the query string for 'post' } - var $form = this, callbacks = []; + var callbacks = []; if (options.resetForm) { callbacks.push(function() { $form.resetForm(); }); } @@ -161,14 +165,20 @@ $.fn.ajaxSubmit = function(options) { // 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) { - $.get(options.closeKeepAlive, fileUpload); + $.get(options.closeKeepAlive, function() { fileUpload(a); }); } else { - fileUpload(); + fileUpload(a); } } else { - $.ajax(options); + // IE7 massage (see issue 57) + if ($.browser.msie && method == 'get') { + var ieMeth = $form[0].getAttribute('method'); + if (typeof ieMeth === 'string') + options.type = ieMeth; + } + $.ajax(options); } // fire 'notify' event @@ -177,8 +187,17 @@ $.fn.ajaxSubmit = function(options) { // private function for handling file uploads (hat tip to YAHOO!) - function fileUpload() { - var form = $form[0]; + function fileUpload(a) { + var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle; + var useProp = !!$.fn.prop; + + if (a) { + // ensure that every serialized input is still enabled + for (i=0; i < a.length; i++) { + el = $(form[a[i].name]); + el[ useProp ? 'prop' : 'attr' ]('disabled', false); + } + } 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 @@ -187,23 +206,25 @@ $.fn.ajaxSubmit = function(options) { return; } - var s = $.extend(true, {}, $.ajaxSettings, options); + s = $.extend(true, {}, $.ajaxSettings, options); s.context = s.context || s; - var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id; - window[fn] = function() { - var f = $io.data('form-plugin-onload'); - if (f) { - f(); - window[fn] = undefined; - try { delete window[fn]; } catch(e){} - } - }; - var $io = $('