[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-17 Thread Stephan Beal
> Regexes are definitely worth learning. Once you know them, you can use > them in many different programming languages (and even non-programming > tools) and you'll be SO happy that you know how to use them. Brief follow-up: http://xkcd.com/208/ That's based on a true story.

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread R. Rajesh Jeba Anbiah
On Aug 16, 7:16 pm, Stephan Beal <[EMAIL PROTECTED]> wrote: > We've all attempted several different ways of highlighting navigation > links which point to the current page. Often times we mark the page > via our PHP by adding a class (e.g. "currentPage") to the navigation > link which points to th

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Karl Swedberg
On Aug 16, 2007, at 3:05 PM, Stephan Beal wrote: On Aug 16, 9:03 pm, Stephan Beal <[EMAIL PROTECTED]> wrote: and your above point, i'd love to see it. Maybe a plugin with options for ignoring/respecting GET parameters? And while you're writing that plugin (hint, hint ;), another point to ad

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Jörn Zaefferer
Stephan Beal schrieb: Hi, all! We've all attempted several different ways of highlighting navigation links which point to the current page. Often times we mark the page via our PHP by adding a class (e.g. "currentPage") to the navigation link which points to the current page, or some such. Here

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread polyrhythmic
The easiest way to learn RegExs, IMO, is with a realtime RegEx checker, such as: http://www.cuneytyilmaz.com/prog/jrx/ I've seen a better one with highlighting but I can't find it in my bookmarks at the moment. Charles On Aug 16, 10:09 am, Stephan Beal <[EMAIL PROTECTED]> wrote: > On Aug 16, 7:

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Stephan Beal
On Aug 16, 9:03 pm, Stephan Beal <[EMAIL PROTECTED]> wrote: > and your above point, i'd love to see it. Maybe a plugin with options > for ignoring/respecting GET parameters? And while you're writing that plugin (hint, hint ;), another point to address is the common practice of linking some elemen

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Stephan Beal
On Aug 16, 8:59 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote: > Most sites I've seen with these GET vars attached have something URLs > like this: > > index.html?category=2&product=210 > > So if I'm on that page, the one for product 210 within category 2, I > don't want to have a link to index.ht

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Karl Swedberg
Bernd Matzner wrote: $('a').each(function(){ if( window.location.href.indexOf( $(this).attr('href') ) >= 0 && $(this).attr('href').length > 1 ) { $(this).css('background-color','#004040') .css('color','#fff') .css('font-style', 'italic')

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Bernd Matzner
> > As for the each() function - I've given it some more thought, but I can't come up with a more elegant solution (except perhaps for filter(), but I doubt that it improves anything performance-wise). That's because we have to check if the current link is in the current location, not the other w

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Stephan Beal
On Aug 16, 7:04 pm, Bernd Matzner <[EMAIL PROTECTED]> wrote: > A | B | href="http://localhost/index.html";>C | D Doh, of course i hadn't considered that the navigation links themselves having GET options (i was thinking about people passing in args from external links). You're right - i think a

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Bernd Matzner
Hi Stephan, I did a quick test case with the following links: A | B | http://localhost/index.html";>C | D The Stephan/Karl solution will only highlight link B regardless of which link I click, whereas my solution highlights A-C when on the index.html page regardless of the GET vars attached, an

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Stephan Beal
On Aug 16, 6:28 pm, Bernd Matzner <[EMAIL PROTECTED]> wrote: > how about plain and stupid checking if the current url is in the link? ... i hadn't considered making sure it works when people link from external sites. :/ > $('a').each(function(){ > if( window.location.href.indexOf( $(this)

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Bernd Matzner
Hi Stephan, Karl, how about plain and stupid checking if the current url is in the link? $('a').each(function(){ if( window.location.href.indexOf( $(this).attr('href') ) >= 0 && $(this).attr('href').length > 1 ) { $(this).css('background-color','#004040') .css('col

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Stephan Beal
On Aug 16, 5:13 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote: > One way to avoid marking external links as the current page would be > to begin with an if statement: > > if (location.hostname == 'www.mysite.com') { The main problem with that is you've normally got to add several domains: your test

[jQuery] Re: stupid dev tricks: marking "current page" links

2007-08-16 Thread Karl Swedberg
On Aug 16, 2007, at 10:16 AM, Stephan Beal wrote: This approach might also have an odd side effect due to the stripping of the domain name from window.location: you might end up marking external links as the current page, which would obviously be incorrect. How to generically solve that is left