<?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; Javascript</title>
	<atom:link href="http://www.garrickcheung.com/category/javascript/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>Smarty Debug with Firebug</title>
		<link>http://www.garrickcheung.com/javascript/smarty-debug-with-firebug/</link>
		<comments>http://www.garrickcheung.com/javascript/smarty-debug-with-firebug/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 23:44:44 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Smarty]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=314</guid>
		<description><![CDATA[I use Smarty, a template engine, at work. One of the most awesome things about it is the debug window, where it can list all the templates being used and variables that are available. Mike Horn shared with me how a user, named Hipska, created a Smarty debug template file that works with Firebug. I [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://www.smarty.net" target="_blank">Smarty</a>, a template engine, at work. One of the most awesome things about it is the debug window, where it can list all the templates being used and variables that are available.</p>
<p><a href="http://www.thegpbkids.com/" target="_blank">Mike Horn</a> shared with me how a <a href="http://www.phphulp.nl/php/print/5/1540/0/scripts/" target="_blank">user, named Hipska, created a Smarty debug template</a> file that works with Firebug. I thought it was so awesome and decided to share it with you too, but with a slight tweak of my own.<span id="more-314"></span></p>
<h3>The Code</h3>
<p>Here&#8217;s the code. I&#8217;ll explain how it works right after.</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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
</pre></td><td class="code"><pre class="smarty" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">{* Smarty *}</span>
<span style="color: #008080; font-style: italic;">{* debug.tpl, firebug version by Hipska, tweaked by GarrickCheung *}</span>
<span style="color: #D36900;">&#123;</span>assign_debug_info<span style="color: #D36900;">&#125;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #0600FF;">isset</span><span style="color: #D36900;">&#40;</span>$_smarty_debug_output<span style="color: #D36900;">&#41;</span> and $_smarty_debug_output <span style="color: #D36900;">eq</span> <span style="color: #ff0000;">&quot;html&quot;</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.1//EN&quot; &quot;http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd&quot;&gt;</span>
<span style="color: #009000;">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot;&gt;</span>
<span style="color: #009000;">&lt;head&gt;</span>
    <span style="color: #009000;">&lt;title&gt;</span>Smarty Debug Console<span style="color: #009000;">&lt;/title&gt;</span>
<span style="color: #D36900;">&#123;</span>literal<span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;style type=&quot;text/css&quot;&gt;</span>
/* <span style="color: #009000;">&lt;![CDATA[ */</span>
<span style="color: #009000;">body, h1, h2, td, th, p {</span>
<span style="color: #009000;">    font-family: sans-serif;</span>
<span style="color: #009000;">    font-weight: normal;</span>
<span style="color: #009000;">    font-size: 0.9em;</span>
<span style="color: #009000;">    margin: 1px;</span>
<span style="color: #009000;">    padding: 0;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">h1 {</span>
<span style="color: #009000;">    margin: 0;</span>
<span style="color: #009000;">    text-align: left;</span>
<span style="color: #009000;">    padding: 2px;</span>
<span style="color: #009000;">    background-color: #f0c040;</span>
<span style="color: #009000;">    color:  black;</span>
<span style="color: #009000;">    font-weight: bold;</span>
<span style="color: #009000;">    font-size: 1.2em;</span>
<span style="color: #009000;"> }</span>
&nbsp;
<span style="color: #009000;">h2 {</span>
<span style="color: #009000;">    background-color: #9B410E;</span>
<span style="color: #009000;">    color: white;</span>
<span style="color: #009000;">    text-align: left;</span>
<span style="color: #009000;">    font-weight: bold;</span>
<span style="color: #009000;">    padding: 2px;</span>
<span style="color: #009000;">    border-top: 1px solid black;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">body {</span>
<span style="color: #009000;">    background: black; </span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">p, table, div {</span>
<span style="color: #009000;">    background: #f0ead8;</span>
<span style="color: #009000;">} </span>
&nbsp;
<span style="color: #009000;">p {</span>
<span style="color: #009000;">    margin: 0;</span>
<span style="color: #009000;">    font-style: italic;</span>
<span style="color: #009000;">    text-align: center;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">table {</span>
<span style="color: #009000;">    width: 100%;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">th, td {</span>
<span style="color: #009000;">    font-family: monospace;</span>
<span style="color: #009000;">    vertical-align: top;</span>
<span style="color: #009000;">    text-align: left;</span>
<span style="color: #009000;">    width: 50%;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">td {</span>
<span style="color: #009000;">    color: green;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">.odd {</span>
<span style="color: #009000;">    background-color: #eeeeee;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">.even {</span>
<span style="color: #009000;">    background-color: #fafafa;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">.exectime {</span>
<span style="color: #009000;">    font-size: 0.8em;</span>
<span style="color: #009000;">    font-style: italic;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">#table_assigned_vars th {</span>
<span style="color: #009000;">    color: blue;</span>
<span style="color: #009000;">}</span>
&nbsp;
<span style="color: #009000;">#table_config_vars th {</span>
<span style="color: #009000;">    color: maroon;</span>
<span style="color: #009000;">}</span>
<span style="color: #009000;">/* ]]&gt;</span> */
<span style="color: #009000;">&lt;/style&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span>literal<span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/head&gt;</span>
<span style="color: #009000;">&lt;body&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;h1&gt;</span>Smarty Debug Console<span style="color: #009000;">&lt;/h1&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;h2&gt;</span>included templates &amp;amp; config files (load time in seconds)<span style="color: #009000;">&lt;/h2&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;div&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>templates <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span>$_debug_tpls<span style="color: #D36900;">&#125;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span><span style="color: #008000;">indent</span> <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span>$_debug_tpls<span style="color: #D36900;">&#91;</span>templates<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">depth</span><span style="color: #D36900;">&#125;</span>&amp;nbsp;&amp;nbsp;&amp;nbsp;<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #009000;">&lt;font color={if $_debug_tpls[templates].type eq &quot;template&quot;}brown{elseif $_debug_tpls[templates].type eq &quot;insert&quot;}black{else}green{/if}&gt;</span>
        <span style="color: #D36900;">&#123;</span>$_debug_tpls<span style="color: #D36900;">&#91;</span>templates<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">filename</span>|escape:html<span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/font&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #0600FF;">isset</span><span style="color: #D36900;">&#40;</span>$_debug_tpls<span style="color: #D36900;">&#91;</span>templates<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">exec_time</span><span style="color: #D36900;">&#41;</span><span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;span class=&quot;exectime&quot;&gt;</span>
        (<span style="color: #D36900;">&#123;</span>$_debug_tpls<span style="color: #D36900;">&#91;</span>templates<span style="color: #D36900;">&#93;</span>.<span style="color: #006600;">exec_time</span>|string_format:<span style="color: #ff0000;">&quot;%.5f&quot;</span><span style="color: #D36900;">&#125;</span>)
        <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">if</span> <span style="color: #D36900;">%</span>templates.<span style="color: #006600;">index</span><span style="color: #D36900;">%</span> <span style="color: #D36900;">eq</span> <span style="color: #cc66cc;">0</span><span style="color: #D36900;">&#125;</span>(total)<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;/span&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #009000;">&lt;br /&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">sectionelse</span><span style="color: #D36900;">&#125;</span>
    <span style="color: #009000;">&lt;p&gt;</span>no templates included<span style="color: #009000;">&lt;/p&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/div&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;h2&gt;</span>assigned template variables<span style="color: #009000;">&lt;/h2&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;table id=&quot;table_assigned_vars&quot;&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>vars <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span>$_debug_keys<span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;tr class=&quot;{cycle values=&quot;odd,even&quot;}&quot;&gt;</span>
            <span style="color: #009000;">&lt;th&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">ldelim</span><span style="color: #D36900;">&#125;</span>$<span style="color: #D36900;">&#123;</span>$_debug_keys<span style="color: #D36900;">&#91;</span>vars<span style="color: #D36900;">&#93;</span>|escape:<span style="color: #ff0000;">'html'</span><span style="color: #D36900;">&#125;</span><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">rdelim</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/th&gt;</span>
            <span style="color: #009000;">&lt;td&gt;</span><span style="color: #D36900;">&#123;</span>$_debug_vals<span style="color: #D36900;">&#91;</span>vars<span style="color: #D36900;">&#93;</span>|@debug_print_var<span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/td&gt;&lt;/tr&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">sectionelse</span><span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;tr&gt;&lt;td&gt;&lt;p&gt;</span>no template variables assigned<span style="color: #009000;">&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/table&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;h2&gt;</span>assigned config file variables (outer template scope)<span style="color: #009000;">&lt;/h2&gt;</span>
&nbsp;
<span style="color: #009000;">&lt;table id=&quot;table_config_vars&quot;&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">section</span> <span style="color: #6A0A0A;">name</span><span style="color: #D36900;">=</span>config_vars <span style="color: #6A0A0A;">loop</span><span style="color: #D36900;">=</span>$_debug_config_keys<span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;tr class=&quot;{cycle values=&quot;odd,even&quot;}&quot;&gt;</span>
            <span style="color: #009000;">&lt;th&gt;</span><span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">ldelim</span><span style="color: #D36900;">&#125;</span>#<span style="color: #D36900;">&#123;</span>$_debug_config_keys<span style="color: #D36900;">&#91;</span>config_vars<span style="color: #D36900;">&#93;</span>|escape:<span style="color: #ff0000;">'html'</span><span style="color: #D36900;">&#125;</span>#<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">rdelim</span><span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/th&gt;</span>
            <span style="color: #009000;">&lt;td&gt;</span><span style="color: #D36900;">&#123;</span>$_debug_config_vals<span style="color: #D36900;">&#91;</span>config_vars<span style="color: #D36900;">&#93;</span>|@debug_print_var<span style="color: #D36900;">&#125;</span><span style="color: #009000;">&lt;/td&gt;&lt;/tr&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">sectionelse</span><span style="color: #D36900;">&#125;</span>
        <span style="color: #009000;">&lt;tr&gt;&lt;td&gt;&lt;p&gt;</span>no config vars assigned<span style="color: #009000;">&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;</span>
    <span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">section</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;/table&gt;</span>
<span style="color: #009000;">&lt;/body&gt;</span>
<span style="color: #009000;">&lt;/html&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #0600FF;">else</span><span style="color: #D36900;">&#125;</span>
<span style="color: #009000;">&lt;script type=&quot;text/javascript&quot;&gt;</span>
// <span style="color: #009000;">&lt;![CDATA[</span>
<span style="color: #009000;">var Smarty_debug = function Smarty_debug(collapsed){ldelim}</span>
&nbsp;
<span style="color: #009000;">	var group = (collapsed) ? console.groupCollapsed : console.group;</span>
&nbsp;
<span style="color: #009000;">	group(&quot;Smarty Debug&quot;);</span>
&nbsp;
<span style="color: #009000;">	group(&quot;Included templates &amp; config files&quot;);</span>
<span style="color: #009000;">	{section name=templates loop=$_debug_tpls}</span>
<span style="color: #009000;">		 console.log(&quot;{$_debug_tpls[templates].filename|escape:javascript}{if isset($_debug_tpls[templates].exec_time)} - {$_debug_tpls[templates].exec_time|string_format:&quot;%.5f&quot;}{if %templates.index% eq 0} (total){/if}{/if}&quot;);</span>
<span style="color: #009000;">	{sectionelse}</span>
<span style="color: #009000;">		 console.info(&quot;no templates included&quot;);</span>
<span style="color: #009000;">	{/section}</span>
<span style="color: #009000;">	console.groupEnd();</span>
&nbsp;
<span style="color: #009000;">	group(&quot;Assigned template variables&quot;);</span>
<span style="color: #009000;">	{section name=vars loop=$_debug_keys}</span>
<span style="color: #009000;">		 console.log(&quot;{ldelim}${$_debug_keys[vars]|escape:'javascript'}{rdelim}:&quot;, {$_debug_vals[vars]|@json_encode});</span>
<span style="color: #009000;">	{sectionelse}</span>
<span style="color: #009000;">		 console.info(&quot;no template variables assigned&quot;);</span>
<span style="color: #009000;">	{/section}</span>
<span style="color: #009000;">	console.groupEnd();</span>
&nbsp;
<span style="color: #009000;">	group(&quot;Assigned config file variables&quot;);</span>
<span style="color: #009000;">	{section name=config_vars loop=$_debug_config_keys}</span>
<span style="color: #009000;">		 console.log(&quot;{ldelim}#{$_debug_config_keys[config_vars]|escape:'javascript'}#{rdelim}:&quot;, {$_debug_config_vals[config_vars]|@json_encode});</span>
<span style="color: #009000;">	{sectionelse}</span>
<span style="color: #009000;">		 console.info(&quot;no config file variables assigned&quot;);</span>
<span style="color: #009000;">	{/section}</span>
<span style="color: #009000;">	console.groupEnd();</span>
&nbsp;
<span style="color: #009000;">	console.groupEnd();</span>
<span style="color: #009000;">	return &quot;Smarty version {$smarty.version}&quot;;</span>
&nbsp;
<span style="color: #009000;">{rdelim};</span>
<span style="color: #009000;">// ]]&gt;</span>
<span style="color: #009000;">&lt;/script&gt;</span>
<span style="color: #D36900;">&#123;</span><span style="color: #D36900;">/</span><span style="color: #0600FF;">if</span><span style="color: #D36900;">&#125;</span></pre></td></tr></table></div>

<h3>How it Works</h3>
<p>This debug template gives you two options on how to view it: the original method display&#8217;s everything in a new pop-up window, the new and awesome method shows the same thing but in the Firebug Console. The template has an if statement/flag that checks whether it should be rendered in HTML or use Firebug. You&#8217;ll have to do some digging on how to setup this flag in your configuration, but the flag is in line 4 defined as $_smarty_debug_output.</p>
<p>The default is to use Firebug. A function named Smarty_debug is defined at the bottom at line 143. When you run it in the Firebug console, it will print out the Smarty debug information in the console as collapsible groups. If the browser doesn&#8217;t support console, then you probably shouldn&#8217;t be using this method, that&#8217;s why the HTML version is available.</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;">Smarty_debug<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//type this in your Firebug Console</span></pre></td></tr></table></div>

<p>It bothered me a little that Hipska&#8217;s method printed out every line in the group once Smarty_debug function is called. Now here&#8217;s my tweak: I&#8217;ve made it optional to print out as a collapsed group but you WILL need Firebug 1.3+ (if it works on other versions, please let me know).  All you need to do is supply a boolean argument.</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;">Smarty_debug<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//prints out a collapsed group</span></pre></td></tr></table></div>

<h3>Conclusion</h3>
<p>I really love being able to print out the Smarty debug data to the Firebug Console because I won&#8217;t have to deal with an additional pop-up every time. I get&#8217;s a little annoying and I think it suck&#8217;s up more memory. Thank you Hipska and Mike!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/smarty-debug-with-firebug/feed/</wfw:commentRss>
		<slash:comments>1</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>Solution to Flash and Select Drop-downs Covering HTML Elements</title>
		<link>http://www.garrickcheung.com/javascript/solution-to-flash-and-select-drop-downs-covering-html-elements/</link>
		<comments>http://www.garrickcheung.com/javascript/solution-to-flash-and-select-drop-downs-covering-html-elements/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 13:00:15 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[HTML / XHTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[markup hierarchy]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=91</guid>
		<description><![CDATA[I&#8217;ve positioned elements absolutely and had to deal with a bug where the element appears below a flash object or select drop-downs, which usually occurs in IE. I&#8217;ve seen a few solutions, which work great, and I have one more to add. Solution 1: iFrame This solution comes from Joe King&#8217;s post. In case you [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve positioned elements absolutely and had to deal with a bug where the element appears below a flash object or select drop-downs, which usually occurs in IE. I&#8217;ve seen a few solutions, which work great, and I have one more to add.<span id="more-91"></span></p>
<h3>Solution 1: iFrame</h3>
<p>This solution comes from <a href="http://www.dotnetjunkies.com/WebLog/jking/archive/2003/07/21/488.aspx" target="_blank">Joe King&#8217;s post</a>.</p>
<blockquote><p>In case you don&#8217;t already know, windowed controls in IE will always cover DHTML layers.  That means if you have a DIV that pops up or floats on the page and it intersects with a windowed control (such as the common SELECT box), the windowed control will obscure the DIV, no matter what zIndex you have set for each element.</p></blockquote>
<p>The solution is to create an iFrame shim under the element that needs to appear above the select drop down.</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;"><span style="color: #003366; font-weight: bold;">var</span> element <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id_of_element'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> iframe_shim <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'iframe'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">'id'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'shim'</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'scrolling'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'no'</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'frameborder'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">'styles'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">'width'</span><span style="color: #339933;">:</span> element.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//Plug in the width of absolutely positioned object here</span>
        <span style="color: #3366CC;">'height'</span><span style="color: #339933;">:</span> element.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;,</span> <span style="color: #006600; font-style: italic;">//Plug in the height of absolutely positioned object here</span>
        <span style="color: #3366CC;">'filter'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'</span> <span style="color: #006600; font-style: italic;">// fixes transparency</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">inject</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">,</span><span style="color: #3366CC;">'after'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//this automatically injects the shim after the element.</span></pre></td></tr></table></div>

<p>Keep in mind you&#8217;ll probably need to modify this to work with your needs. E.g. For drop down navigation, you would create the shim and use Javascript to make adjustments to the position and dimensions of the shim to reflect that dropped down menu in the navigation.</p>
<h3>Solution 2: Flash Param: wmode=transparent</h3>
<p>This solution was found on <a href="http://www.cssplay.co.uk/menus/flyout_flash.html" target="_blank">CSS Play by Stu and Fran Nicholls</a>.</p>
<p>So you have a flash object and you require HTML elements to appear above it. You set the HTML elements positioning to absolute and try z-index, which probably didn&#8217;t work in IE. You only need to set the flash object&#8217;s wmode parameter to transparent to fix this. Use the &lt;param&gt; to set the name/value, and set the wmode attribute on the &lt;embed&gt; tag like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;param name=&quot;wmode&quot; value=&quot;transparent&quot;&gt;
&lt;embed src=&quot;flash.swf&quot; quality=&quot;high&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;100&quot; height=&quot;100&quot; wmode=&quot;transparent&quot;&gt;&lt;/embed&gt;</pre></td></tr></table></div>

<h3>Solution 3: Markup Hierarchy</h3>
<p>Let&#8217;s say you have a flash object that you have no control over, such as a YouTube video. The flash object comes in with wmode=&#8221;window&#8221; or something. What do you do? Consider markup hierarchy. In IE, the next HTML element is considered at a higher layer than the element before it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;box_1&quot;&gt;Box 1&lt;/div&gt;
&lt;div class=&quot;box_2&quot;&gt;Box 2&lt;/div&gt;</pre></td></tr></table></div>

<p>Box 1 will appear above Box 2. So using the drop down navigation as an example again (from solution 1) I would use Javascript to relocate the navigation&#8217;s html markup below the flash object and adjust the positioning of the nav to make it look like it never moved via CSS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/solution-to-flash-and-select-drop-downs-covering-html-elements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run Javascript Functions Without using &#8216;domready&#8217; Event</title>
		<link>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/</link>
		<comments>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/#comments</comments>
		<pubDate>Sun, 09 Nov 2008 01:35:27 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[domready]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=125</guid>
		<description><![CDATA[I don&#8217;t really like using the &#8216;domready&#8217; event. The idea of adding another event to the window object just bugs me. So here&#8217;s the alternative. In short, an array is created, functions you want to run are added to the array, and when the page reaches the bottom the functions in the array are run. [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t really like using the &#8216;domready&#8217; event. The idea of adding another event to the window object just bugs me. So here&#8217;s the alternative. In short, an array is created, functions you want to run are added to the array, and when the page reaches the bottom the functions in the array are run.<span id="more-125"></span></p>
<h3>The Code</h3>
<p>I create my <a href="http://www.garrickcheung.com/javascript/dont-pollute-the-global-space-namespace-it/">namespaced object literal</a> which includes an array to keep all the functions I want to run. This would be at the top in the &lt;head&gt;.</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>GTC_CORE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> GTC_CORE <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'init'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
GTC_CORE.<span style="color: #660066;">init</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//returns an empty array</span></pre></td></tr></table></div>

<p>At the bottom of the page, right before the &lt;body&gt; tag, I have the code to run all the functions that are in the GTC_CORE.init array. Here I will be using MooTools Array.each() method.</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>GTC_CORE.<span style="color: #660066;">init</span>.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    GTC_CORE.<span style="color: #660066;">init</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>func<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        func<span style="color: #009900;">&#40;</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></pre></td></tr></table></div>

<h3>Adding Functions to the Array</h3>
<p>If you have &#8216;domready&#8217; blocks in the content between the &lt;body&gt; tags, it&#8217;s a simple change. I&#8217;ll give you the before and after.</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;">//Before</span>
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: #006600; font-style: italic;">//Load this stuff here</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;">//After</span>
GTC_CORE.<span style="color: #660066;">init</span>.<span style="color: #660066;">push</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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Load this stuff here</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Simple as pie and one less event to add. Keep in mind that &#8216;domready&#8217; is used to make sure that the DOM elements were all loaded. If you need something to happen on &#8216;load&#8217;, then that&#8217;s a different story. The &#8216;load&#8217; event makes sure that even the images are done loading, where the &#8216;domready&#8217; event does not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/run-javascript-functions-without-using-domready-event/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Pollute the Global Space; Namespace It!</title>
		<link>http://www.garrickcheung.com/javascript/dont-pollute-the-global-space-namespace-it/</link>
		<comments>http://www.garrickcheung.com/javascript/dont-pollute-the-global-space-namespace-it/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 01:07:08 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[dot notation]]></category>
		<category><![CDATA[global space]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[object literal]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=128</guid>
		<description><![CDATA[I like to namespace my code with object literals to contain all my functions and classes. It keeps things organized, decreases global space pollution from additional functions, and prevents conflicts with third-party scripts. It&#8217;s very easy to extend too. Create the Namespaced Object I usually start out by checking whether the namespaced object literal is [...]]]></description>
			<content:encoded><![CDATA[<p>I like to namespace my code with object literals to contain all my functions and classes. It keeps things organized, decreases global space pollution from additional functions, and prevents conflicts with third-party scripts. It&#8217;s very easy to extend too.<span id="more-128"></span></p>
<h3>Create the Namespaced Object</h3>
<p>I usually start out by checking whether the namespaced object literal is already existing, and if it&#8217;s not, then create one. You can use the name of the website, or your initials, whatever works. I&#8217;m going to use my initials and &#8220;CORE&#8221;.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>GTC_CORE<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> GTC_CORE <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Extend your Namespace</h3>
<p>Like I said, I like to use dot notation. It&#8217;s just my preference.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">GTC_CORE.<span style="color: #660066;">printHello</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
GTC_CORE.<span style="color: #660066;">printWelcome</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Welcome!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Namespace in Action</h3>
<p>So here we have a GTC_CORE namespaced object. Now let&#8217;s say we want to run the printHello function. You just run it like how you do any other function you&#8217;ve written.</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;">GTC_CORE.<span style="color: #660066;">printHello</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;">// Alert appears printing 'Hello!'</span>
GTC_CORE.<span style="color: #660066;">printWelcome</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;">// Alert appears printing 'Welcome!'</span></pre></td></tr></table></div>

<h3>Alternative to Dot Notation: Start with the Object Literal</h3>
<p>There are other ways to create a namespace. Here we&#8217;re just plugging in the functions into the object literal GTC_CORE. Notice that every addition requires a comma, except the last one. I&#8217;ll also throw in a couple examples for variables and nesting object literals inside.</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
29
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> GTC_CORE <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// printHello function</span>
    <span style="color: #3366CC;">'printHello'</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Hello!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//printWelcome function</span>
    <span style="color: #3366CC;">'printWelcome'</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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Welcome!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//the value of 'name' is Garrick, a string</span>
    <span style="color: #3366CC;">'name'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Garrick'</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//the value of 'num' is 12, an int</span>
    <span style="color: #3366CC;">'num'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//nested object literal</span>
    <span style="color: #3366CC;">'nested'</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">'val1'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">'val2'</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">2</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
GTC_CORE.<span style="color: #660066;">printHello</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;">//Alerts with &quot;Hello!&quot;</span>
GTC_CORE.<span style="color: #660066;">printWelcome</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;">//Alerts with &quot;Welcome!&quot;</span>
GTC_CORE.<span style="color: #000066;">name</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//returns 'Garrick'</span>
GTC_CORE.<span style="color: #660066;">num</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//returns 10</span>
GTC_CORE.<span style="color: #660066;">nested</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//returns object literal</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/dont-pollute-the-global-space-namespace-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get Around Form submit() Mapping</title>
		<link>http://www.garrickcheung.com/javascript/get-around-form-submit-mapping/</link>
		<comments>http://www.garrickcheung.com/javascript/get-around-form-submit-mapping/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 06:32:27 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[HTML / XHTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[submit()]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=131</guid>
		<description><![CDATA[If you&#8217;ve had to use javascript to submit a form, you may have used the forms submit() method. You may also experienced difficulty, such as a &#8220;submit is not a function&#8221; error. It has to deal with mapping and I&#8217;ve got a very simple solution. The Setup: Just so you know, this is done with [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve had to use javascript to submit a form, you may have used the forms submit() method. You may also experienced difficulty, such as a &#8220;submit is not a function&#8221; error. It has to deal with mapping and I&#8217;ve got a very simple solution.<span id="more-131"></span></p>
<h3>The Setup:</h3>
<p>Just so you know, this is done with MooTools 1.2, but if you know javascript, you can build it from scratch.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;response_form&quot; action=&quot;response.html&quot; method=&quot;get&quot;&gt;
    &lt;fieldset&gt;
        &lt;legend&gt;Test&lt;/legend&gt;
        Grab the response.
        &lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot; /&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'response_form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
form.<span style="color: #660066;">getElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input[type=submit]'</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>
    form.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>The Test:</h3>
<p>Copy the code into a test html file. Open Firebug (you DO have Firebug and FireFox, don&#8217;t you?) and display the console. Click on the submit button and there should be an error.</p>
<h3>The Solution:</h3>
<p>Very simple now. Change the name to anything besides submit and you&#8217;ve fixed the mapping issue.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;input type=&quot;submit&quot; name=&quot;submit_btn&quot; value=&quot;submit&quot; /&gt;</pre></td></tr></table></div>

<p>This one took me a while to find, but I was glad when I did. I hope this is helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/get-around-form-submit-mapping/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What I Learned About Multi-threading in JavaScript</title>
		<link>http://www.garrickcheung.com/javascript/what-i-learned-about-multi-threading-in-javascript/</link>
		<comments>http://www.garrickcheung.com/javascript/what-i-learned-about-multi-threading-in-javascript/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 04:01:22 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[$clear]]></category>
		<category><![CDATA[delay()]]></category>
		<category><![CDATA[periodical()]]></category>
		<category><![CDATA[setInterval]]></category>
		<category><![CDATA[setTimeout]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=95</guid>
		<description><![CDATA[There&#8217;s no such thing. Correct me if I&#8217;m wrong, but multi-threading in javascript does not exist. But we can simulate it, as is discussed by James Edwards. How does it work? It all hinges on the use of asynchronous timers. When we run repetitive code inside an asynchronous timer, we’re giving the browser’s script interpreter [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s no such thing. Correct me if I&#8217;m wrong, but multi-threading in javascript does not exist. But we can simulate it, as is <a href="http://www.sitepoint.com/article/multi-threading-javascript/" target="_blank">discussed by James Edwards</a>. How does it work?</p>
<blockquote><p>It all hinges on the use of asynchronous timers. When we run repetitive code inside an asynchronous timer, we’re giving the browser’s script interpreter time to process each iteration.</p></blockquote>
<p><span id="more-95"></span></p>
<p>This is a solution for those times we have our scripts set up to do some major processing with loops, which causes the browser to hang. In Firefox you get an &#8220;unresponsive script&#8221; warning during those times.</p>
<blockquote><p>Effectively, a piece of code inside a for iterator is asking the interpreter to do everything straight away: “run this code n times as fast as possible.” However the same code inside an asynchronous timer is breaking the code up into small, discreet chunks; that is, “run this code once as fast possible,”—then wait—then “run this code once as fast as possible”, and so on, n times.</p>
<p>The trick is that the code inside each iteration is small and simple enough for the interpreter to process it completely within the speed of the timer, be it 100 or 5,000 milliseconds. If that requirement is met, then it doesn’t matter how intense the overall code is, because we’re not asking for it to be run all at once.</p></blockquote>
<h3>The Code</h3>

<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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> checksomething<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> okay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>  
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> limit <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> processor <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>busy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>condition<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                okay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">==</span> limit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                clearInterval<span style="color: #009900;">&#40;</span>processor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Notice that in line 4 we&#8217;re setting an interval to run a function every 100ms. Once the iteration has met the limit, it clears the interval. So basically, we have something running in the background every 100ms. This solves the problem of causing the browser to spit out the &#8220;unresponsive script&#8221; warning. But there&#8217;s another problem. If you want the function to return something, it will always return false because:</p>
<blockquote><p>&#8230;the inner function is asynchronous. The outer function will return before the first iteration of the inner function has even happened!</p></blockquote>
<p>This got me thinking about how I&#8217;ve used callback functions when doing ajax requests. Basically, you pass in a function as an argument and have it run inside the function.</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;"><span style="color: #003366; font-weight: bold;">var</span> test_func <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: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'this is test func.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> test_func2 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callBack<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'this is test func 2.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    callBack<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
test_func2<span style="color: #009900;">&#40;</span>test_func<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">/* Result is an alert appears stating &quot;this is test func 2&quot; and right after another alert appears stating &quot;this is test func&quot;. */</span></pre></td></tr></table></div>

<p>Upon reading further, James also had the same idea.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> checksomething<span style="color: #009900;">&#40;</span>oncomplete<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> okay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> limit <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> processor <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>busy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>condition<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                okay <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">==</span> limit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                clearInterval<span style="color: #009900;">&#40;</span>processor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> oncomplete <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    oncomplete<span style="color: #009900;">&#40;</span>okay<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You can also use setTimeout()/clearTimeout() instead of setInterval()/clearInterval().</p>
<h3>In MooTools 1.2.1</h3>
<p>MooTools has some methods to the timing stuff too. The function periodical() method uses setInterval() and the function delay() method uses setTimeout(). Both can be cleared using $clear() by passing in the timer.</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: #003366; font-weight: bold;">var</span> delay_run <span style="color: #339933;">=</span> run_func.<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//runs the function in one second.</span>
<span style="color: #003366; font-weight: bold;">var</span> periodical_run <span style="color: #339933;">=</span> run_func.<span style="color: #660066;">periodical</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #006600; font-style: italic;">//runs the function every one second.</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Clears the timers</span>
$clear<span style="color: #009900;">&#40;</span>delay_run<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$clear<span style="color: #009900;">&#40;</span>periodical_run<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Here&#8217;s one of James&#8217; functions but with the periodical() method:</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="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> count_func <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>callBack<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> limit <span style="color: #339933;">=</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> processor <span style="color: #339933;">=</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: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>busy<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>i <span style="color: #339933;">==</span> limit<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                $clear<span style="color: #009900;">&#40;</span>processor<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$type<span style="color: #009900;">&#40;</span>callBack<span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    callBack<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            busy <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</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: #660066;">periodical</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>I know it looks pretty much the same. But it&#8217;s just SLIGHTLY cleaner.. yeah? Well the point is that now you know about simulating multi-threading in javascript!</p>
<p>Thank you James for introducing me and everyone else to this technique. This was an awesome lesson!</p>
<p>P.S. <a href="http://www.sitepoint.com/forums/showpost.php?p=4019631&#038;postcount=12" target="_blank">Word on the street (or a user comment on James&#8217; article)</a> is that:</p>
<blockquote><p>Per the difference between setTimeout and setInterval, as I understand it, they both generate events, which get put on a queue. Since a webpage basically runs in a single thread, only one event can be handled at a time, so the events on the queue just run in order, one after another- including the timers. Thus, the timer never executes EXACTLY in the interval you specify. The timer only generates an event exactly when you specify, and the event function itself only gets executed whenever the browser&#8217;s single thread gets up to it in the queue. One additional consequence is that if a setInterval event happens, and there&#8217;s already a setInterval event on the queue that hasn&#8217;t been executed yet, the new event doesn&#8217;t get added to the queue. So setInterval events get dropped. The smaller you set your interval, and the more complex your function, the more likely they are to get dropped.</p>
<p>this doesn&#8217;t happen with setTimeout however. Since the new setTimeout events don&#8217;t get added until the last setTimeout function has finished, you never have more than one timer event on the queue at a time.</p></blockquote>
<p>I suggest figuring out a way to use setTimeout to make sure that a timer event isn&#8217;t dropped.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/what-i-learned-about-multi-threading-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Form property set/get error with MooTools in Internet Explorer</title>
		<link>http://www.garrickcheung.com/javascript/form-property-setget-error-with-mootools-in-internet-explorer/</link>
		<comments>http://www.garrickcheung.com/javascript/form-property-setget-error-with-mootools-in-internet-explorer/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 09:13:51 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=30</guid>
		<description><![CDATA[When I was working on TV.com&#8216;s redesign, I found an error when setting or getting a form element&#8217;s properties in IE. The other browsers was able to set or get the property just fine. So I&#8217;m going to share my solution with you today. I&#8217;ll go over the methods MooTools has first so you know [...]]]></description>
			<content:encoded><![CDATA[<p>When I was working on <a href="http://www.tv.com" target="_blank">TV.com</a>&#8216;s redesign, I found an error when setting or getting a form element&#8217;s properties in IE. The other browsers was able to set or get the property just fine. So I&#8217;m going to share my solution with you today.  I&#8217;ll go over the methods MooTools has first so you know what I was doing.<span id="more-30"></span></p>
<h3>MooTools Set or Get</h3>
<p>MooTools has two sets of methods when setting or getting an elements properties.</p>
<p>You can use the <a href="http://mootools.net/docs/Element/Element#Element:set" target="_blank">set()</a> or <a href="http://mootools.net/docs/Element/Element#Element:get" target="_blank">get()</a> method like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Element Method: set</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'anchor_id'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://www.testurl.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// sets the element's href</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Element Method: get</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'anchor_id'</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> <span style="color: #006600; font-style: italic;">// returns the element's href as a string</span></pre></div></div>

<p>Or you can use <a href="http://mootools.net/docs/Element/Element#Element:setProperty" target="_blank">setProperty()</a> or <a href="http://mootools.net/docs/Element/Element#Element:getProperty" target="_blank">getProperty()</a> methods:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Element Method: setProperty</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'anchor_id'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'http://www.testurl.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// sets the element's href</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Element Method: getProperty</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'anchor_id'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// returns the element's href as a string</span></pre></div></div>

<p>Note: There&#8217;s also methods to set/get more than one property and remove property(s) using:</p>
<ul>
<li><a href="http://mootools.net/docs/Element/Element#Element:setProperties" target="_blank">setProperties()</a></li>
<li><a href="http://mootools.net/docs/Element/Element#Element:getProperties" target="_blank">getProperties()</a></li>
<li><a href="http://mootools.net/docs/Element/Element#Element:removeProperty" target="_blank">removeProperty()</a></li>
<li><a href="http://mootools.net/docs/Element/Element#Element:removeProperties" target="_blank">removeProperties()</a></li>
</ul>
<h3>Error Up Ahead!</h3>
<p>The problem I came across was when I wanted to set or get a form elements property in IE. If the form element contained an element with a name property that is the same as the form elements property name then an error would occur. Here&#8217;s the code example:</p>
<p>HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;test_form&quot; action=&quot;http://www.testurl.com/action_page/&quot; method=&quot;post&quot;&gt;
    &lt;fieldset&gt;
        &lt;legend&gt;&lt;/legend&gt;
&lt;input name=&quot;action&quot; type=&quot;hidden&quot; value=&quot;ajax_call&quot; /&gt;
    &lt;/fieldset&gt;
&lt;/form&gt;</pre></div></div>

<p>Javascript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'test_form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// grab the element</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> get_action <span style="color: #339933;">=</span> form.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// IE returns null, others return the url as a string</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> getProperty_action <span style="color: #339933;">=</span> form.<span style="color: #660066;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// IE returns null, others return the url as a string</span></pre></div></div>

<h3>Eureka: The Solution!</h3>
<p>The only way I could find around this was to use Javascripts native method when dealing with DOM elements. Take a look at this code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> form <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'test_form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// grab the element</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> get_action <span style="color: #339933;">=</span> form.<span style="color: #660066;">getAttributeNode</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'action'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">nodeValue</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// IE, and the other browsers, returns the url as a string</span></pre></div></div>

<p>Now you just need to remember not to name your child nodes the same name as the name of the parent form elements property so you can continue to use MooTools method, or use the native method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/form-property-setget-error-with-mootools-in-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Inspired by Aaron Newton&#8217;s &#8220;Programming to the Pattern&#8221;</title>
		<link>http://www.garrickcheung.com/javascript/inspired-by-aaron-newtons-programming-to-the-pattern/</link>
		<comments>http://www.garrickcheung.com/javascript/inspired-by-aaron-newtons-programming-to-the-pattern/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 06:33:56 +0000</pubDate>
		<dc:creator>Garrick</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[Javascript Pattern]]></category>

		<guid isPermaLink="false">http://www.garrickcheung.com/?p=15</guid>
		<description><![CDATA[Aaron Newton is a contrbutor to MooTools and the care-taker of Clientside, CNET.com&#8217;s developer blog. He recently wrote about being inspired to write code differently and a more indepth post about his thoughts on (take a deep breath if you&#8217;re verbally reading this) &#8220;jQuery, MooTools, the Ajax Experience, Programming to the Pattern, and What Really [...]]]></description>
			<content:encoded><![CDATA[<p>Aaron Newton is a contrbutor to MooTools and the care-taker of Clientside, CNET.com&#8217;s developer blog. He recently wrote about being <a href="http://clientside.cnet.com/best-practices/thoughts-on-coding-and-new-classes-as-a-result/" target="_blank">inspired to write code differently</a> and a more indepth post about his thoughts on (take a deep breath if you&#8217;re verbally reading this) &#8220;<a href="http://clientside.cnet.com/best-practices/jquery-and-the-ajax-experience-programming-to-the-pattern-and-what-really-makes-one-framework-different-from-another/" target="_blank">jQuery, MooTools, the Ajax Experience, Programming to the Pattern, and What Really Makes One Framework Different From Another</a>&#8220;. He has inspired me to be more aware of how I write my code.<span id="more-15"></span></p>
<h3>Programming to the Pattern</h3>
<p>Aaron&#8217;s says:</p>
<blockquote><p>When I write my code, I can choose to be an architect, or a construction worker. I can design, or I can implement. In reality, I must do both, but I can choose which one I want to do more and, in many ways, it’s possible for me to do almost entirely one or the other &#8211; though not 100%.</p>
<p>What the hell am I talking about? Let me put it to you this way: if you write 20 lines of code to describe a user interaction on a page to make it snazzy or easier to use, is it worth writing another 5 or 10 lines to make that code reusable? If you program the experience directly, you’ll always write it again and again. But if you program the pattern, you’ll write less and less.</p></blockquote>
<p>This part really got me thinking because I know I don&#8217;t want to keep re-writing code, but that&#8217;s just what I&#8217;ve been doing. I&#8217;ve tried writting my classes to be reuseable, and so have my co-workers, though the only real way to reuse it is to not only copy of the class, but use the same HTML markup as well, which I don&#8217;t really want to do because other people may have different markup.</p>
<p>His code example is a really good one:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> PopupForm <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>
	Implements<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span>Events<span style="color: #339933;">,</span> Options<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
	options<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		requestOptions<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">/*the user can fill in additional ajax options*/</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		onComplete<span style="color: #339933;">:</span> $empty <span style="color: #006600; font-style: italic;">//do nothing on complete by default</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	initialize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>link<span style="color: #339933;">,</span> form<span style="color: #339933;">,</span> popup<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">form</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">link</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>link<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">popup</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>popup<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setOptions</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">makeRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">attach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	makeRequest<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">request</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">form</span>.<span style="color: #660066;">retrieve</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'send'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">requestOptions</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">request</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'complete'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			popup.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #339933;">,</span> response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'complete'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	attach<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">link</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">show</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">form</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit'</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">request</span>.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	show<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">popup</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	hide<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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">popup</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><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></div></div>

<p>He goes on to show that you can also extend this class by changing the show and hide functions to add some animation.</p>
<p>I also really like the benefits he stated:</p>
<ul>
<blockquote>
<li>My code is now far more legible. I have small methods that just do one thing and I know what it’s doing and why. My classes are named things that describe what they do, and the classes themselves are small things that just do one thing. If I need a class that does two things, I write two classes and a small controller class that calls them.</li>
<li>My code is reusable &#8211; if the pattern ever comes up again, I don’t have to write it again. I’ve amazed myself in how often this has happened. Stuff I never, ever thought I’d reuse ends up coming back to me in a week and there I am using it again.</li>
<li>The points where my application &#8211; the web page I’m working on at the moment &#8211; touches my generic code are very small. I don’t write much code about the pages themselves &#8211; all I do is instantiate classes for a given page element. This small footprint means that there’s less code that’s only good for that page.</li>
<li>When it’s time to refactor &#8211; perhaps there’s a new version of the framework I’m using, or a new browser bug is found, or a new browser hits the market (oh, hi <a href="http://www.google.com/chrome">chrome</a>), or I find a bug in my own code (which is the most frequent of all these reasons), I have to go fix it. If I’m writing all my code for each page I have to go refactor it everywhere. If, on the other hand, my pages just instantiate my classes, I only have to refactor my classes. Since I control the interface to my classes, I can completely rewrite the class without having to touch the code that instantiates them.</li>
<li>Finally, I end up changing the way I think about the user experience I develop. I’m much more likely to develop an experience and reuse it than create a new one from scratch. This creates an experience consistency that, to me, means a better user experience.</li>
</blockquote>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.garrickcheung.com/javascript/inspired-by-aaron-newtons-programming-to-the-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
