Peppy and MooTools
This post has been updated after more tinkering and testing.
A while back James Donaghue boasted his new selector engine Peppy. Lets say for giggles that we wanted to use MooTools and Peppy together. Here's how I got things to work.
The JavaScript
//sets peppy as the default engine
Window.$$ = function(selector){
return new Elements(new peppy.query(selector));
}
//get elements
window.addEvent('domready',function() {
$$('div').each(function(el) { // straight cash homey
el.setStyle('color','#f00');
});
});
I have no idea why you'd want to do this; MooTools' selector engine is rock solid. I was simply playing around and wanted to show you what I came up with.
![Convert XML to JSON with JavaScript]()
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
![Detect DOM Node Insertions with JavaScript and CSS Animations]()
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
![Build a Toggling Announcement Slider Using MooTools 1.2]()
A few of my customer have asked for me to create a subtle but dynamic (...I know...) way for them to advertise different specials on their website. Not something that would display on every page, but periodically or only the homepage. Using a trick...
![Spoiler Prevention with CSS Filters]()
No one likes a spoiler. Whether it be an image from an upcoming film or the result of a football match you DVR'd, sometimes you just don't want to know. As a possible provider of spoiler content, some sites may choose to warn users ahead...
Awesome! I’ve been waiting for this. The Peppy selector engine is really faster, and in some tests faster than Sizzle, I thought sizzle might make it’s way to MooTools but Peppy’s better ayway.
Have you even looked at the source of Peppy? I find it quite funny to compare it to Mootools or Sizzle, it’s not on the same level at all. For example binding DOM mutation events for caching slows down every DOM operation a lot! Way much more than the gain of the faster queries. It gets even the attribute getter wrong: e.getAttribute( a ) || e[a]; It’s good that it’s small but there’s a lot of space for improvements, so to say.
I’m not saying that I believe Peppy is better — quite frankly, it’s not. I just wanted to show you what I had at the end of my experimenting. Hell, I wouldn’t even say that this is quality. It’s not, quite honestly, but it worked.
Hey guys,
You can also use John Resig’s Sizzle in MooTools, by using this code:
This overwrites the
$$
function, but you can rename it to whatever you want, obviously.@Ryan: You stole my upcoming blog article! :) Thanks for the submission!