From beb75371fa2091320bbe761c156efa86cf280f4d Mon Sep 17 00:00:00 2001 From: Julian Seidenberg Date: Thu, 24 Feb 2011 17:47:34 +1300 Subject: [PATCH] BUGFIX: update jquery form to latest version --- thirdparty/jquery-form/.piston.yml | 2 +- thirdparty/jquery-form/jquery.form.js | 408 +++++++++++++++++--------- 2 files changed, 269 insertions(+), 141 deletions(-) diff --git a/thirdparty/jquery-form/.piston.yml b/thirdparty/jquery-form/.piston.yml index fa6d4eee5..b137baa3f 100644 --- a/thirdparty/jquery-form/.piston.yml +++ b/thirdparty/jquery-form/.piston.yml @@ -1,7 +1,7 @@ --- format: 1 handler: - commit: 1f9901ad56ba458c8db0bffb759dbb65921891ae + commit: 317312dbb96538297b540be19e42533c4baea6ec branch: master lock: false repository_class: Piston::Git::Repository diff --git a/thirdparty/jquery-form/jquery.form.js b/thirdparty/jquery-form/jquery.form.js index be8c0b6bf..14e14572a 100644 --- a/thirdparty/jquery-form/jquery.form.js +++ b/thirdparty/jquery-form/jquery.form.js @@ -1,6 +1,6 @@ /*! * jQuery Form Plugin - * version: 2.43 (12-MAR-2010) + * version: 2.63 (29-JAN-2011) * @requires jQuery v1.3.2 or later * * Examples and documentation at: http://malsup.com/jquery/form/ @@ -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,12 +119,17 @@ $.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) { @@ -128,37 +139,37 @@ $.fn.ajaxSubmit = function(options) { $(options.target)[fn](data).each(oldSuccess, arguments); }); } - else if (options.success) + else if (options.success) { callbacks.push(options.success); + } options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg - for (var i=0, max=callbacks.length; i < max; i++) - callbacks[i].apply(options, [data, status, xhr || $form, $form]); + 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]); @@ -169,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 = $('