<?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; MooTools</title>
	<atom:link href="http://www.garrickcheung.com/category/mootools/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>Building on David Walshes MooTools Tip: Event.stop</title>
		<link>http://www.garrickcheung.com/mootools/mootools-tip-event-stop/</link>
		<comments>http://www.garrickcheung.com/mootools/mootools-tip-event-stop/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 02:56:45 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=362</guid>
		<description><![CDATA[David Walsh shared a tip on how he handles firing events on an element without user input to trigger the event. I&#8217;m going to build on that by sharing how I would handle it. Problem The issue is that usually an event is added and the default behavior is disabled. 1 2 3 4 $&#40;'myLink'&#41;.addEvent&#40;'click',function&#40;e&#41; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://davidwalsh.name/mootools-event-stop">David Walsh shared a tip</a> on how he handles firing events on an element without user input to trigger the event. I&#8217;m going to build on that by sharing how I would handle it.<span id="more-362"></span></p>
<h3>Problem</h3>
<p>The issue is that usually an event is added and the default behavior is disabled.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myLink'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    e.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//do stuff</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And if you just so happen to need to trigger the event manually, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myLink'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You&#8217;ll get an error that the stop method doesn&#8217;t exist. This is because you&#8217;re just firing the function and an event argument is not being passed into the function.</p>
<p>Now, lets say you have a class and you wanted to manually execute a method that&#8217;s being attached to an event. An error would also occur in this case.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myClass <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// ... some code here..</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// the click event function that is attached..</span>
    clicky<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        e.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #006600; font-style: italic;">//.. do some clicky stuff</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<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;">// create instance of class</span>
<span style="color: #003366; font-weight: bold;">var</span> instance_of_myClass <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myClass<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;">// firing clicky function</span>
instance_of_myClass.<span style="color: #660066;">clicky</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// results in error because stop() does not exist</span></pre></td></tr></table></div>

<h3>Solution</h3>
<p>Here&#8217;s how you can solve both problems, and I learned this from <a href="http://keetology.com/">Mark Obcena</a>. This is very useful if you don&#8217;t want to modify the classes code or extend it. Pass in a dummy object with an empty stop function:</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;"><span style="color: #006600; font-style: italic;">// this will fire the click event without an issue</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myLink'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #000066;">stop</span><span style="color: #339933;">:</span>$empty<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;">// this too will fire the clicky function on the instance without an issue</span>
instance_of_myClass.<span style="color: #660066;">clicky</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">stop</span><span style="color: #339933;">:</span>$empty<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Tada! Thanks David and Mark!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/mootools-tip-event-stop/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Announcing: MooTools Forge!</title>
		<link>http://www.garrickcheung.com/mootools/announcing-mootools-forge/</link>
		<comments>http://www.garrickcheung.com/mootools/announcing-mootools-forge/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 21:24:01 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=359</guid>
		<description><![CDATA[Exciting news! MooTools has just announced their plugin repository, MooTools Forge! It&#8217;s hooked into GitHub and it&#8217;s open sourced. How awesome! Check out all the details from the MooTools blog!]]></description>
			<content:encoded><![CDATA[<p>Exciting news! <a href="http://mootools.net">MooTools</a> has just announced their plugin repository, <a href="http://mootools.net/forge/">MooTools Forge</a>! It&#8217;s hooked into <a href="http://www.github.com">GitHub</a> and it&#8217;s open sourced. How awesome!</p>
<p>Check out all the details from the <a href="http://mootools.net/blog/2009/12/10/the-official-mootools-plugins-repository-is-here/">MooTools blog</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/announcing-mootools-forge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Released: MooTools 1.2.3</title>
		<link>http://www.garrickcheung.com/mootools/released-mootools-123/</link>
		<comments>http://www.garrickcheung.com/mootools/released-mootools-123/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 22:18:15 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=349</guid>
		<description><![CDATA[I&#8217;m excited to tell you that MooTools 1.2.3 has been released today! It&#8217;s mainly bug fixes and updates. One major change is compatibility with other frameworks. Like the MooTools-Dev team, I do not advise using more than one framework. But if you have to.. then you have to. See below for a list of changes, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m excited to tell you that <a href="http://mootools.net/blog/2009/06/19/mootools-123-released/" target="_blank">MooTools 1.2.3</a> has been released today! It&#8217;s mainly bug fixes and updates. One major change is compatibility with other frameworks. Like the MooTools-Dev team, I do not advise using more than one framework. But if you have to.. then you have to. See below for a list of changes, straight from the cows mouth!<span id="more-349"></span></p>
<p><strong>Core</strong></p>
<ul>
<li>Element: MooTools compatibility mode: the $ function is only defined if no pre-existing $ function is found. If an existing $ function is found, you can use document.id()</li>
<li>Element: changed internal instances of $ to document.id</li>
<li>Core: fix for server-side MS JScript 5.x; makes MooTools more friendly for server side programming</li>
<li>Class: Class doesn’t require Browser, removed from scripts.json</li>
<li>Element: Fixes for set/get Property</li>
<li>Element.Dimensions: fix for webkit body.scrollTop inconsistency, getBoundingClientRect used whenever possible (not just for Trident), renaming element.position to element.setPosition; adding docs for the method; alias is included in-line for compatibility</li>
<li>Hash: Hash extend no longer uses the window if no arguments supplied</li>
<li>Request: clearing Request readystate before calling success or failure;</li>
<li>Selectors: Added :enabled pseudoselector, was in the Docs but not implemented.</li>
<li>Docs: Fixed docs headers for first-child, last-child, and only-child.</li>
<li>Internal: UnitTester test suite is now a git submodule</li>
<li>Numerous small fixes, speed improvements, documentation tweaks, etc.</li>
</ul>
<p><strong>More</strong></p>
<ul>
<li>Per the change in -core, $ is no longer used (uses document.id instead)</li>
<li>Element.Measure: trying cssText solution for Element.expose (again).</li>
<li>Element.Forms: swapping feature detection for browser support per</li>
<li>Date: Massive refactoring of Date.js and Date.Extras.js</li>
<li>Drag.Move: Fixing drag with grid issues</li>
<li>IframeShim: altering zindex assignment in IframeShim to better ensure that it’s always underneath the shimmed element, updating Iframeshim’s empty document creation; fixes https issues in IE6</li>
<li>FormValidator: reworking formvalidator scroll-to logic to be a little more efficient</li>
<li>OverText: preventing overtext from focusing on inputs except when they are interacted with (so OverText.update() does not focus an input);now stops polling when elements are hidden (when polling is enabled)</li>
<li>Fx.Scroll: adding scrollIntoView method &#8211; scrolls an element so that it is completely visible; if below the view, scrolls down until it is at the bottom of the screen, if above, scrolls up until it is at the top.</li>
<li>JSONP: was calling (the deprecated) this.request instead of this.send during retries</li>
<li>URI: Adding set(‘data’, obj) to set</li>
<li>Assets: adding error callback for Assets.images</li>
<li>Tips: removing dependency for Element.Measure for Tips; updating CSS class name in OverText</li>
<li>Numerous small fixes, speed improvements, documentation tweaks, etc.</li>
</ul>
<p>Great job MooTools-Dev team!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/released-mootools-123/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Search Stylesheet Selectors with MooTools</title>
		<link>http://www.garrickcheung.com/css/search-stylesheet-selectors-with-mootools/</link>
		<comments>http://www.garrickcheung.com/css/search-stylesheet-selectors-with-mootools/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 22:30:52 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[selector]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=340</guid>
		<description><![CDATA[You should already know that MooTools has Fx.Morph, that allows you to animate multiple css properties on an element and you can also pass it a selector string so you don&#8217;t have to type out all of the properties. Well, you can also pull these properties by using an undocumented method in MooTools, as I [...]]]></description>
			<content:encoded><![CDATA[<p>You should already know that MooTools has Fx.Morph, that allows you to animate multiple css properties on an element and you can also pass it a selector string so you don&#8217;t have to type out all of the properties.</p>
<p>Well, you can also pull these properties by using an undocumented method in MooTools, as I just learned from <a href="http://keetology.com/" target="_blank">Mark Obcena</a>. How? It&#8217;s very simple as you will see.<span id="more-340"></span></p>
<h3>Code</h3>

<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: #003366; font-weight: bold;">var</span> selector_rules <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Fx.<span style="color: #660066;">CSS</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">search</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.some_class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// returns an object with camelCase key's</span></pre></td></tr></table></div>

<p>See, isn&#8217;t that simple? Keep in mind that this doesn&#8217;t give you every single property. In my tests of running this code with Firebug on <a href="http://www.gamespot.com" target="_blank">GameSpot.com</a>, font-family and overflow properties were missing in the returned object when it clearly shows up in Firebug&#8217;s CSS panel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/css/search-stylesheet-selectors-with-mootools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MooTools TextOverlay Class</title>
		<link>http://www.garrickcheung.com/mootools/textoverlay-class/</link>
		<comments>http://www.garrickcheung.com/mootools/textoverlay-class/#comments</comments>
		<pubDate>Tue, 19 May 2009 06:55:50 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[MoreSimple]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=328</guid>
		<description><![CDATA[Some classes I&#8217;ve come across do a lot and are inflexible. I&#8217;ve seen some that are semantically incorrect when it comes to creating/using elements that the user has no control over. So I&#8217;ve been mulling over the idea of rewriting/cleaning/correcting some of these classes that I come across in hopes to make them flexible and [...]]]></description>
			<content:encoded><![CDATA[<p>Some classes I&#8217;ve come across do a lot and are inflexible. I&#8217;ve seen some that are semantically incorrect when it comes to creating/using elements that the user has no control over. So I&#8217;ve been mulling over the idea of rewriting/cleaning/correcting some of these classes that I come across in hopes to make them flexible and simple. Well, I decided to have a go at it, obviously</p>
<p>I understand it&#8217;s like re-inventing the wheel. But in order to improve, we should always scrutinize work because a better solution may be available.</p>
<p>Here&#8217;s my first attempt, with the MooTools class, TextOverlay. If you look closely, it&#8217;s MooTools-More OverText modified to give the user more options.<span id="more-328"></span></p>
<h3>What&#8217;s the Difference?</h3>
<p>You must be wondering what&#8217;s different between the two. Well, I felt that positioning of the element should be handled by css, so I removed the reposition method. In OverText, the text-overlaying was created for you with MooTools and the default element was a &#8216;div&#8217; with &#8216;label&#8217; as your option.  I did away with that and you now can either pass in an existing DOM element, or create one on the fly (though you&#8217;ll need to inject it into the DOM yourself). OverText &#8216;show&#8217; and &#8216;hide&#8217; methods explicitly call&#8217;s the text-overlay&#8217;s show/hide methods and then fires custom events &#8216;textShow&#8217; and &#8216;textHide&#8217;. I decided to give the user flexibility by removing the explicit call&#8217;s to the text-overlay&#8217;s and only firing the custom events.</p>
<h3>Example</h3>
<p>The HTML, CSS, and JavaScript below is an example of how to set things up.</p>
<p><strong>HTML</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;container&quot;&gt;
    &lt;form id=&quot;textoverlay_test&quot; name=&quot;textoverlay_test&quot; action=&quot;&quot; method=&quot;post&quot;&gt;
        &lt;fieldset&gt;
            &lt;legend&gt;&lt;/legend&gt;
            &lt;div class=&quot;fields&quot;&gt;
                &lt;input id=&quot;first_name&quot; type=&quot;text&quot; name=&quot;first_name&quot; value=&quot;&quot; /&gt;
                &lt;label for=&quot;first_name&quot;&gt;First Name&lt;/label&gt;
            &lt;/div&gt;
            &lt;div class=&quot;fields&quot;&gt;
                &lt;input type=&quot;text&quot; name=&quot;last_name&quot; value=&quot;&quot; /&gt;
                &lt;label for=&quot;last_name&quot;&gt;Last Name&lt;/label&gt;
            &lt;/div&gt;
        &lt;/fieldset&gt;
    &lt;/form&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p><strong>CSS</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.container</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
input<span style="color: #00AA00;">,</span> label <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">11px</span> arial<span style="color: #00AA00;">,</span> veranda<span style="color: #00AA00;">,</span> helvetica<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
label <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">-16px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.fields</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><strong>JavaScript</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'domready'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> input<span style="color: #339933;">,</span> label<span style="color: #339933;">,</span> fields <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#textoverlay_test .fields'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">new</span> TextOverlay<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'label'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
            onTextHide<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                text.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hide'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//added to differentiate from default textHide event</span>
            <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
            onTextShow<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span> text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                text.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'show'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//added to differentiate from default textShow event</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Doing all this should simplify things and decrease the number of function calls. If you did a &#8216;console.profile&#8217; in Firebug, I&#8217;m sure you&#8217;ll notice the difference between OverText and TextOverlay. Give it a try and let me know what you think! I&#8217;ve set it up in <a href="http://github.com/GCheung55/MoreSimple/" target="_blank">Github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/textoverlay-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MooTools FileManager by Christoph Pojer</title>
		<link>http://www.garrickcheung.com/uncategorized/mootools-filemanager-by-christoph-pojer/</link>
		<comments>http://www.garrickcheung.com/uncategorized/mootools-filemanager-by-christoph-pojer/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 21:23:29 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[file manager]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=322</guid>
		<description><![CDATA[Christoph, one of MooTools&#8217; developers and creator of Styx, a PHP framework, created a MooTools based File Manager. I&#8217;ve tried out his demos, and everything seems VERY slick. It has loads of features too. Features (straight from the horses mouth) Browse through Files and Folders on your Server Rename, Delete, Move (Drag&#38;Drop), Copy (Drag + [...]]]></description>
			<content:encoded><![CDATA[<p>Christoph, one of MooTools&#8217; developers and creator of <a href="http://styx.og5.net/" target="_blank">Styx, a PHP framework</a>, <a href="http://og5.net/christoph/article/MooTools_based_FileManager" target="_blank">created a MooTools based File Manager</a>. I&#8217;ve tried out his demos, and everything seems VERY slick. It has loads of features too.<span id="more-322"></span></p>
<p><strong>Features</strong> (straight from the horses mouth)</p>
<ul>
<li>Browse through Files and Folders on your Server</li>
<li>Rename, Delete, Move (Drag&amp;Drop), Copy (Drag + hold CTRL) and Download Files</li>
<li>View detailed Previews of Images, Text-Files, Compressed-Files or Audio Content</li>
<li>Nice User Interface <img src='http://www.garrickcheung.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>Upload Files via FancyUpload (integrated Feature)</li>
<li>Option to automatically resize big Images when uploading</li>
<li>Use it to select a File anywhere you need to specify one inside your Application&#8217;s Backend</li>
<li>Use as a FileManager in TinyMCE</li>
<li>Provides your Client with the most possible convenience ( ;D )</li>
</ul>
<p>The back-end is in PHP but you can port it to whatever language you&#8217;re working with. The file manager is also released under the MIT-License. This is currently his RC1 (1st release candidate, for those not in the know). <a href="http://og5.net/christoph/article/MooTools_based_FileManager" target="_blank">Head over to check out his demos</a>!</p>
<p>Great job, Christoph!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/uncategorized/mootools-filemanager-by-christoph-pojer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MooTools 1.2.2 and More Released!</title>
		<link>http://www.garrickcheung.com/mootools/mootools-122-and-more-released/</link>
		<comments>http://www.garrickcheung.com/mootools/mootools-122-and-more-released/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 01:31:19 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=318</guid>
		<description><![CDATA[Valerio Proietti just posted the release of MooTools 1.2.2 and MooTools More (1.2.2.1). Looks like there are some goodies from the Core: MooTools 1.2.2 is a mainly a bug fix release but it also includes an almost entirely new Class.js. The reasoning behind this is that the old Class.js didn’t play nicely with some advanced [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mootools.net/blog/2009/04/23/mootools-122-and-the-new-mootools-more/" target="_blank"> Valerio Proietti just posted the release of MooTools 1.2.2 and MooTools More (1.2.2.1)</a>.</p>
<p>Looks like there are some goodies from the Core:</p>
<blockquote><p>
MooTools 1.2.2 is a mainly a bug fix release but it also includes an almost entirely new Class.js. The reasoning behind this is that the old Class.js didn’t play nicely with some advanced usages of this.parent() present in the new MooTools-More. We already had the script ready and tested in the MooTools 2.0 branch so we simply “backported” it to 1.2.2. Other than providing the parent fixes, the new Class also features a much more robust inheritance model, especially when dealing with objects.
</p></blockquote>
<p>And something for the More:</p>
<blockquote><p>One of the new features of MooTools-More, since the last RC, is that it is now possible access the previous state of overwritten methods of classes through Class.refractor.</p></blockquote>
<p>And last bit of exciting news: quick/regular new feature bi-weekly releases.</p>
<p>Way to go team! Thank you for the awesome work!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/mootools-122-and-more-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>MooTools ContextMenu Class by David Walsh</title>
		<link>http://www.garrickcheung.com/mootools/mootools-contextmenu-class-by-david-walsh/</link>
		<comments>http://www.garrickcheung.com/mootools/mootools-contextmenu-class-by-david-walsh/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 08:50:39 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=288</guid>
		<description><![CDATA[Do you need to write some custom code or plug-in together for a context menu? I&#8217;m talking about the menu that comes up when you use your right mouse click. Well, now you don&#8217;t because David Walsh has release a pretty wicked and flexible ContextMenu class for MooTools. It&#8217;s simple because it&#8217;ll create something like: [...]]]></description>
			<content:encoded><![CDATA[<p>Do you need to write some custom code or plug-in together for a context menu? I&#8217;m talking about the menu that comes up when you use your right mouse click. Well, now you don&#8217;t because David Walsh has release a pretty wicked and flexible <a href="http://davidwalsh.name/mootools-context-menu" target="_blank">ContextMenu class for MooTools</a>.<span id="more-288"></span></p>
<p>It&#8217;s simple because it&#8217;ll create something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;ul id=&quot;contextmenu&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;#edit&quot; class=&quot;edit&quot;&gt;Edit&lt;/a&gt;&lt;/li&gt;
	&lt;li class=&quot;separator&quot;&gt;&lt;a href=&quot;#cut&quot; class=&quot;cut&quot;&gt;Cut&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#copy&quot; class=&quot;copy&quot;&gt;Copy&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#paste&quot; class=&quot;paste&quot;&gt;Paste&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#delete&quot; class=&quot;delete&quot;&gt;Delete&lt;/a&gt;&lt;/li&gt;
	&lt;li class=&quot;separator&quot;&gt;&lt;a href=&quot;#quit&quot; class=&quot;quit&quot;&gt;Quit&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>And display the following with a right click:<br />
<img src="http://www.garrickcheung.com/wp-content/uploads/dw-context.jpg" alt="ContextMenu Class" /></p>
<p>I really like that you can enable/disable the menu or individual items in the menu. Something I&#8217;m looking forward to in his next version is to be able to add/remove items.</p>
<p>Head on over to <a href="http://davidwalsh.name/mootools-context-menu" target="_blank">his post</a> for more info, the files, and a demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/mootools-contextmenu-class-by-david-walsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Aaron Newton&#8217;s Event Delegation for MooTools</title>
		<link>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/</link>
		<comments>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 19:00:57 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[MooTools]]></category>
		<category><![CDATA[event delegation]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=252</guid>
		<description><![CDATA[I just learned of Aaron Newton&#8217;s Event.Delegate.js and think it is amazing. Why is it amazing? Event delegation is a common practice where by you attach an event listener to a parent object to monitor its children rather than attach events to all the children. It’s far more efficient when you have numerous items on [...]]]></description>
			<content:encoded><![CDATA[<p>I just learned of <a href="http://www.clientcide.com/code-releases/event-delegation-for-mootools/" target="_blank">Aaron Newton&#8217;s Event.Delegate.js</a> and think it is amazing. Why is it amazing?</p>
<blockquote><p>
Event delegation is a common practice where by you attach an event listener to a parent object to monitor its children rather than attach events to all the children. It’s far more efficient when you have numerous items on a page that you want to interact with.</p></blockquote>
<p>The examples below should give you a better idea how awesome it is.<br />
<span id="more-252"></span></p>
<h3>The Problem</h3>
<p>Say you have A LOT of anchors and you want to add a click event to them. Normally you&#8217;d do this in several ways:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// First method</span>
<span style="color: #003366; font-weight: bold;">var</span> links <span style="color: #339933;">=</span> $$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
links.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    link.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//Do this stuff</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;">// Second method</span>
$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.link'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Do this stuff</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This is all fine but it&#8217;s not very efficient. You end up looping through all the anchors to add the event.</p>
<h3>The Solution</h3>
<p>With Event.Delegate you can attach an event to the parent, and have it handle everything. I&#8217;m going to use the example from Aaron&#8217;s post with a small addition to what I have above.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Parent element handles the delegation, and here it's document.body</span>
document.<span style="color: #660066;">body</span>.<span style="color: #660066;">delegate</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'a.link'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Just like addEvent, you can pass in the event and stop it.</span>
    e.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'you clicked a link!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Conclusion</h3>
<p>I really like Event Delegation. I&#8217;m really curious how fast it is though. Time to do a couple console.profile() to log the times.</p>
<p>I didn&#8217;t understand this part of his post:</p>
<blockquote><p>Finally, you can pass in a function of your own. If your function returns true, then your method will fire. Note that the element passed to your method is not extended by MooTools yet for efficiency. You should avoid extending it yourself (by passing it through $) as this will affect performance. Instead, use the static methods on Element.
</p></blockquote>
<p>It confused me. I thought he was talking about the third argument, until he mentioned it&#8217;s a function that returns true. Passing in a function as a test looks something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//My test function</span>
<span style="color: #003366; font-weight: bold;">var</span> testFunc <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> target.<span style="color: #660066;">match</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.link'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
document.<span style="color: #660066;">body</span>.<span style="color: #660066;">delegate</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> testFunc<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    e.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'you clicked a link!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Thanks for writing about this Aaron. It&#8217;s a really great addition.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/mootools/aaron-newtons-event-delegation-for-mootools/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
