John Beppu schrieb:
Could you briefly explain what the jquery.delegate plugin does?'
(I'm curious.)
I wrote that for the validation plugin. It allows me to listen for focus
and blur events on the form, which normally doesn't work because focus
and blur don't bubble.
It also simplifies binding event handlers for event delegatation, via
the delegate-plugin-method. The relevant code from the validation plugin:
function delegate(event) {
var validator = jQuery.data(this[0].form, "validator");
validator.settings["on" + event.type] && validator.settings["on" +
event.type].call(validator, this[0] );
}
jQuery(this.currentForm)
.delegate("focusin focusout keyup", ":text, :password, :file,
select, textarea", delegate)
.delegate("click", ":radio, :checkbox", delegate);
Another usage example is in the dynamic-totals demo (
http://dev.jquery.com/view/trunk/plugins/validate/demo/dynamic-totals.html
):
$("#orderform").delegate("keyup", "input.quantity", function(event) {
var totals = 0;
$("#orderitems input.quantity").each(function() {
totals += +this.value;
});
$("#totals").attr("value", totals).valid();
});
Here its used to listen for keyup events on any "input.quantity" and
update the total-field accordingly and checking its validity at the end.
Jörn