<?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; MoreSimple</title>
	<atom:link href="http://www.garrickcheung.com/tag/moresimple/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>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>
	</channel>
</rss>
