Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created May 12, 2010 10:32
Show Gist options
  • Save 3rd-Eden/398422 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/398422 to your computer and use it in GitHub Desktop.
How to replace the Spry Element selector engine
Spry.$$ = function( selectorSequence, rootNode )
{
var matches = [];
Spry.$$.addExtensions( matches );
// If the first argument to $$() is an object, it
// is assumed that all args are either a DOM element
// or an array of DOM elements, in which case we
// simply append all DOM elements to our special
// matches array and return immediately.
if (typeof arguments[0] == "object")
{
for (var i = 0; i < arguments.length; i++)
{
if (arguments[i].constructor == Array)
matches.push.apply(matches, arguments[i]);
else
matches.push(arguments[i]);
}
return matches;
}
if (!rootNode)
rootNode = document;
else
rootNode = Spry.$(rootNode);
for( var nodes = Sizzle( selectorSequence, rootNode ), length = nodes.length, i = 0; i < length; i++ ){
matches.push( nodes[i] );
}
return matches;
};
@3rd-Eden
Copy link
Author

Example of how to replace the existing Spry selector engine with a new one. In the example above I'm using Sizzle ( http://github.com/jeresig/sizzle/ );
You need to replace the above code with the existing Spry.$$ function. After that you can remove the Spry.$$ tokenizer. And your ready to go. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment