Peppy and MooTools

By  on  

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.

Recent Features

  • By
    I’m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

  • By
    How to Create a RetroPie on Raspberry Pi – Graphical Guide

    Today we get to play amazing games on our super powered game consoles, PCs, VR headsets, and even mobile devices.  While I enjoy playing new games these days, I do long for the retro gaming systems I had when I was a kid: the original Nintendo...

Incredible Demos

  • By
    Multiple Background CSS Animations

    CSS background animation has been a hot topic for a long time, mostly because they look pretty sweet and don't require additional elements.  I was recently asked if it was possible to have multiple background animations on a given element and the answer is yes...with...

  • By
    CSS Vertical Center with Flexbox

    I'm 31 years old and feel like I've been in the web development game for centuries.  We knew forever that layouts in CSS were a nightmare and we all considered flexbox our savior.  Whether it turns out that way remains to be seen but flexbox does easily...

Discussion

  1. cssProdigy

    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.

  2. carl

    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.

  3. 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.

  4. Ryan

    Hey guys,

    You can also use John Resig’s Sizzle in MooTools, by using this code:

    Window.$$ = function(selector){
        return new Elements(new Sizzle(selector));
    }
    

    This overwrites the $$ function, but you can rename it to whatever you want, obviously.

  5. @Ryan: You stole my upcoming blog article! :) Thanks for the submission!

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!