X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=form%2Fform.js;h=13b513b4ca414dbf1bfe987e0b099877b781e600;hb=db85661c055cde53ba3c8a104a5c9bc9143ac74c;hp=d1a7ba798f5570fb9b57fb0ad1118e5d7272080d;hpb=ce6af8e8894b14c7b2c41b64a097bc49acc73b19;p=jquery.git diff --git a/form/form.js b/form/form.js index d1a7ba7..13b513b 100644 --- a/form/form.js +++ b/form/form.js @@ -37,27 +37,26 @@ * @param url form action override * @param mth form method override * @return "this" object - * @see ajaxForm(), serialize(), load(), $.xml() + * @see ajaxForm(), serialize(), load(), $.ajax() * @author Mark Constable (markc@renta.net) * @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig */ $.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) { if ( !this.vars ) this.serialize(); - if (pre_cb && pre_cb.constructor == Function) - if (pre_cb(this.vars) === false) return; + if (pre_cb && pre_cb.constructor == Function && pre_cb(this.vars) === false) return; var f = this.get(0); var url = url || f.action || ''; var mth = mth || f.method || 'POST'; - if (target && target.constructor == Function) { - $.xml(mth, url, $.param(this.vars), target); - } else if (target && target.constructor == String) { + if (target && target.constructor == Function) + $.ajax(mth, url, $.param(this.vars), target); + else if (target && target.constructor == String) $(target).load(url, this.vars, post_cb); - } else { + else { this.vars.push({name: 'evaljs', value: 1}); - $.xml(mth, url, $.param(this.vars), function(r) { + $.ajax(mth, url, $.param(this.vars), function(r) { eval(r.responseText); }); } @@ -104,13 +103,14 @@ $.fn.ajaxSubmit = function(target, post_cb, pre_cb, url, mth) { * @param post_cb callback after any results are returned * @param pre_cb callback function before submission * @return the jQuery Object + * @type jQuery * @see serialize(), ajaxSubmit() * @author Mark Constable (markc@renta.net) * @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig */ $.fn.ajaxForm = function(target, post_cb, pre_cb) { return this.each(function(){ - $('input[@type="submit"],input[@type="image"]', this).click(function(ev){ + $("input[@type=submit],input[@type=image]", this).click(function(ev){ this.form.clicked = this; if (ev.offsetX != undefined) { this.form.clicked_x = ev.offsetX; @@ -121,7 +121,6 @@ $.fn.ajaxForm = function(target, post_cb, pre_cb) { } }); }).submit(function(e){ - e.preventDefault(); $(this).ajaxSubmit(target, post_cb, pre_cb); return false; }); @@ -138,6 +137,7 @@ $.fn.ajaxForm = function(target, post_cb, pre_cb) { * $.param( $("form").formdata() ); * * @return An array of name/value pairs representing the form + * @type Array * @see serialize() # @author John Resig */ @@ -165,6 +165,7 @@ $.fn.formdata = function(){ * $('#form-id').serialize().some_other_plugin(); * * @return the jQuery Object + * @return jQuery * @see ajaxForm(), ajaxSubmit() * @author Mark Constable (markc@renta.net) * @author G. vd Hoven, Mike Alsup, Sam Collett, John Resig @@ -174,34 +175,21 @@ $.fn.serialize = function() { var ok = {INPUT:true, TEXTAREA:true, OPTION:true}; $('*', this).each(function() { - if (this.disabled || this.type == 'reset' || - (this.type == 'checkbox' && !this.checked) || - (this.type == 'radio' && !this.checked)) return; - - if (this.type == 'submit' || this.type == 'image') { - if (this.form.clicked != this) return; - - if (this.type == 'image') { - if (this.form.clicked_x) { - a.push({name: this.name+'_x', value: this.form.clicked_x}); - a.push({name: this.name+'_y', value: this.form.clicked_y}); - return; - } - } - } - - if (!ok[this.nodeName.toUpperCase()]) - return; - var par = this.parentNode; var p = par.nodeName.toUpperCase(); - if ((p == 'SELECT' || p == 'OPTGROUP') && !this.selected) return; + var n = this.name || p == 'OPTGROUP' && par.parentNode.name || p == 'SELECT' && par.name || this.id; - var n = this.name || par.name; - if (!n && p == 'OPTGROUP' && (par = par.parentNode)) - n = par.name; + if ( !n || this.disabled || this.type == 'reset' || + (this.type == 'checkbox' || this.type == 'radio') && !this.checked || + !ok[this.nodeName.toUpperCase()] || + (this.type == 'submit' || this.type == 'image') && this.form.clicked != this || + (p == 'SELECT' || p == 'OPTGROUP') && !this.selected ) return; - if (n == undefined) return; + if (this.type == 'image' && this.form.clicked_x) + return a.push( + {name: this.name+'_x', value: this.form.clicked_x}, + {name: this.name+'_y', value: this.form.clicked_y} + ); a.push({name: n, value: this.value}); });