[jQuery] Change href of external links
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.5730.11" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2>Uh oh, I know what it is. It's a bug in pushStack.
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2>If the last arg to pushStack is a function, it does
.each(fn) with the filtered set but returns the original set.
</FONT></SPAN><SPAN class=925510822-14122006><FONT face=Arial color=#0000ff
size=2>If there are two trailing function args, the first is treated as above.
However, if the filtered set returned nothing (and thus fn was never called) it
does .each(fn2) with the original set. Kind of like an if-then-else. It's never
been documented but I think it will be eventually.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2>I think this should fix it:</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2> pushStack: function(a,args) {<BR> var fn =
args && args.length > 1 &&
args[args.length-1];<BR> var fn2 = args && args.length > 2
&& args[args.length-2];<BR></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=925510822-14122006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> discuss-bounces@jquery.com
[mailto:discuss-bounces@jquery.com] <B>On Behalf Of </B>Jonathan
Sharp<BR><B>Sent:</B> Thursday, December 14, 2006 2:31 PM<BR><B>To:</B> jQuery
Discussion.<BR><B>Subject:</B> Re: [jQuery] Change href of external
links<BR></FONT><BR></DIV>
<DIV></DIV>On 12/14/06, Yehuda Katz <<A
href="mailto:wycats@gmail.com">wycats@gmail.com</A>> wrote:<BR>> If that
was the case, jQuery("#main a").filter(function() { return false; }) would
return nothing. But it doesn't. It returns the original group of elements. At
least for me.<BR><BR>Hm... I also tested this and filter didn't prune the list
with my function returning false. <BR><BR>Here's the filter function out of
1.0.3 which checks if t is a function and pushes the result of jQuery.grep(this,
t) onto the stack.<BR><BR>filter: function(t) {<BR>
return this.pushStack(<BR>
*SNIP*<BR><BR>
typeof t == "function"
&&<BR>
jQuery.grep( this, t ) || <BR><BR>
jQuery.filter(t,this).r, arguments );<BR>
},<BR><BR>Now in the grep function it operates on the list of elements in elms.
It calls the function we defined (fn) and if fn returns false it shouldn't add
them to the result array. <BR><BR>grep: function(elems, fn, inv)
{<BR> *SNIP*<BR>
var result = [];<BR><BR>
// Go through the array, only saving the items<BR>
// that pass the validator function<BR>
for ( var i = 0; i < elems.length; i++
)<BR> if ( !inv
&& fn(elems[i],i) || inv && !fn(elems[i],i)
)<BR>
result.push( elems[i] );<BR><BR> return
result;<BR> },<BR><BR>Am I missing something here?
<BR><BR>Cheers,<BR>-js<BR><BR></BODY></HTML>
_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/