Robert,
I have also needed this bit of help from jQuery...for extracting texts
from HTML code.

I proposed this similar solution on the Sizzle group some time ago:

   http://groups.google.com/group/sizzlejs/browse_thread/thread/44d2b3fd5d532b5b

which probably solves with a simpler sort() on the result set, maybe
only done when a comma (group separator) is found in the selector.

Maybe your code adds some way to do it faster or are there other
reasons to not use .sort() ?

Diego


On 14 Feb, 01:47, Robert Katić <[email protected]> wrote:
> I corrected the joinResultsHelper:
>
> function joinResultsHelper( res, a, i, b, j ) {
>     if ( b && b[j] ) {
>         for ( var l = a.length; i < l; ++i ) {
>             if ( a[i] === b[j] && !b[++j] )
>                 return joinResultsHelper( res, a, i )
>
>             else if ( precedes(a[i], b[j]) )
>                 res.push( a[i] );
>
>             else {
>                 res.push( b[j++] );
>                 joinResultsHelper( res, b, j, a, i );
>                 break;
>             }
>         }
>     } else {
>         for ( var l = a.length; i < l; ++i )
>             res.push( a[i] );
>     }
>
>     return res;
>
> }
>
> On Feb 14, 12:26 am, Robert Katić <[email protected]> wrote:
>
> > The querySelectorAll returns elements in documents order, but Sizzle
> > (for now?) treat each selector separately.
>
> > Maybe this can be easily resolved joining each result array in one
> > with nodes in documents order?
> > If so, maybe something like this would help (not tested). Or you are
> > thinking to sort results all together?
>
> > var precedes = ( document.documentElement.sourceIndex == 0 ) &&
> >         function( a, b ) {
> >             return a.sourceIndex < b.sourceIndex;
> >         }
> >     || ( document.documentElement.compareDocumentPosition ) &&
> >         function( a, b ) {
> >             return !!( a.compareDocumentPosition(b) & 4 );
> >         }
> >     ||  function( a, b ) {
> >             if ( a === b || b.contains(a) )
> >                 return false
>
> >             if ( a.contains(b) )
> >                 return true;
>
> >             var c = a.parentNode;
> >             while ( !c.contains(b) ) {
> >                 a = c;
> >                 c = c.parentNode;
> >             }
>
> >             var p = b.parentNode;
> >             while ( p !== c ) {
> >                 b = p;
> >                 p = p.parentNode;
> >             }
>
> >             var nodes = c.childNodes;
> >             for ( var i = 0, node = nodes[0]; node; node = nodes[+
> > +i] ) {
> >                 if ( node === a )
> >                     return true;
> >                 if ( node === b )
> >                     return false;
> >             }
>
> >             return false;
> >         };
>
> > function joinResultsHelper( res, a, i, b, j ) {
> >     if ( b[j] ) {
> >         for ( var l = a.length; i < l; ++i ) {
> >             if ( a[i] === b[j] )
> >                 ++j;
>
> >             else if ( precedes(a[i], b[j]) )
> >                 res.push( a[i] );
>
> >             else {
> >                 res.push( b[j++] );
> >                 joinResultsHelper( res, b, j, a, i );
> >                 break;
> >             }
> >         }
> >     } else {
> >         for ( var l = a.length; i < l; ++i )
> >             res.push( a[i] );
> >     }
>
> >     return res;
>
> > }
>
> > function joinResults( a, b ) {
> >     if ( a.length === 0 )
> >         return b;
>
> >     if ( b.length === 0 )
> >         return a;
>
> >     return joinResultsHelper( [], a, 0, b, 0 );
>
> > }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to