/* * jquery form plugin * version: 2.12 (06/07/2008) */ (function($) { $.fn.ajaxsubmit = function(options) { // fast fail if nothing selected (http://dev.jquery.com/ticket/2752) if (!this.length) { log('ajaxsubmit: skipping submit process - no element selected'); return this; } if (typeof options == 'function') options = { success: options }; options = $.extend({ url: this.attr('action') || window.location.tostring(), type: this.attr('method') || 'get' }, options || {}); var veto = {}; this.trigger('form-pre-serialize', [this, options, veto]); if (veto.veto) { log('ajaxsubmit: submit vetoed via form-pre-serialize trigger'); 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] } ); } // give pre-submit callback an opportunity to abort the submit if (options.beforesubmit && options.beforesubmit(a, this, options) === false) { log('ajaxsubmit: submit aborted via beforesubmit callback'); return this; } // fire vetoable 'validate' event this.trigger('form-submit-validate', [a, this, options, veto]); if (veto.veto) { log('ajaxsubmit: submit vetoed via form-submit-validate trigger'); return this; } var q = $.param(a); if (options.type.touppercase() == 'get') { options.url += (options.url.indexof('?') >= 0 ? '&' : '?') + q; options.data = null; // data is null for 'get' } 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(); }); // 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); }); } 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](data, status, $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; if (options.iframe || found) { if ($.browser.safari && options.closekeepalive) $.get(options.closekeepalive, fileupload); else fileupload(); } else $.ajax(options); // fire 'notify' event this.trigger('form-submit-notify', [this, options]); return this; // private function for handling file uploads (hat tip to yahoo!) function fileupload() { var form = $form[0]; //if ($(':input[@name=submit]', form).length) { //alert('error: form elements must not be named "submit".'); //return; //} var opts = $.extend({}, $.ajaxsettings, options); var id = 'jqformio' + (new date().gettime()); var $io = $('