};
}
-//
// Counter for holding the active query's
$.xmlActive=0;
var xml = new XMLHttpRequest();
if ( xml ) {
- //
- // Increase the query counter
- $.xmlActive++;
-
- //
- // Show loader if needed
- if ($.xmlCreate) {
- $.xmlCreate();
- }
-
- //
// Open the socket
xml.open(type || "GET", url, true);
-
- if ( data ) {
+ if ( data )
xml.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- }
- //
// Set header so calling script knows that it's an XMLHttpRequest
xml.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
* a bug where XMLHttpReqeuest sends an incorrect Content-length
* header. See Mozilla Bugzilla #246651.
*/
- if ( xml.overrideMimeType ) {
+ if ( xml.overrideMimeType )
xml.setRequestHeader('Connection', 'close');
- }
xml.onreadystatechange = function() {
- if ( xml.readyState == 4 ) {
- if ( ret ) { ret(xml); }
+ // Socket is openend
+ if ( xml.readyState == 1 ) {
+ // Increase counter
+ $.xmlActive++;
+
+ // Show loader if needed
+ if ( ($.xmlActive >= 1) && ($.xmlCreate) )
+ $.xmlCreate();
+ }
- //
+ // Socket is closed and data is available
+ if ( xml.readyState == 4 ) {
// Decrease counter
$.xmlActive--;
- //
// Hide loader if needed
- if ($.xmlActive <= 0) {
- if ($.xmlDestroy) {
- $.xmlDestroy();
- }
+ if ( ($.xmlActive <= 0) && ($.xmlDestroy) ) {
+ $.xmlDestroy();
+ $.xmlActive = 0
}
+
+ // Process result
+ if ( ret )
+ ret(xml);
}
};
- xml.send(data);
+ xml.send(data)
}
};
h = h.responseText;
self.html(h).find("script").each(function(){
try {
- eval( this.text || this.textContent || this.innerHTML );
+ $.eval( this.text || this.textContent || this.innerHTML );
} catch(e){}
});
if(f){f(h);}
};
/**
- * function: $.fn.formValues
- * usage: $('#frmLogin').formValues()
- * docs: Gets the form values and creates a key=>value array of the found values (only for ENABLED elements!)
+ * name: $.fn.formValues
+ * example: $('#frmLogin').formValues('sButton')
+ * docs: Gets form values and creates a key=>value array of the found values.
+ * Optionally adds the button which is clicked if you provide it.
+ * Only does this for ENABLED elements in the order of the form.
*/
-$.fn.formValues = function() {
+$.fn.formValues = function(sButton) {
var a = [];
- this.find("input[@type='submit'],input[@type='hidden'],textarea,input[@checked],input[@type='password'],input[@type='text'],option[@selected]").filter(":enabled").each(function() {
- o = {};
- o.name = this.name || this.id || this.parentNode.name || this.parentNode.id;
- o.value = this.value;
- a.push(o);
+ var elp = {INPUT:true, TEXTAREA:true, OPTION:true};
+
+ // Loop the shite
+ $('*', this).each(function() {
+ // Skip disabled elements
+ if (this.disabled)
+ return;
+
+ // Skip elements not of the types in elp
+ if (!elp[this.tagName.toUpperCase()])
+ return;
+
+ // Skip submit buttons and image elements
+ if ((this.type == 'submit') || (this.type == 'image'))
+ return;
+
+
+ // Skip non-selected options
+ var sP = this.parentNode.nodeName.toUpperCase();
+ if (((sP == 'SELECT') || (sP == 'OPTGROUP')) && (!this.selected))
+ return;
+
+ // Skip non-checked nodes
+ if (((this.type == 'radio') || (this.type == 'checkbox')) && (!this.checked))
+ return;
+
+ // If we come here, everything is fine
+ var sN = this.name || this.id || this.parentNode.name || this.parentNode.id;
+ var sV = this.value;
+ if ((!sN) && (sP == 'OPTGROUP'))
+ sN = this.parentNode.parentNode.name || this.parentNode.parentNode.id;
+
+ // Add the data
+ a.push({ name: sN, value: sV });
+ });
+
+ // Add submit button if needed
+ if (sButton && (sButton !== null)) {
+ var el = $(sButton).get(0);
+ a.push({
+ name: el.name || el.id || el.parentNode.name || el.parentNode.id,
+ value: el.value
});
+ }
+
+ // Done
return a;
};
/**
- * function: $.update
- * usage: $.update('someJQueryObject', 'someurl', 'array');
- * docs: Mimics the ajaxUpdater from prototype. Posts the key=>value array to the url and
- * puts the results from that call in the jQuery object specified.
- * --> If you set the blnNoEval to true, the script tags are NOT evaluated.
+ * name: $.fn.update
+ * example: $('someJQueryObject').update('sURL', 'sAction', 'aValues', 'fCallback');
+ * docs: Calls sURL with sAction and sends the aValues
+ * Puts the results from that call in the jQuery object and calls fCallback
*/
-$.update = function(objElement, strURL, arrValues, fncCallback) {
- $.post(strURL, arrValues, function(strHTML) {
- //
- // Update the element with the new HTML
- objElement.html(strHTML);
-
- //
- // Evaluate the scripts
- objElement.html(strHTML).find("script").each(function(){
- try { eval( this.text || this.textContent || this.innerHTML ); } catch(e){}
- });
+$.fn.update = function(sURL, sMethod, aValues, fCallback) {
+ var el = this;
+
+ // Process
+ $.xml(
+ sMethod || "GET",
+ sURL || "",
+ $.param(aValues),
+ function(sResult) {
+ sResult = $.httpData(sResult);
+
+ // Update the element with the new HTML
+ el.html(sResult);
+
+ // Evaluate the scripts AFTER this (so you can allready modify the new HTML!)
+ el.html(sResult).find("script").each(function(){
+ try { $.eval( this.text || this.textContent || this.innerHTML ); } catch(e) { }
+ });
+
+ // And call the callback handler :)
+ if (fCallback && (fCallback.constructor == Function))
+ fCallback();
+ }
+ );
+};
- //
- // Callback handler
- if (fncCallback) { fncCallback(); }
- });
+/**
+ * name: $.fn.serialize
+ * example: $('someJQueryObject').serialize('sButton', 'fCallback');
+ * docs: 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.
+ */
+$.fn.serialize = function(sButton, fCallback) {
+ var el = this.get(0);
+
+ // Process
+ $.xml(
+ el.method || "GET",
+ el.action || "",
+ $.param(this.formValues(sButton)),
+ function(sResult) {
+ if (fCallback && (fCallback.constructor == Function))
+ fCallback($.httpData(sResult));
+ }
+ );
};