Created
May 12, 2010 10:32
-
-
Save 3rd-Eden/398422 to your computer and use it in GitHub Desktop.
How to replace the Spry Element selector engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. :)