New Extension, Possible $() changes?

New Extension, Possible $() changes?


I'm working on a rather small extension to jQuery that has some major
implications. The goal of the extension is to be able to serialize
just a subsection of a form. I plan to accomplish this by imitating
the ".elements" property of a form object for any arbitrary DOM
element that descends from a form element.
There are two changes that would be in the area that is the core.
1. In jQuery.fn.serializeArray() rather than querying the node name,
query the existence of the .elements property
- return jQuery.nodeName(this, "form") ?
jQuery.makeArray(this.elements) : this;
+ return this.elements ? jQuery.makeArray(this.elements) : this;
2. This is the big one. In jQuery.fn.init( selector, context ) there
is no ability to do: $(DOMElement, context). Thoughts, or suggestions
about implementing that? So far I've come up with no solution that is
really scalable:
a. Traverse up from each form element in the form until hitting a
ceiling of either the document or the subsection.
b. Traverse down from the subsection, iterating through every node
looking for that particular form element.
I'd love to hear any thoughts about implementing this.
Nathan Hammond
***
Code:
serializeSubsection: function() {
this.map(function(){
var self = this,
form = this; // Not yet, but a good place to start.
// Traverse upward until we find the form.
while (!jQuery.nodeName(form, "form")) {
form = form.parentNode ? form.parentNode : this;
if (form == this) break;
}
// Get the array for the form elements.
// Filter it to only have the descendants of the subsection.
// Store it as the relevant HTMLCollection for the subsection
element.
this.elements =
jQuery(jQuery.makeArray(form.elements)).filter(function(i) {
return jQuery(this, self).length == 1; // $(DOMElement,
context) doesn't exist.
}).get();
});
return this.serializeArray();
}