[Proto-Scripty] Re: Getting Text Nodes of Elements

2008-10-11 Thread RobG



On Oct 12, 10:05 am, kangax <[EMAIL PROTECTED]> wrote:
> On Oct 11, 2:40 pm, RobG <[EMAIL PROTECTED]> wrote:
> > On Oct 12, 3:29 am, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
> > > On Sat, Oct 11, 2008 at 10:31 AM, RobG <[EMAIL PROTECTED]> wrote:
> > > > Performance is not the issue - fewer lines of code doesn't necessarily
> > > > mean faster performance.
>
> > > Do you differentiate between browser sniffing and object/method sniffing?
>
> > As far as I am aware, there is no such thing as "object/method
> > sniffing", it's called object/feature detection.  Browser sniffing is
> > using the user agent string or similar to distinguish a particular
> > browser.  Object or feature detection is using a test to see if a
> > particular object or feature is supported.  It is much more robust and
> > requires far less maintenance.
>
> > > Do you like that Prototype's Selector#findElements method uses XPATH
> > > (Firefox) and querySelector/querySelectorAll (WebKit) when available?
>
> > Yes, I just don't like the way it goes about deciding which method to
> > used.
>
> What exactly could be done better? Are you referring to getting rid of
> `switch` in favor of forking the returning function?

To be honest, I haven't looked at that particular bit of code in
detail, I was making a general comment.  I don't have time to do so
at the moment either, my spare time is taken up with other
interests. :-)


> > > Or do you think this muddles up the codebase with unnecessary
> > > branching?
>
> > Not necessarily.  Branching can be avoided where it matters (usually
> > for performance reasons) - the feature test need only be carried out
> > once and an appropriate method assigned to the identifier that will be
> > used to call it.  e.g.
>
> > var someMethod = (function () {
> >   if ( featureTest ) {
> >     return function() { /* function using feature */ };
> >   } else {
> >     return function() { /* alternative function */ };
> >   }
>
> > })();
>
> > Sometimes you have to wait until the DOM is ready before you can do
> > the test, or a body element exists, etc.  In those cases, bottom-
> > loading the script helps.  Some functions are not called often enough
> > to make it worthwhile.
>
> Redefining function on first invocation works quite nicely in those
> cases.

Yes, that's a good alternative.


> > > (not trying to get into a huge discussion, just curious where you draw 
> > > the line)
>
> > Browser sniffing can nearly always be avoided, sometimes it takes a
> > bit of time and effort to work out an appropriate test.  I find that
> > once programmers start sniffing, it's very easy to become lazy and
> > depend on it when fairly simple alternatives exist.
>
> > For example, a little while ago (12 months?) jQuery had 17 browser
> > sniffs, it now has 30.  I haven't counted how many there are in
> > Prototype.js.
>
> We are slowly getting rid of them where possible.

Good.  I can grudgingly accept its use as a temporary crutch, but it
really grates to see it used as a fundamental strategy.


--
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Getting Text Nodes of Elements

2008-10-11 Thread kangax

On Oct 11, 2:40 pm, RobG <[EMAIL PROTECTED]> wrote:
> On Oct 12, 3:29 am, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
>
> > On Sat, Oct 11, 2008 at 10:31 AM, RobG <[EMAIL PROTECTED]> wrote:
> > > Performance is not the issue - fewer lines of code doesn't necessarily
> > > mean faster performance.
>
> > Do you differentiate between browser sniffing and object/method sniffing?
>
> As far as I am aware, there is no such thing as "object/method
> sniffing", it's called object/feature detection.  Browser sniffing is
> using the user agent string or similar to distinguish a particular
> browser.  Object or feature detection is using a test to see if a
> particular object or feature is supported.  It is much more robust and
> requires far less maintenance.
>
> > Do you like that Prototype's Selector#findElements method uses XPATH
> > (Firefox) and querySelector/querySelectorAll (WebKit) when available?
>
> Yes, I just don't like the way it goes about deciding which method to
> used.

What exactly could be done better? Are you referring to getting rid of
`switch` in favor of forking the returning function?

>
> > Or do you think this muddles up the codebase with unnecessary
> > branching?
>
> Not necessarily.  Branching can be avoided where it matters (usually
> for performance reasons) - the feature test need only be carried out
> once and an appropriate method assigned to the identifier that will be
> used to call it.  e.g.
>
> var someMethod = (function () {
>   if ( featureTest ) {
> return function() { /* function using feature */ };
>   } else {
> return function() { /* alternative function */ };
>   }
>
> })();
>
> Sometimes you have to wait until the DOM is ready before you can do
> the test, or a body element exists, etc.  In those cases, bottom-
> loading the script helps.  Some functions are not called often enough
> to make it worthwhile.

Redefining function on first invocation works quite nicely in those
cases.

>
> > (not trying to get into a huge discussion, just curious where you draw the 
> > line)
>
> Browser sniffing can nearly always be avoided, sometimes it takes a
> bit of time and effort to work out an appropriate test.  I find that
> once programmers start sniffing, it's very easy to become lazy and
> depend on it when fairly simple alternatives exist.
>
> For example, a little while ago (12 months?) jQuery had 17 browser
> sniffs, it now has 30.  I haven't counted how many there are in
> Prototype.js.

We are slowly getting rid of them where possible.

>
> --
> Rob

--
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: Getting Text Nodes of Elements

2008-10-11 Thread RobG



On Oct 12, 3:29 am, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
> On Sat, Oct 11, 2008 at 10:31 AM, RobG <[EMAIL PROTECTED]> wrote:
> > Performance is not the issue - fewer lines of code doesn't necessarily
> > mean faster performance.
>
> Do you differentiate between browser sniffing and object/method sniffing?

As far as I am aware, there is no such thing as "object/method
sniffing", it's called object/feature detection.  Browser sniffing is
using the user agent string or similar to distinguish a particular
browser.  Object or feature detection is using a test to see if a
particular object or feature is supported.  It is much more robust and
requires far less maintenance.


> Do you like that Prototype's Selector#findElements method uses XPATH
> (Firefox) and querySelector/querySelectorAll (WebKit) when available?

Yes, I just don't like the way it goes about deciding which method to
used.


> Or do you think this muddles up the codebase with unnecessary
> branching?

Not necessarily.  Branching can be avoided where it matters (usually
for performance reasons) - the feature test need only be carried out
once and an appropriate method assigned to the identifier that will be
used to call it.  e.g.

var someMethod = (function () {
  if ( featureTest ) {
return function() { /* function using feature */ };
  } else {
return function() { /* alternative function */ };
  }
})();

Sometimes you have to wait until the DOM is ready before you can do
the test, or a body element exists, etc.  In those cases, bottom-
loading the script helps.  Some functions are not called often enough
to make it worthwhile.


> (not trying to get into a huge discussion, just curious where you draw the 
> line)

Browser sniffing can nearly always be avoided, sometimes it takes a
bit of time and effort to work out an appropriate test.  I find that
once programmers start sniffing, it's very easy to become lazy and
depend on it when fairly simple alternatives exist.

For example, a little while ago (12 months?) jQuery had 17 browser
sniffs, it now has 30.  I haven't counted how many there are in
Prototype.js.


--
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Getting Text Nodes of Elements

2008-10-11 Thread Justin Perkins

On Sat, Oct 11, 2008 at 10:31 AM, RobG <[EMAIL PROTECTED]> wrote:
> Performance is not the issue - fewer lines of code doesn't necessarily
> mean faster performance.

Do you differentiate between browser sniffing and object/method sniffing?

Do you like that Prototype's Selector#findElements method uses XPATH
(Firefox) and querySelector/querySelectorAll (WebKit) when available?
Or do you think this muddles up the codebase with unnecessary
branching?

(not trying to get into a huge discussion, just curious where you draw the line)

-justin

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-11 Thread RobG



On Oct 10, 1:56 pm, "Justin Perkins" <[EMAIL PROTECTED]> wrote:
> On Thu, Oct 9, 2008 at 10:42 PM, RobG <[EMAIL PROTECTED]> wrote:
> > Interesting, but it relies on browser sniffing and proprietary
> > properties.
>
> What's wrong with that?

There are many, many articles on why browser sniffing should not be
used as a general strategy - here's one:

http://www.jibbering.com/faq/faq_notes/not_browser_detect.html#bdTop
>

In general, proprietary methods should not be used for code on the web
as they are implemented differently in different browsers - cautious
use of innerHTML is one of the few exceptions.  The sniff for Opera is
because its innerText is different to IEs, so one poor choice has led
to another.

The code doesn't work in Prototype.js version 1.6 - it doesn't deal
with inline script and returns different results in different
browsers.  Also, there doesn't seem to be any point in using [\n\r\s]
in the RegExp - what browser supported by Prototype.js doesn't include
new lines and returns in white space?  That indicates non-compliance
with ECMA-262.


> If it is in the name of performance, I say go for it.

Performance is not the issue - fewer lines of code doesn't necessarily
mean faster performance.

Anyhow, performance is moot if the code doesn't work.  Beware early
optimisation - it can cause more issues than it solves.


--
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Getting Text Nodes of Elements

2008-10-09 Thread Hector Virgen
Would it be better to receive text nodes as an enumerable? Maybe something
like Element#childTextNodes() to compliment Element#childElements()? It
would be nice if text nodes that contain only white space are excluded.
-Hector

On Thu, Oct 9, 2008 at 8:56 PM, Justin Perkins <[EMAIL PROTECTED]>wrote:

>
> On Thu, Oct 9, 2008 at 10:42 PM, RobG <[EMAIL PROTECTED]> wrote:
> > Interesting, but it relies on browser sniffing and proprietary
> > properties.
>
> What's wrong with that? If it is in the name of performance, I say go for
> it.
>
> -justin
>
> >
>

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-09 Thread Justin Perkins

On Thu, Oct 9, 2008 at 10:42 PM, RobG <[EMAIL PROTECTED]> wrote:
> Interesting, but it relies on browser sniffing and proprietary
> properties.

What's wrong with that? If it is in the name of performance, I say go for it.

-justin

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-09 Thread RobG



On Oct 9, 8:57 am, Andrew Dupont <[EMAIL PROTECTED]> wrote:
[...]
> You want Tobie's "getInnerText" function [1]. We should think about
> putting this into Prototype at some point.
>
> [1]http://tobielangel.com/2006/10/18/extending-prototype-getinnertext

Interesting, but it relies on browser sniffing and proprietary
properties.  Consider:

function getText(el)
{
  var x = el.childNodes;
  var txt = '';
  var node;

  for (var i=0, len=x.length; ihttp://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Getting Text Nodes of Elements

2008-10-08 Thread Andrew Dupont



On Oct 8, 10:31 am, "Hector Virgen" <[EMAIL PROTECTED]> wrote:
> Maybe there's a better way to approach my problem.
> I have a nested unordered list that contains an image (icon) and some text
> in each LI. I want to extract just the text part of the LI without the
> image.
>
> 
>     Foo
>     Bar
>         
>             Baz
>         
>     
> 
>
> What I want is extract 'Foo', 'Bar', and 'Baz' from each of the LIs. Any
> ideas on how to go about this, or should I restructure my html?

You want Tobie's "getInnerText" function [1]. We should think about
putting this into Prototype at some point.

Cheers,
Andrew

[1] http://tobielangel.com/2006/10/18/extending-prototype-getinnertext

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread solidhex

The DOM methods for manipulating text nodes are pretty fail safe these
days, once you clean up the white space. If you're creating the HTML
chunks dynamically, it's much easier to use insert and update methods,
but for cases where you need to access existing text nodes, Prototype
currently doesn't have anything up its sleeve to handle that
yet :)



On Oct 8, 11:02 am, "Hector Virgen" <[EMAIL PROTECTED]> wrote:
> Thanks for the all of the suggestions. Any chance something like this can be
> added into Prototype for cross-browser compatibility and ease of use?
> -Hector
>
> On Wed, Oct 8, 2008 at 10:57 AM, solidhex <[EMAIL PROTECTED]> wrote:
>
> > You can also use Prototype's methods for removing white space,
> > something like:
>
> >                $('foo', 'bar', 'baz').each(function(el) {
>
> >  console.log(el.cleanWhitespace().childNodes[1].nodeValue.strip());
> >                });
>
> > That seems to return what you're after.
>
> > On Oct 8, 8:53 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> > > Getting the text is pretty simple:
>
> > >         $$('li').each(function(elm){
> > >                 alert (elm.innerHTML.gsub(/<[^>]+>/,''))
> > >         });
>
> > > The issue lies with the LI that has a UL in it. In that case, you get
> > > "Bar [bunch of whitespace] Baz", then next you get just "Baz". If the
> > > order of elements is important, then you will need to use either a
> > > smarter selector or a test inside the loop to only return the non-
> > > child portion of the element.
>
> > > Walter
>
> > > On Oct 8, 2008, at 11:31 AM, Hector Virgen wrote:
>
> > > > Maybe there's a better way to approach my problem.
>
> > > > I have a nested unordered list that contains an image (icon) and
> > > > some text in each LI. I want to extract just the text part of the
> > > > LI without the image.
>
> > > > 
> > > >     Foo
> > > >     Bar
> > > >         
> > > >             Baz
> > > >         
> > > >     
> > > > 
>
> > > > What I want is extract 'Foo', 'Bar', and 'Baz' from each of the
> > > > LIs. Any ideas on how to go about this, or should I restructure my
> > > > html?
>
> > > > -Hector
>
> > > > On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø
> > > > <[EMAIL PROTECTED]> wrote:
> > > > This might not work in IE, as IE doesn't return textnodes in
> > > > childNodes.
>
> > > > /Søren
>
> > > > On 07/10/2008, at 21.24, Hector Virgen wrote:
>
> > > >> Thanks! That should do the trick :)
>
> > > >> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins
> > > >> <[EMAIL PROTECTED]> wrote:
>
> > > >> I think you will need to use the native methods to get the text nodes
> > > >> as Prototype filters them out. This will work though:
>
> > > >> $A( $('some-element-id').childNodes ).select( function(element){
> > > >> return element.nodeType == 3; } )
>
> > > >> Or better yet:
>
> > > >> Element.addMethods({
> > > >>  textNodes: function(element){
> > > >>    return $A(element.childNodes).select( function(child){ return
> > > >> child.nodeType == 3; } );
> > > >>  }
> > > >> });
>
> > > >> Then you can just do: $('some-element-id').textNodes();
>
> > > >> -justin
--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread Hector Virgen
Thanks for the all of the suggestions. Any chance something like this can be
added into Prototype for cross-browser compatibility and ease of use?
-Hector

On Wed, Oct 8, 2008 at 10:57 AM, solidhex <[EMAIL PROTECTED]> wrote:

>
> You can also use Prototype's methods for removing white space,
> something like:
>
>$('foo', 'bar', 'baz').each(function(el) {
>
>  console.log(el.cleanWhitespace().childNodes[1].nodeValue.strip());
>});
>
> That seems to return what you're after.
>
> On Oct 8, 8:53 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> > Getting the text is pretty simple:
> >
> > $$('li').each(function(elm){
> > alert (elm.innerHTML.gsub(/<[^>]+>/,''))
> > });
> >
> > The issue lies with the LI that has a UL in it. In that case, you get
> > "Bar [bunch of whitespace] Baz", then next you get just "Baz". If the
> > order of elements is important, then you will need to use either a
> > smarter selector or a test inside the loop to only return the non-
> > child portion of the element.
> >
> > Walter
> >
> > On Oct 8, 2008, at 11:31 AM, Hector Virgen wrote:
> >
> > > Maybe there's a better way to approach my problem.
> >
> > > I have a nested unordered list that contains an image (icon) and
> > > some text in each LI. I want to extract just the text part of the
> > > LI without the image.
> >
> > > 
> > > Foo
> > > Bar
> > > 
> > > Baz
> > > 
> > > 
> > > 
> >
> > > What I want is extract 'Foo', 'Bar', and 'Baz' from each of the
> > > LIs. Any ideas on how to go about this, or should I restructure my
> > > html?
> >
> > > -Hector
> >
> > > On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø
> > > <[EMAIL PROTECTED]> wrote:
> > > This might not work in IE, as IE doesn't return textnodes in
> > > childNodes.
> >
> > > /Søren
> >
> > > On 07/10/2008, at 21.24, Hector Virgen wrote:
> >
> > >> Thanks! That should do the trick :)
> >
> > >> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins
> > >> <[EMAIL PROTECTED]> wrote:
> >
> > >> I think you will need to use the native methods to get the text nodes
> > >> as Prototype filters them out. This will work though:
> >
> > >> $A( $('some-element-id').childNodes ).select( function(element){
> > >> return element.nodeType == 3; } )
> >
> > >> Or better yet:
> >
> > >> Element.addMethods({
> > >>  textNodes: function(element){
> > >>return $A(element.childNodes).select( function(child){ return
> > >> child.nodeType == 3; } );
> > >>  }
> > >> });
> >
> > >> Then you can just do: $('some-element-id').textNodes();
> >
> > >> -justin
> >
>

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread solidhex

You can also use Prototype's methods for removing white space,
something like:

$('foo', 'bar', 'baz').each(function(el) {

console.log(el.cleanWhitespace().childNodes[1].nodeValue.strip());
});

That seems to return what you're after.

On Oct 8, 8:53 am, Walter Lee Davis <[EMAIL PROTECTED]> wrote:
> Getting the text is pretty simple:
>
>         $$('li').each(function(elm){
>                 alert (elm.innerHTML.gsub(/<[^>]+>/,''))
>         });
>
> The issue lies with the LI that has a UL in it. In that case, you get  
> "Bar [bunch of whitespace] Baz", then next you get just "Baz". If the  
> order of elements is important, then you will need to use either a  
> smarter selector or a test inside the loop to only return the non-
> child portion of the element.
>
> Walter
>
> On Oct 8, 2008, at 11:31 AM, Hector Virgen wrote:
>
> > Maybe there's a better way to approach my problem.
>
> > I have a nested unordered list that contains an image (icon) and  
> > some text in each LI. I want to extract just the text part of the  
> > LI without the image.
>
> > 
> >     Foo
> >     Bar
> >         
> >             Baz
> >         
> >     
> > 
>
> > What I want is extract 'Foo', 'Bar', and 'Baz' from each of the  
> > LIs. Any ideas on how to go about this, or should I restructure my  
> > html?
>
> > -Hector
>
> > On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø  
> > <[EMAIL PROTECTED]> wrote:
> > This might not work in IE, as IE doesn't return textnodes in  
> > childNodes.
>
> > /Søren
>
> > On 07/10/2008, at 21.24, Hector Virgen wrote:
>
> >> Thanks! That should do the trick :)
>
> >> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins  
> >> <[EMAIL PROTECTED]> wrote:
>
> >> I think you will need to use the native methods to get the text nodes
> >> as Prototype filters them out. This will work though:
>
> >> $A( $('some-element-id').childNodes ).select( function(element){
> >> return element.nodeType == 3; } )
>
> >> Or better yet:
>
> >> Element.addMethods({
> >>  textNodes: function(element){
> >>    return $A(element.childNodes).select( function(child){ return
> >> child.nodeType == 3; } );
> >>  }
> >> });
>
> >> Then you can just do: $('some-element-id').textNodes();
>
> >> -justin
--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread Walter Lee Davis

Getting the text is pretty simple:

$$('li').each(function(elm){
alert (elm.innerHTML.gsub(/<[^>]+>/,''))
});

The issue lies with the LI that has a UL in it. In that case, you get  
"Bar [bunch of whitespace] Baz", then next you get just "Baz". If the  
order of elements is important, then you will need to use either a  
smarter selector or a test inside the loop to only return the non- 
child portion of the element.

Walter

On Oct 8, 2008, at 11:31 AM, Hector Virgen wrote:

> Maybe there's a better way to approach my problem.
>
> I have a nested unordered list that contains an image (icon) and  
> some text in each LI. I want to extract just the text part of the  
> LI without the image.
>
> 
> Foo
> Bar
> 
> Baz
> 
> 
> 
>
> What I want is extract 'Foo', 'Bar', and 'Baz' from each of the  
> LIs. Any ideas on how to go about this, or should I restructure my  
> html?
>
> -Hector
>
>
> On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø  
> <[EMAIL PROTECTED]> wrote:
> This might not work in IE, as IE doesn't return textnodes in  
> childNodes.
>
> /Søren
>
> On 07/10/2008, at 21.24, Hector Virgen wrote:
>
>> Thanks! That should do the trick :)
>>
>> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins  
>> <[EMAIL PROTECTED]> wrote:
>>
>> I think you will need to use the native methods to get the text nodes
>> as Prototype filters them out. This will work though:
>>
>> $A( $('some-element-id').childNodes ).select( function(element){
>> return element.nodeType == 3; } )
>>
>> Or better yet:
>>
>> Element.addMethods({
>>  textNodes: function(element){
>>return $A(element.childNodes).select( function(child){ return
>> child.nodeType == 3; } );
>>  }
>> });
>>
>> Then you can just do: $('some-element-id').textNodes();
>>
>> -justin
>>
>>
>>
>>
>>
>>
>
>
>
>
>
> >


--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread Brian Williams
you could put the text in a span element that should make it loads easier


On Wed, Oct 8, 2008 at 11:31 AM, Hector Virgen <[EMAIL PROTECTED]> wrote:

> Maybe there's a better way to approach my problem.
> I have a nested unordered list that contains an image (icon) and some text
> in each LI. I want to extract just the text part of the LI without the
> image.
>
> 
> Foo
> Bar
> 
> Baz
> 
> 
> 
>
> What I want is extract 'Foo', 'Bar', and 'Baz' from each of the LIs. Any
> ideas on how to go about this, or should I restructure my html?
>
> -Hector
>
>
> On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø <[EMAIL PROTECTED]>wrote:
>
>> This might not work in IE, as IE doesn't return textnodes in childNodes.
>> /Søren
>>
>> On 07/10/2008, at 21.24, Hector Virgen wrote:
>>
>> Thanks! That should do the trick :)
>>
>> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins <[EMAIL PROTECTED]>wrote:
>>
>>>
>>> I think you will need to use the native methods to get the text nodes
>>> as Prototype filters them out. This will work though:
>>>
>>> $A( $('some-element-id').childNodes ).select( function(element){
>>> return element.nodeType == 3; } )
>>>
>>> Or better yet:
>>>
>>> Element.addMethods({
>>>  textNodes: function(element){
>>>return $A(element.childNodes).select( function(child){ return
>>> child.nodeType == 3; } );
>>>  }
>>> });
>>>
>>> Then you can just do: $('some-element-id').textNodes();
>>>
>>> -justin
>>>
>>>
>>>
>>
>>
>>
>>
>>
>>
>>
>
> >
>

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread Hector Virgen
Maybe there's a better way to approach my problem.
I have a nested unordered list that contains an image (icon) and some text
in each LI. I want to extract just the text part of the LI without the
image.


Foo
Bar

Baz




What I want is extract 'Foo', 'Bar', and 'Baz' from each of the LIs. Any
ideas on how to go about this, or should I restructure my html?

-Hector


On Wed, Oct 8, 2008 at 3:48 AM, Søren Erland Vestø <[EMAIL PROTECTED]>wrote:

> This might not work in IE, as IE doesn't return textnodes in childNodes.
> /Søren
>
> On 07/10/2008, at 21.24, Hector Virgen wrote:
>
> Thanks! That should do the trick :)
>
> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins <[EMAIL PROTECTED]>wrote:
>
>>
>> I think you will need to use the native methods to get the text nodes
>> as Prototype filters them out. This will work though:
>>
>> $A( $('some-element-id').childNodes ).select( function(element){
>> return element.nodeType == 3; } )
>>
>> Or better yet:
>>
>> Element.addMethods({
>>  textNodes: function(element){
>>return $A(element.childNodes).select( function(child){ return
>> child.nodeType == 3; } );
>>  }
>> });
>>
>> Then you can just do: $('some-element-id').textNodes();
>>
>> -justin
>>
>>
>>
>
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread Søren Erland Vestø
This might not work in IE, as IE doesn't return textnodes in childNodes.

/Søren

On 07/10/2008, at 21.24, Hector Virgen wrote:

> Thanks! That should do the trick :)
>
> On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins <[EMAIL PROTECTED] 
> > wrote:
>
> I think you will need to use the native methods to get the text nodes
> as Prototype filters them out. This will work though:
>
> $A( $('some-element-id').childNodes ).select( function(element){
> return element.nodeType == 3; } )
>
> Or better yet:
>
> Element.addMethods({
>  textNodes: function(element){
>return $A(element.childNodes).select( function(child){ return
> child.nodeType == 3; } );
>  }
> });
>
> Then you can just do: $('some-element-id').textNodes();
>
> -justin
>
>
>
>
> >


--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-08 Thread ColinFine



On Oct 7, 7:42 pm, "Hector Virgen" <[EMAIL PROTECTED]> wrote:
> Is there a Prototype way to get the descendants of an element that are only
> text nodes? Element.descendents() only returns elements. Thanks!
> -Hector

It's neither Prototype nor part of a published API, but I have noticed
that Scriptaculous:effects adds a method to Element called
'collectTextNodes'. It actually does a 'join' on them, so if you want
a list of nodes, you can't use it (though you might copy it).

If you do want a string, and you're using Scripty as well, and you
don't mind the risk of using internal functions, you could use it
directly :-)

Colin

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-07 Thread Hector Virgen
Thanks! That should do the trick :)

On Tue, Oct 7, 2008 at 12:12 PM, Justin Perkins <[EMAIL PROTECTED]>wrote:

>
> I think you will need to use the native methods to get the text nodes
> as Prototype filters them out. This will work though:
>
> $A( $('some-element-id').childNodes ).select( function(element){
> return element.nodeType == 3; } )
>
> Or better yet:
>
> Element.addMethods({
>  textNodes: function(element){
>return $A(element.childNodes).select( function(child){ return
> child.nodeType == 3; } );
>  }
> });
>
> Then you can just do: $('some-element-id').textNodes();
>
> -justin
>
> >
>

--~--~-~--~~~---~--~~
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: Getting Text Nodes of Elements

2008-10-07 Thread Justin Perkins

I think you will need to use the native methods to get the text nodes
as Prototype filters them out. This will work though:

$A( $('some-element-id').childNodes ).select( function(element){
return element.nodeType == 3; } )

Or better yet:

Element.addMethods({
  textNodes: function(element){
return $A(element.childNodes).select( function(child){ return
child.nodeType == 3; } );
  }
});

Then you can just do: $('some-element-id').textNodes();

-justin

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---