<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Garrick Cheung &#187; selector engine</title>
	<atom:link href="http://www.garrickcheung.com/tag/selector-engine/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.garrickcheung.com</link>
	<description>Sharing what I know and learn about CSS, MooTools, Javascript, PHP and etc.</description>
	<lastBuildDate>Wed, 28 Apr 2010 02:52:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Sly, New Selector Engine &amp; How to Use in MooTools</title>
		<link>http://www.garrickcheung.com/javascript/sly-selector-engine/</link>
		<comments>http://www.garrickcheung.com/javascript/sly-selector-engine/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 16:00:44 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[selector]]></category>
		<category><![CDATA[selector engine]]></category>
		<category><![CDATA[Sly]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=302</guid>
		<description><![CDATA[You&#8217;ve heard of selector engines right? The engine that parses the HTML to match a string argument to return matching HTML elements? How about Sizzle and Peppy (two fast selector engines) that was released? Or how a couple JS frameworks were implementing Sizzle and the MooTools dev team decided not to follow suit? Now, have [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;ve heard of selector engines right? The engine that parses the HTML to match a string argument to return matching HTML elements? How about Sizzle and Peppy (two fast selector engines) that was released? Or how a couple JS frameworks were implementing Sizzle and the <a href="http://mootools.net/blog/2008/12/04/sizzle/" target="_blank">MooTools dev team decided not to follow suit</a>?</p>
<p>Now, have you heard of Sly, the new selector engine on the block? No? That&#8217;s because <a href="http://digitarald.de" target="_blank">Harald Kirschner</a> just released it yesterday, 03/25/09, and I can&#8217;t tell you how awesome it is.. or can I?</p>
<p>I&#8217;ll start you off with a brief description&#8230; and graphs!<span id="more-302"></span></p>
<blockquote><p>Sly is a turbocharged, cross-browser, library-agnostic JavaScript class for querying DOM documents using CSS3 selectors.</p></blockquote>
<p>And turbocharged it sure is, just check out the stats!<br />
<img src="http://www.garrickcheung.com/wp-content/uploads/sly_selector_performance.png" alt="Sly Selector Performance" style="width:455px;" /></p>
<p>The benefits:</p>
<ul>
<li>Pure and powerful <em>JavaScript</em> matching algorithm for <em>fast</em> and <em>accurate</em> queries</li>
<li>Extra optimizations for <em>frequently used selectors</em> and <em>latest browser features</em></li>
<li>Works uniformly in <code>DOM</code> documents, fragments or <code>XML</code> documents</li>
<li>Utility methods for matching and filtering of elements</li>
<li><em>Standalone selector parser</em> to produce <em>JavaScript</em> <code>Object</code> representations</li>
<li><em>Customizable</em> pseudo-classes, attribute operators and combinators</li>
<li>Just <strong>3 kB</strong>! (<a href="http://developer.yahoo.com/yui/compressor/" target="_blank">minified</a> and <a href="http://www.gzip.org/" target="_blank">gzipped</a>, <strong>8 kB</strong> without <em>gzip</em>)</li>
<li>No dependencies on third-party JS libraries, but developers can override internal methods (like <code>getAttribute</code>) for seamless integration.</li>
<li>Code follows the <a href="http://mootools.net" target="_blank">MooTools</a> philosophy, respecting strict standards, throwing no warnings and using meaningful variable names</li>
</ul>
<h3>Use it in MooTools?</h3>
<p>Yes, that&#8217;s right. You can use it in MooTools right now, though I don&#8217;t think it&#8217;s necessary since the MooTools selector engine is very good. But just like how <a href="http://davidwalsh.name/mootools-peppy-sizzle" target="_blank">David Walsh showed us how to use Sizzle and Peppy in MooTools</a>, you can do the following to use Sly:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Window.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    $Sly<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Sly<span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// returns an array of all the anchors in the page</span>
$Sly<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// returns the first anchor on the page</span>
$Sly<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now, you may be wondering whether doing this will allow you to use MooTools methods on the elements. Well, the good news is that you can because the MooTools Elements class applies the methods to all elements. Observe:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// returns the href of the first anchor</span>
$Sly<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And lastly, <a href="http://blog.olicio.us/2009/03/19/sly–-the-super-snazzy-selector-engine/" target="_blank">Oskar Krawczyk posted how to replace the $$ function itself (thanks Oskar!)</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">Window.<span style="color: #660066;">implement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    $$<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> Sly.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span>selector<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Great job, Harald, great job indeed. Way to represent!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/sly-selector-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Implement Other Selector Engines (e.g. Sizzle or Peppy) into MooTools?</title>
		<link>http://www.garrickcheung.com/mootools/implement-other-selector-engines-eg-sizzle-or-peppy-into-mootools/</link>
		<comments>http://www.garrickcheung.com/mootools/implement-other-selector-engines-eg-sizzle-or-peppy-into-mootools/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 09:06:06 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Peppy]]></category>
		<category><![CDATA[selector engine]]></category>
		<category><![CDATA[Sizzle]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=226</guid>
		<description><![CDATA[Not too long ago announcements of two new selector engines came on the scene, Peppy by James Donaghue and Sizzle by John Resig. At the time I had a fleeting thought of how cool it would be if MooTools was as fast or faster than Peppy and Sizzle. Yesterday, Ajaxian tells us that the Dojo [...]]]></description>
			<content:encoded><![CDATA[<p>Not too long ago announcements of two new selector engines came on the scene, <a href="http://ajaxian.com/archives/peppy-css3-selector-engine" target="_blank">Peppy by James Donaghue</a> and <a href="http://ajaxian.com/archives/sizzle-john-resig-has-a-new-selector-engine" target="_blank">Sizzle by John Resig</a>. At the time I had a fleeting thought of how cool it would be if MooTools was as fast or faster than Peppy and Sizzle.</p>
<p>Yesterday, <a href="http://ajaxian.com/archives/a-great-example-of-sharing-sizzle-engine-in-dojo-foundation" target="_blank">Ajaxian tells us</a> that the Dojo Community will vote on whether they implement the Sizzle selector engine instead of using their own.</p>
<p>Just after reading that I thought whether MooTools would benefit from implementing a selector engine instead of using their own. Apparently I was not alone in this thought as <a href="http://www.clientcide.com/industry-news/sizzle-power-in-mootools/">Aaron Newton has posted his thoughts and pros/cons</a>. Here&#8217;s my two cents.<span id="more-226"></span></p>
<p>Aaron brings up very good pros and cons. I think we should not follow the trend and switch to Sizzle but instead take in what we can and be inspired to improve upon it. We should already be doing that. This would require our awesome MooTools dev team to be up-to-date, but aren&#8217;t they continuously learning?</p>
<p>In this way, we can keep to the &#8216;extensibility&#8217; philosophy. Besides, if we figure out an even better method, who is to say that other developers aren&#8217;t looking at MooTools and taking from it what they deem better?</p>
<p>Lastly, why Sizzle and not Peppy? Last I checked, Peppy was beating out Sizzle on <a href="http://jamesdonaghue.com/static/peppy/profile/slickspeed/" target="_blank">SlickSpeed</a>. James recently <a href="http://jamesdonaghue.com/?p=187" target="_blank">took a stab at documentation for Peppy</a> too.</p>
<p>At the end of the day, it all depends on what our MooTools dev team wants to do because, after all, MooTools was created for their use, and it&#8217;s great if others can use it too.</p>
<p>P.S. Thanks to James Donaghue and John Resig on their awesome work!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/implement-other-selector-engines-eg-sizzle-or-peppy-into-mootools/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>
