jdalton
2007-May-04 19:44 UTC
does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
Hi guys, I am new to this whole css3/ xpath thing and I am diggin it 8). I am trying to do something like $$(''a:contains("next >")''); but I get a js error when executing that. Is this even supported or am I doing it wrong. Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-May-05 08:40 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
Hey there! jdalton a écrit :> I am trying to do something like $$(''a:contains("next >")''); > but I get a js error when executing that.I''d really like you to tell me what exactly you think this selector should fetch... It''s not a CSS3 selector at all (:contains does not seem to be part of the CSS 3 Selectors spec). At "worst," and assuming I guess your intent correctly, you can emulate it like so (untested, but should do well enough): $$(''a'').select(function(link) { return link.innerHTML.stripTags().include(''next >''); }) ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
tobie
2007-May-05 09:10 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
> It''s not a CSS3 selector at all (:contains does not > seem to be part of the CSS 3 Selectors spec).Hi Christophe, Sorry to contradict you, but it is: http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors - Tobie --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Christophe Porteneuve
2007-May-05 11:00 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
Hey Tobie! tobie a écrit :> Sorry to contradict you, but it is: > http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectorsExcept it''s not in the latest version: http://www.w3.org/TR/css3-selectors/ The version you''re alluding to is almost 6 years old. The :contains pseudo-class was dropped somewhere along the way I guess. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
tobie
2007-May-05 11:38 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
Haha, you''re right... sorry about that! On May 5, 7:00 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey Tobie! > > tobie a écrit : > > > Sorry to contradict you, but it is: > >http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors > > Except it''s not in the latest version: > > http://www.w3.org/TR/css3-selectors/ > > The version you''re alluding to is almost 6 years old. The :contains > pseudo-class was dropped somewhere along the way I guess. > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Marius Feraru
2007-May-05 13:50 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Christophe Porteneuve wrote:> jdalton a écrit : >> I am trying to do something like $$(''a:contains("next >")''); but I get >> a js error when executing that. > I''d really like you to tell me what exactly you think this selector > should fetch... It''s not a CSS3 selector at all (:contains does not seem > to be part of the CSS 3 Selectors spec). > > At "worst," and assuming I guess your intent correctly, you can emulate > it like so (untested, but should do well enough): > > $$(''a'').select(function(link) { return > link.innerHTML.stripTags().include(''next >''); })AFAICT, this shouldn''t really work because innerHTML doesn''t decode HTML entities (">" in this example), but anyway, the approach sounds OK. OTOH, XPath should do it with: $x(''.//a[contains(.,"next >")]'') In Prototype terms, this would become: document._getElementsByXPath(''.//a[contains(.,"next >")]'') But anyway this was just for the sake of example, as, AFAIK, currently Prototype doesn''t have XPath support for "some" browsers (e.g. MSIE).> ''HTH+1 ;-) - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFGPIu5tZHp/AYZiNkRAuBqAJsHHOfKqsGjVubAMKg/hbUKp9NbRQCfWLLe pd38GEgm1sfjgvtAWg4m6zo=gYMo -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
jdalton
2007-May-05 17:38 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
Hey guys, Thanks for clearing that up. Like I said I am rather new to the xpath (mainly because its not cross browser at the moment) and css3 syntax. I recognize the power it holds and it has peeked my curiosity. Do you know of any resources for finding good usage examples? P.S. Here is a regexp I use for extracting html elements from text in php. The regexp can be used in js too. Its very thorough and allows for tags like <div title=''next >'' id="nav">test</div> $selfClosing = preg_match(''/(br|hr|img|input|link|meta|param)/i'', $tagName); if($selfClosing){ //very thorough regular expression $pattern = ''%<''.$tagName.''(?:(?:(?:\s|\n)+\w+(?:(?:\s|\n)*=(?:\s| \n)*(?:".*?"|\''.*?\''|[^\''">\s]+))?)+(?:\s|\n)*|(?:\s|\n)*)/>%i''; } else{ $pattern = ''%<''.$tagName.''(?:(?:(?:\s|\n)+\w+(?:(?:\s|\n)*=(?:\s| \n)*(?:".*?"|\''.*?\''|[^\''">\s]+))?)+(?:\s|\n)*|(?:\s|\n)*)>(?:(?:.| \n)*?)</''.$tagName.''>%''; } - Thanx --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Marius Feraru
2007-May-05 22:24 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 jdalton wrote:> Like I said I am rather new to the xpath (mainly because its not cross > browser at the moment) and css3 syntax.CSS3 fails under the same "not cross browser" umbrella given its current status (both as standardization and implementation).> I recognize the power it holds and it has peeked my curiosity. > Do you know of any resources for finding good usage examples?Whatever links we may give, they will all fail as "advertising", so let''s stick to the Wikipedia article [1], as it provides lotta good pointers. Besides, it looks like Google still works OK for this query [2] ;-) [1] http://en.wikipedia.org/wiki/Xpath [2] http://www.google.com/search?q=xpath%20tutorial> P.S. Here is a regexp I use for extracting html elements from text in > php. The regexp can be used in js too. Its very thorough and allows for > tags like <div title=''next >'' id="nav">test</div>That ">" char inside @title should have been encoded, but you already knew that; same goes for things like <foo onclick="x = y > 2 ? a : b"> or <a href="...?foo=a&bar=b">, etc.> $selfClosing = preg_match(''/(br|hr|img|input|link|meta|param)/i'', > $tagName);You missed ''base'', ''area'', ''col'' (maybe more, depending what standard you are referring to - like ''frame''?) ;-)> if($selfClosing){ > //very thorough regular expression > $pattern = ''%<''.$tagName.''(?:(?:(?:\s|\n)+\w+(?:(?:\s|\n)*=(?:\s| > \n)*(?:".*?"|\''.*?\''|[^\''">\s]+))?)+(?:\s|\n)*|(?:\s|\n)*)/>%i'';I wouldn''t name this really "thorough", but OK, if it serves your purposes, then use it. If you allow me some comments (OK, ignoring the ugly "new lines" workaround), I''d say: - - the approach you chose for determining the attributes list results in a too high level of alternation: TAG ( ATTRIBUTE+ BLANK* | BLANK* ) you could minimize it to: TAG ATTRIBUTE* BLANKS* - - attribute names may be more than "\w+" (eg.: ''http-equiv''). If you want to play friendly with at least HTML4, allow at least ''-'', but extending it to XML name/nmtoken rules should be even better ;-) - - be more economic when getting the attributes values by using negative lists, e.g. ".*?" -> "[^"]*" - - note that browsers can handle even aberrations like "<foo bar= >", making attribute value optional (even when "=" is in place) would do it> } > else{ > $pattern = ''%<''.$tagName.''(?:(?:(?:\s|\n)+\w+(?:(?:\s|\n)*=(?:\s| > \n)*(?:".*?"|\''.*?\''|[^\''">\s]+))?)+(?:\s|\n)*|(?:\s|\n)*)>(?:(?:.| > \n)*?)</''.$tagName.''>%'';OK, I''m sure you know this one may fail badly, but anyway, at least allow whitespace in the "end-tag", after the tagName. ;-)> }cheers and my apologies for this off-topic message (is "Saturday night" a good excuse?) ;-) - -- Marius Feraru -----BEGIN PGP SIGNATURE----- iD8DBQFGPQQntZHp/AYZiNkRAix0AJ9MGhh1DX2lHvX6a7RhTJRntDhkxQCfZbOP JwlQQvGoofJ/B2Ndz4AQbhw=W7Av -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
jdalton
2007-May-05 22:58 UTC
Re: does $$() or Element.getElementBySelector() support something like: $$(''a:contains("next >")'');
@Marius Feraru - Thanx for the tips. I will fix the effected php code 8), so it won''t "fail badly". ;-P --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---