2006-03-22 03:33:07 +00:00
|
|
|
// AJAX Plugin
|
|
|
|
// Docs Here:
|
|
|
|
// http://jquery.com/docs/ajax/
|
|
|
|
|
|
|
|
if ( typeof XMLHttpRequest == 'undefined' && typeof window.ActiveXObject == 'function') {
|
2006-05-16 22:15:05 +00:00
|
|
|
XMLHttpRequest = function() {
|
2006-05-16 16:18:52 +00:00
|
|
|
return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') >= 0) ?
|
2006-03-23 21:13:20 +00:00
|
|
|
"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
|
|
|
|
};
|
2006-03-22 03:33:07 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 16:18:52 +00:00
|
|
|
// Counter for holding the active query's
|
|
|
|
$.xmlActive=0;
|
|
|
|
|
2006-03-22 03:33:07 +00:00
|
|
|
$.xml = function( type, url, data, ret ) {
|
2006-06-16 02:43:04 +00:00
|
|
|
if ( !url ) {
|
|
|
|
ret = type.onComplete;
|
|
|
|
var onSuccess = type.onSuccess;
|
|
|
|
var onError = type.onError;
|
|
|
|
data = type.data;
|
|
|
|
url = type.url;
|
|
|
|
type = type.type;
|
|
|
|
}
|
|
|
|
|
2006-03-23 21:13:20 +00:00
|
|
|
var xml = new XMLHttpRequest();
|
2006-03-22 03:33:07 +00:00
|
|
|
|
2006-03-23 21:13:20 +00:00
|
|
|
if ( xml ) {
|
2006-05-16 16:18:52 +00:00
|
|
|
// Open the socket
|
2006-03-23 21:13:20 +00:00
|
|
|
xml.open(type || "GET", url, true);
|
2006-05-20 09:46:41 +00:00
|
|
|
if ( data )
|
2006-03-23 21:13:20 +00:00
|
|
|
xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
2006-03-22 03:33:07 +00:00
|
|
|
|
2006-05-16 16:18:52 +00:00
|
|
|
// Set header so calling script knows that it's an XMLHttpRequest
|
|
|
|
xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
|
|
|
|
2006-06-16 02:43:04 +00:00
|
|
|
/* Borrowed from Prototype:
|
|
|
|
* Force "Connection: close" for Mozilla browsers to work around
|
2006-05-16 16:18:52 +00:00
|
|
|
* a bug where XMLHttpReqeuest sends an incorrect Content-length
|
|
|
|
* header. See Mozilla Bugzilla #246651.
|
|
|
|
*/
|
2006-05-20 09:46:41 +00:00
|
|
|
if ( xml.overrideMimeType )
|
2006-05-16 16:18:52 +00:00
|
|
|
xml.setRequestHeader('Connection', 'close');
|
|
|
|
|
2006-03-27 07:08:32 +00:00
|
|
|
xml.onreadystatechange = function() {
|
2006-05-20 09:46:41 +00:00
|
|
|
// Socket is openend
|
|
|
|
if ( xml.readyState == 1 ) {
|
|
|
|
// Increase counter
|
|
|
|
$.xmlActive++;
|
|
|
|
|
|
|
|
// Show loader if needed
|
|
|
|
if ( ($.xmlActive >= 1) && ($.xmlCreate) )
|
|
|
|
$.xmlCreate();
|
|
|
|
}
|
2006-05-16 16:18:52 +00:00
|
|
|
|
2006-05-20 09:46:41 +00:00
|
|
|
// Socket is closed and data is available
|
|
|
|
if ( xml.readyState == 4 ) {
|
2006-05-16 16:18:52 +00:00
|
|
|
// Decrease counter
|
|
|
|
$.xmlActive--;
|
|
|
|
|
|
|
|
// Hide loader if needed
|
2006-05-20 09:46:41 +00:00
|
|
|
if ( ($.xmlActive <= 0) && ($.xmlDestroy) ) {
|
|
|
|
$.xmlDestroy();
|
|
|
|
$.xmlActive = 0
|
2006-05-16 16:18:52 +00:00
|
|
|
}
|
2006-05-20 09:46:41 +00:00
|
|
|
|
2006-06-16 02:43:04 +00:00
|
|
|
if ( xml.status && xml.status >= 200 && xml.status < 300 ) {
|
|
|
|
if ( onSuccess )
|
|
|
|
onSuccess( xml );
|
|
|
|
} else if ( onError ) {
|
|
|
|
onError( xml );
|
|
|
|
}
|
|
|
|
|
2006-05-20 09:46:41 +00:00
|
|
|
// Process result
|
|
|
|
if ( ret )
|
|
|
|
ret(xml);
|
2006-03-27 07:08:32 +00:00
|
|
|
}
|
|
|
|
};
|
2006-03-22 03:33:07 +00:00
|
|
|
|
2006-05-20 09:46:41 +00:00
|
|
|
xml.send(data)
|
2006-03-23 21:13:20 +00:00
|
|
|
}
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.httpData = function(r,type) {
|
2006-03-23 21:13:20 +00:00
|
|
|
return r.getResponseHeader("content-type").indexOf("xml") > 0 || type == "xml" ?
|
|
|
|
r.responseXML : r.responseText;
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.get = function( url, ret, type ) {
|
2006-03-23 21:13:20 +00:00
|
|
|
$.xml( "GET", url, null, function(r) {
|
2006-05-16 22:15:05 +00:00
|
|
|
if ( ret ) { ret( $.httpData(r,type) ); }
|
2006-03-23 21:13:20 +00:00
|
|
|
});
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.getXML = function( url, ret ) {
|
2006-03-23 21:13:20 +00:00
|
|
|
$.get( url, ret, "xml" );
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.post = function( url, data, ret, type ) {
|
2006-03-23 21:13:20 +00:00
|
|
|
$.xml( "POST", url, $.param(data), function(r) {
|
2006-05-16 22:15:05 +00:00
|
|
|
if ( ret ) { ret( $.httpData(r,type) ); }
|
2006-03-23 21:13:20 +00:00
|
|
|
});
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.postXML = function( url, data, ret ) {
|
2006-03-23 21:13:20 +00:00
|
|
|
$.post( url, data, ret, "xml" );
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.param = function(a) {
|
2006-03-23 21:13:20 +00:00
|
|
|
var s = [];
|
2006-05-16 16:18:52 +00:00
|
|
|
if (a && typeof a == 'object' && a.constructor == Array) {
|
2006-05-16 22:15:05 +00:00
|
|
|
for ( var i=0; i < a.length; i++ ) {
|
|
|
|
s[s.length] = a[i].name + "=" + encodeURIComponent( a[i].value );
|
|
|
|
}
|
2006-05-16 16:18:52 +00:00
|
|
|
} else {
|
2006-05-16 22:15:05 +00:00
|
|
|
for ( var j in a ) {
|
|
|
|
s[s.length] = j + "=" + encodeURIComponent( a[j] );
|
|
|
|
}
|
2006-05-16 16:18:52 +00:00
|
|
|
}
|
2006-03-23 21:13:20 +00:00
|
|
|
return s.join("&");
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$.fn.load = function(a,o,f) {
|
2006-03-23 21:13:20 +00:00
|
|
|
// Arrrrghhhhhhhh!!
|
|
|
|
// I overwrote the event plugin's .load
|
|
|
|
// this won't happen again, I hope -John
|
2006-05-16 22:15:05 +00:00
|
|
|
if ( a && a.constructor == Function ) {
|
2006-03-23 21:13:20 +00:00
|
|
|
return this.bind("load", a);
|
2006-05-16 22:15:05 +00:00
|
|
|
}
|
2006-03-22 03:33:07 +00:00
|
|
|
|
2006-03-23 21:13:20 +00:00
|
|
|
var t = "GET";
|
|
|
|
if ( o && o.constructor == Function ) {
|
|
|
|
f = o;
|
|
|
|
o = null;
|
|
|
|
}
|
2006-06-05 16:19:03 +00:00
|
|
|
if (typeof o !== 'undefined') {
|
2006-03-23 21:13:20 +00:00
|
|
|
o = $.param(o);
|
|
|
|
t = "POST";
|
|
|
|
}
|
|
|
|
var self = this;
|
2006-06-09 14:49:09 +00:00
|
|
|
$.xml(t,a,o,function(res){
|
2006-06-08 17:31:57 +00:00
|
|
|
// Assign it and execute all scripts
|
2006-06-09 14:49:09 +00:00
|
|
|
self.html(res.responseText).find("script").each(function(){
|
2006-06-09 15:36:06 +00:00
|
|
|
try { eval( this.text || this.textContent || this.innerHTML || ""); } catch(e){}
|
2006-03-23 21:13:20 +00:00
|
|
|
});
|
2006-06-08 17:31:57 +00:00
|
|
|
|
|
|
|
// Callback function
|
|
|
|
if (f && f.constructor == Function)
|
2006-06-09 14:49:09 +00:00
|
|
|
f(res.responseText);
|
2006-03-23 21:13:20 +00:00
|
|
|
});
|
|
|
|
return this;
|
2006-03-22 03:33:07 +00:00
|
|
|
};
|
2006-05-16 16:18:52 +00:00
|
|
|
|
|
|
|
/**
|
2006-06-08 17:31:57 +00:00
|
|
|
* Initial frontend function to submit form variables. This function
|
|
|
|
* is for registering coordinates, in the case of an image being used
|
|
|
|
* as the submit element, and sets up an event to listen and wait for
|
|
|
|
* a form submit click. It then calls any following chained functions
|
|
|
|
* to actually gather the variables and submit them.
|
|
|
|
*
|
|
|
|
* Usage examples, when used with getForm().putForm():
|
|
|
|
*
|
|
|
|
* 1. Just eval the results returned from the backend.
|
|
|
|
* $('#form-id').form();
|
|
|
|
*
|
|
|
|
* 2. Render backend results directly to target ID (expects (x)HTML).
|
|
|
|
* $('#form-id').form('#target-id');
|
|
|
|
*
|
|
|
|
* 3. Submit to backend URL (form action) then call this function.
|
|
|
|
* $('#form-id').form(post_callback);
|
|
|
|
*
|
|
|
|
* 4. Load target ID with backend results then call a function.
|
|
|
|
* $('#form-id').form('#target-id', null, post_callback);
|
|
|
|
*
|
|
|
|
* 5. Call a browser function (for validation) and then (optionally)
|
|
|
|
* load server results to target ID.
|
|
|
|
* $('#form-id').form('#target-id', pre_callback);
|
|
|
|
*
|
|
|
|
* 6. Call validation function first then load server results to
|
|
|
|
* target ID and then also call a browser function.
|
|
|
|
* $('#form-id').form('#target-id', pre_callback, post_callback);
|
|
|
|
*
|
|
|
|
* @param target arg for the target id element to render
|
|
|
|
* @param pre_cb callback function before submission
|
|
|
|
* @param post_cb callback after any results are returned
|
|
|
|
* @return "this" object
|
|
|
|
* @see getForm(), putForm()
|
|
|
|
* @author Mark Constable (markc@renta.net)
|
|
|
|
* @author G. vd Hoven, Mike Alsup, Sam Collett
|
|
|
|
* @version 20060606
|
2006-05-16 16:18:52 +00:00
|
|
|
*/
|
2006-06-08 17:31:57 +00:00
|
|
|
$.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;
|
|
|
|
});
|
|
|
|
};
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
if (!ok[this.nodeName.toUpperCase()])
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
return;
|
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
var par = this.parentNode;
|
|
|
|
var p = par.nodeName.toUpperCase();
|
|
|
|
if ((p == 'SELECT' || p == 'OPTGROUP') && !this.selected)
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
return;
|
2006-05-17 18:04:46 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
var n = this.name || par.name;
|
|
|
|
if (!n && p == 'OPTGROUP' && (par = par.parentNode))
|
|
|
|
n = par.name;
|
2006-06-02 14:27:25 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
if (n == undefined)
|
|
|
|
return;
|
2006-06-01 16:40:37 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
a.push({name: n, value: this.value});
|
2006-05-17 18:04:46 +00:00
|
|
|
});
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
this.vars = a;
|
$.fn.formValues;
Gets form values and creates a key=>value array of the found values.
What's new?
- Only does this for ENABLED elements.
- Keeps the same order of the form.
- Optionally adds the button which is clicked (marks that name with an 'x' in the list)
example: $('#frmLogin').formValues('oButton');
$.fn.update (PREVIOUSLY: $.update, so beware!!!!)
Calls sURL with sAction (method) and sends the aValues. Puts the results from that call in the jQuery object and calls fCallback if provided.
What's new?
- Renamed $.update to $.fn.update, since it is more obvious to call $('someJQueryObject').update(...) then $.update($('someJQueryObject'), ...). It's also more jQuery-ish
- Added the method you want to use, since i used post before, now you can select between either GET or POST.
example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
$.fn.serialize
Calls the form's action with the correct method and the serialized values. Optionally adds the button which is clicked if you provide it. When there are results, the fCallback function is called.
What's new?
- The entire function
example: $('someForm').serialize('sButton', 'fCallback');
2006-05-31 11:14:21 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
return this;
|
|
|
|
}
|
2006-05-16 16:18:52 +00:00
|
|
|
|
|
|
|
/**
|
2006-06-08 17:31:57 +00:00
|
|
|
* Final form submission plugin usually used in conjunction with
|
|
|
|
* form() and getForm(). If a second argument is a valid function
|
|
|
|
* then it will be called before the form vars are sent to the
|
|
|
|
* backend. If this pre-submit function returns exactly "false"
|
|
|
|
* then it will abort further processing otherwise the process
|
|
|
|
* will continue according to the first and third arguments.
|
|
|
|
*
|
|
|
|
* If the first argument is a function, and it exists, then the form
|
|
|
|
* values will be submitted and that callback function called. If
|
|
|
|
* the first argument is a string value then the "load()" plugin
|
|
|
|
* will be called which will populate the innerHTML of the indicated
|
|
|
|
* element and a callback will be called if there is third argument.
|
|
|
|
* If there are no arguments then the form values are submitted with
|
|
|
|
* an additional variable (evaljs=1) which indicates to the backend
|
|
|
|
* to to prepare the returned results for evaluation, ie; the result
|
|
|
|
* needs to be valid javascript all on a single line.
|
|
|
|
*
|
|
|
|
* Usage example:
|
|
|
|
*
|
|
|
|
* $.fn.myvars = function() {
|
|
|
|
* this.vars = [];
|
|
|
|
* for (var i in this) {
|
|
|
|
* if (this[i] instanceof Function || this[i] == null) continue;
|
|
|
|
* this.vars.push({name: i, value: this[i].length});
|
|
|
|
* }
|
|
|
|
* return this;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* precb = function(vars) {
|
|
|
|
* return confirm('Submit these values?\n\n'+$.param(vars));
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* $('*').myvars().putForm('#mytarget',precb,null,'myhandler.php');
|
|
|
|
*
|
|
|
|
* @param target arg for the target id element to render
|
|
|
|
* @param pre_cb callback function before submission
|
|
|
|
* @param post_cb callback after any results are returned
|
|
|
|
* @param url form action override
|
|
|
|
* @param mth form method override
|
|
|
|
* @return "this" object
|
|
|
|
* @see form(), getForm(), load(), xml()
|
|
|
|
* @author Mark Constable (markc@renta.net)
|
|
|
|
* @author G. vd Hoven, Mike Alsup, Sam Collett
|
|
|
|
* @version 20060606
|
2006-05-16 16:18:52 +00:00
|
|
|
*/
|
2006-06-08 17:31:57 +00:00
|
|
|
$.fn.putForm = function(target, pre_cb, post_cb, url, mth) {
|
|
|
|
if (pre_cb && pre_cb.constructor == Function)
|
|
|
|
if (pre_cb(this.vars) === false)
|
|
|
|
return;
|
2006-05-16 16:18:52 +00:00
|
|
|
|
2006-06-08 17:31:57 +00:00
|
|
|
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) {
|
|
|
|
$(target).load(url, this.vars, post_cb);
|
|
|
|
} else {
|
|
|
|
this.vars.push({name: 'evaljs', value: 1});
|
2006-06-09 15:36:06 +00:00
|
|
|
$.xml(mth, url, $.param(this.vars), function(r) { eval(r.responseText); });
|
2006-06-08 17:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|