[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread sspboyd
agreed, this is not the best way to handle this issue. I'm considering it as a temporary work-around to a technical issue with the underlying cms. On Feb 24, 9:49 am, the_woodsman <[EMAIL PROTECTED]> wrote: > Seriously, if you want this to scale when you have more names in the > future, it'd be b

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread the_woodsman
Seriously, if you want this to scale when you have more names in the future, it'd be better to do at least some of the work server side, if you can- perhaps put all names in a span with class personName, then play around with those elements in JQ on the client side.

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread Dave Stewart
> I was also thinking that the routine you built could be converted into a search-term highlighter. There's already a jQuery plugin that highlights, called, conveniently- enough, highlight!

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread sspboyd
Excellent suggestions. I will have to investigate a bit more on how much text will be on the different pages and whether I can make any improvements on the number of names returned in each xml file. (I might also be able to get list of names as a json feed). I was also thinking that the routine

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread Dave Stewart
As well, when your name list gets rather large, I'm sure other pre- processing routines could speed things up. For example, you could split the XML list into 26 sections, based on First Name, then text the html for which Capital letters it contains. You then only loop through again for those names

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread Dave Stewart
Hey Stephen, RegExps are always going to be slower than a basic indexOf, so perhaps when you loop through the names you could try running an indexOf first, then if it comes out positive, only then do you the RegExp replacement. I imagine that there would be a cutoff point where the performance in

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-24 Thread sspboyd
Dave, That is great! Thanks. I've tested it out with an array of 1000 names as a worst case scenario and it is pretty slow. I'll have to see about refining the list of names if possible to keep it as small as possible. Thanks again, Stephen On Feb 23, 7:16 pm, Dave Stewart <[EMAIL PROTECTED]> wr

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread Dave Stewart
Heh heh, this is cool! var names = ['Stephen Boyd','Fred Von Brown'] $("body").each( function(){ var html = $(this).html() $(names).each( function(i, e){ var rx= new RegExp(e, 'gi') html = html.replace(rx, '' +e+ '') }

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread Dave Stewart
For only the first name on each page, just remove the 'g' modifier from the RegExp constructor (I'm sure you know this)

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread Dave Stewart
Well you could do something like this (it would be prohibitively slow on 250 names on one page though!!) : var names = ['Stephen','Fred'] $("body").each( function(){ var html = $(this).html() $(names).each( function(i, e){ var rx= new RegExp(e, 'gi')

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread sspboyd
Timothy, Yes, I know the list of names. On Feb 23, 3:41 pm, timothytoe <[EMAIL PROTECTED]> wrote: > Do you know the list of names? Or are you trying to identify what > might be a name on the page (say two words in a row with initial > caps)? > > On Feb 23, 12:35 pm, sspboyd <[EMAIL PROTECTED]> wr

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread timothytoe
Do you know the list of names? Or are you trying to identify what might be a name on the page (say two words in a row with initial caps)? On Feb 23, 12:35 pm, sspboyd <[EMAIL PROTECTED]> wrote: > Hi Dave, > I want to find specific names (I have a list of 320 names in an xml > file). I want to sca

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread sspboyd
Hi Dave, I want to find specific names (I have a list of 320 names in an xml file). I want to scan through a page and create a link around the first instance for one of the names in the list. eg "Stephen Boyd's favourite person in the work is Fred Von Brown. Stephen Boyd calls Fred Von Brown ever

[jQuery] Re: trying to find the first instance of a person's name on the page

2008-02-23 Thread Dave Stewart
Well regexp would be useful if there was a pattern to people's names, but there isn't. Do you want to find any names, or a list, or a specific name?