+$.fn.form = function(target, pre_cb, post_cb) {
+ $('input[@type="submit"],input[@type="image"]', this).click(function(ev){
+ this.form.clicked = this;
+ if (ev.offsetX != undefined) {
+ this.form.clicked_x = ev.offsetX;
+ this.form.clicked_y = ev.offsetY;
+ } else {
+ this.form.clicked_x = ev.pageX - this.offsetLeft;
+ this.form.clicked_y = ev.pageY - this.offsetTop;
+ }
+ });
+ this.submit(function(e){
+ e.preventDefault();
+ $(this).getForm().putForm(target, pre_cb, post_cb);
+ return this;
+ });
+};
+
+/**
+ * This function gathers form element variables into an array that
+ * is embedded into the current "this" variable as "this.vars". It
+ * is normally used in conjunction with form() and putForm() but can
+ * be used standalone as long as an image is not used for submission.
+ *
+ * Standalone usage examples:
+ *
+ * 1. Gather form vars and return array to LHS variable.
+ * var myform = $('#form-id').getForm();
+ *
+ * 2. Provide a serialized URL-ready string (after 1. above).
+ * var mystring = $.param(myform.vars);
+ *
+ * 3. Gather form vars and send to RHS plugin via "this.vars".
+ * $('#form-id').getForm().some_other_plugin();
+ *
+ * @return "this" object
+ * @see form(), putForm()
+ * @author Mark Constable (markc@renta.net)
+ * @author G. vd Hoven, Mike Alsup, Sam Collett
+ * @version 20060606
+ */
+$.fn.getForm = function() {
+ var a = [];
+ 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;
+ }
+ }
+ }