Hi,
Ah right, that's fair enough. When I wrote that post I didn't realize
that you could simply pass a function reference into the each method.
Personally I prefer to take advantage of the slightly higher level
interfaces provided by Prototype to avoid possible difficulties in
future releases.
I did encounter one problem which was relatively simple to solve. If a
form, or input element is nested within the specified element
hierarchy, a JavaScript error is reported. By testing for the presence
of 'stopObserving' method, it is possible to determine whether that
method is appropriate on a per element basis:
Object.extend(Element.Methods, {
stopObservingNested: function(element) {
element.stopObserving();
element.descendants().each(function(element) {
if (element.stopObserving !== undefined)
element.stopObserving();
});
}
});
2008/10/3 kangax <[EMAIL PROTECTED]>:
>
> On Oct 2, 6:15 pm, "Lea Hayes" <[EMAIL PROTECTED]> wrote:
>> Or as puckpuck suggested with the 'descendants' method instead of the
>> CSS selector for greatly improved performance.
>
> `Element.descendants` uses `Element.select` internally. That's why I
> used `select` directly (to avoid an extra function call). `_each` is
> there to avoid try/catch which is not really needed as far as I can
> see. Also, passing `Event.stopObserving` as an iterator avoids an
> extra function : )
>
>>
>> Object.extend(Element.prototype, {
>> stopObservingNested: function() {
>> this.stopObserving();
>> this.descendants().each(function(el) {
>> el.stopObserving(); });
>> }
>> });
>>
>> I have tested the above, and it appears to work fine.
>>
>> Best regards,
>> Lea Hayes
>
> --
> kangax
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---