[Proto-Scripty] Re: lastDescendant()?

2008-09-11 Thread beachcomber

Thank you both for your suggestions.

I think for my purposes (a simple image gallery with next prev -
looping from last to first and vice versa) then kangax's suggestion is
all that I need at this time.

I will certainly look indepth at Matt's solution as there are some
good ideas there that I can learn from.

Regards,

Rob

On Sep 10, 4:07 pm, kangax <[EMAIL PROTECTED]> wrote:
> On Sep 10, 10:20 am, Matt Foster <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > firstDescendant is a convienence function for referencing the
> > "firstChild" where its an immediate descendant of the element.  At
> > first I thought you could just bust out with ele.descendants().last()
> > but in researching this idea it would potentially give you unexpected
> > results.  As descendants()  grabs all children and grandchildren the
> > last object on that array could very well be a deeply nested element
> > and not particularly the lastChild element reference that you were
> > looking for.  If this method is something you would really value you
> > could simply add it yourself using the Element.addMethods method, it
> > might look something like this.
>
> > Element.addMethods({
> >   lastDescendant: function(element) {
> >     element = $(element).lastChild;
> >     while (element && element.nodeType != 1) element =
> > element.previousSibling;
> >     return $(element);
> >   }
>
> > });
>
> A less performant, but shorter version would be:
>
> $(element).childElements().last();
>
> --
> kangax- Hide quoted text -
>
> - Show quoted text -
--~--~-~--~~~---~--~~
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 prototype-scriptaculous@googlegroups.com
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: lastDescendant()?

2008-09-10 Thread kangax

On Sep 10, 10:20 am, Matt Foster <[EMAIL PROTECTED]> wrote:
> firstDescendant is a convienence function for referencing the
> "firstChild" where its an immediate descendant of the element.  At
> first I thought you could just bust out with ele.descendants().last()
> but in researching this idea it would potentially give you unexpected
> results.  As descendants()  grabs all children and grandchildren the
> last object on that array could very well be a deeply nested element
> and not particularly the lastChild element reference that you were
> looking for.  If this method is something you would really value you
> could simply add it yourself using the Element.addMethods method, it
> might look something like this.
>
> Element.addMethods({
>   lastDescendant: function(element) {
> element = $(element).lastChild;
> while (element && element.nodeType != 1) element =
> element.previousSibling;
> return $(element);
>   }
>
> });

A less performant, but shorter version would be:

$(element).childElements().last();

--
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 prototype-scriptaculous@googlegroups.com
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: lastDescendant()?

2008-09-10 Thread Matt Foster

firstDescendant is a convienence function for referencing the
"firstChild" where its an immediate descendant of the element.  At
first I thought you could just bust out with ele.descendants().last()
but in researching this idea it would potentially give you unexpected
results.  As descendants()  grabs all children and grandchildren the
last object on that array could very well be a deeply nested element
and not particularly the lastChild element reference that you were
looking for.  If this method is something you would really value you
could simply add it yourself using the Element.addMethods method, it
might look something like this.

Element.addMethods({
  lastDescendant: function(element) {
element = $(element).lastChild;
while (element && element.nodeType != 1) element =
element.previousSibling;
return $(element);
  }
});





On Sep 10, 9:23 am, beachcomber <[EMAIL PROTECTED]> wrote:
> Hi firstly... I love prototype!
>
> I'm currently exploring prototype and I've found that there is a
> function called firstDescendant().
>
> However I was wondering if there was a similar function for selecting
> the last descendant?
>
> Regards,
>
> Rob
--~--~-~--~~~---~--~~
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 prototype-scriptaculous@googlegroups.com
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
-~--~~~~--~~--~--~---