<?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>dev.enekoalonso.com &#187; html</title>
	<atom:link href="http://dev.enekoalonso.com/tag/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.enekoalonso.com</link>
	<description>having fun with code</description>
	<lastBuildDate>Wed, 12 Oct 2011 21:40:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Angry Birds as a Web App</title>
		<link>http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/</link>
		<comments>http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/#comments</comments>
		<pubDate>Thu, 12 May 2011 17:40:58 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[angry]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[birds]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=693</guid>
		<description><![CDATA[Really, really cool, Rovio has released Angry Birds (and all the game assets) as a web app, Javascript and Canvas based. I can&#8217;t wait to see clones of Angry Birds with custom assets, maps and sounds. via Angry Birds as a Web App. Related Posts:July 30, 2010 -- Titanium Developer: love and hate (3)May 3, 2010 [...]]]></description>
			<content:encoded><![CDATA[<p>Really, really cool, Rovio has released Angry Birds (and all the game assets) as a web app, Javascript and Canvas based. I can&#8217;t wait to see clones of Angry Birds with custom assets, maps and sounds.</p>
<p>via <a href="http://googlesystem.blogspot.com/2011/05/angry-birds-as-web-app.html">Angry Birds as a Web App</a>.</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>July 30, 2010 -- <a href="http://dev.enekoalonso.com/2010/07/30/titanium-developer-love-and-hate/" title="Titanium Developer: love and hate">Titanium Developer: love and hate</a> (3)</li><li>May 3, 2010 -- <a href="http://dev.enekoalonso.com/2010/05/03/playing-with-websockets/" title="Playing with WebSockets">Playing with WebSockets</a> (4)</li><li>May 18, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/18/location-hash-is-dead-on-html5-browsers/" title="location.hash is dead (on html5 browsers)">location.hash is dead (on html5 browsers)</a> (0)</li><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding duplicate ID&#8217;s on an HTML page</title>
		<link>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/</link>
		<comments>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/#comments</comments>
		<pubDate>Fri, 06 May 2011 17:49:34 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[duplicate]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[id]]></category>
		<category><![CDATA[ids]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[page]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=687</guid>
		<description><![CDATA[Looks like sometimes we forgot element ID&#8217;s are meant to be unique on a HTML page. Here is a little bit of code I just wrote to find duplicate ID&#8217;s on a page (run the code on your browser&#8217;s javascript console): var idList = &#123;&#125;; var nodes = document.getElementsByClassName&#40;&#39;&#39;&#41;; for &#40;var i in nodes&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Looks like sometimes we forgot element ID&#8217;s are meant to be unique on a HTML page. Here is a little bit of code I just wrote to find duplicate ID&#8217;s on a page (run the code on your browser&#8217;s javascript console):</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> idList = <span class="br0">&#123;</span><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> nodes = document.<span class="me1">getElementsByClassName</span><span class="br0">&#40;</span><span class="st0">&#39;&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="kw1">in</span> nodes<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>isNaN<span class="br0">&#40;</span>i<span class="br0">&#41;</span> <span class="sy0">&amp;&amp;</span> nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span> = idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span>? idList<span class="br0">&#91;</span>nodes<span class="br0">&#91;</span>i<span class="br0">&#93;</span>.<span class="me1">id</span><span class="br0">&#93;</span><span class="nu0">+1</span>:<span class="nu0">1</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> id <span class="kw1">in</span> idList<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>idList<span class="br0">&#91;</span>id<span class="br0">&#93;</span> <span class="sy0">&gt;</span> <span class="nu0">1</span><span class="br0">&#41;</span> console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&quot;Duplicate id: #&quot;</span> + id<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Have fun!</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>May 12, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/" title="Angry Birds as a Web App">Angry Birds as a Web App</a> (0)</li><li>May 14, 2010 -- <a href="http://dev.enekoalonso.com/2010/05/14/interesting-json-vulnerability-old-stuff/" title="Interesting JSON vulnerability (old stuff)">Interesting JSON vulnerability (old stuff)</a> (0)</li><li>April 14, 2010 -- <a href="http://dev.enekoalonso.com/2010/04/14/getting-unique-timestamps-in-javascript/" title="Getting unique timestamps in Javascript">Getting unique timestamps in Javascript</a> (0)</li><li>March 24, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/" title="Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates">Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates</title>
		<link>http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/</link>
		<comments>http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 20:54:01 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[engine]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mooml]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[render]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=501</guid>
		<description><![CDATA[Mooml 1.1 has been finally released today and made available to everybody via Github and Mootools Forge plugin repository. What is new in Mooml 1.1 Mooml 1.1 has a lot of new features, but these are worth to mention: No more eval() Mooml.Template Mooml.Templates Pass functions as arguments to template functions References to elements with [...]]]></description>
			<content:encoded><![CDATA[<p>Mooml 1.1 has been finally released today and made available to everybody via Github and Mootools Forge plugin repository.</p>
<h2>What is new in Mooml 1.1</h2>
<p>Mooml 1.1 has a lot of new features, but these are worth to mention:</p>
<ul>
<li>No more eval()</li>
<li>Mooml.Template</li>
<li>Mooml.Templates</li>
<li>Pass functions as arguments to template functions</li>
<li>References to elements with an Id</li>
</ul>
<h2>No more eval()</h2>
<p>Although the use of eval() was transparent to the final user, Mooml 1.0.X depended on it to properly generate the dom elements using the template functions like div(), span(), table(), etc. Mooml 1.1 does not use eval() anymore, which prevents issues when compressing the code with compilers like Google Closure Compiler and also increments the overall performance of template rendering.</p>
<h2>Mooml.Template</h2>
<p>Mooml.Template is the new constructor for Mooml templates. This constructor will allow to create standalone templates like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> tpl = <span class="kw2">new</span> Mooml.<span class="me1">Template</span><span class="br0">&#40;</span><span class="st0">&#39;mytemplate&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>params<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; div<span class="br0">&#40;</span><span class="br0">&#123;</span> id: params.<span class="me1">divId</span> <span class="br0">&#125;</span>, params.<span class="me1">divContent</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">grab</span><span class="br0">&#40;</span>tpl.<span class="me1">render</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; divId: <span class="st0">&#39;mydiv&#39;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; divContent: <span class="st0">&#39;Hi there!&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// will create: &lt;div id=&quot;mydiv&quot;&gt;Hi there!&lt;/div&gt;</span></div>
</li>
</ol>
</div>
<p> There is no need to create a Mooml.Template object when using Mooml.register(), which will work as in previous versions of Mooml.</p>
<h2>Mooml.Templates</h2>
<p>Mooml.Templates is a mixing that can be implemented into other Mootools classes. This will allow these classes to create their own templates internally and use them without the need of registering global templates with Mooml.register(). Here is an example of a Dog class:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> Dog = <span class="kw2">new</span> <span class="kw2">Class</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; Implements: <span class="br0">&#91;</span>Options, Mooml.<span class="me1">Templates</span><span class="br0">&#93;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; options: <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; bark: <span class="st0">&#39;Bark! Bark!&#39;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; initialize: <span class="kw2">function</span><span class="br0">&#40;</span>options<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">setOptions</span><span class="br0">&#40;</span>options<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">register</span><span class="br0">&#40;</span><span class="st0">&#39;dog&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>bark<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;div<span class="br0">&#40;</span><span class="br0">&#123;</span> <span class="st0">&#39;class&#39;</span>: <span class="st0">&#39;dog&#39;</span><span class="br0">&#125;</span>, bark<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; toElement: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw1">this</span>.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">&#39;dog&#39;</span>, <span class="kw1">this</span>.<span class="me1">options</span>.<span class="me1">bark</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">grab</span><span class="br0">&#40;</span><span class="kw2">new</span> Dog<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// &lt;div class=&quot;dog&quot;&gt;Bark! Bark!&lt;/div&gt;</span></div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">grab</span><span class="br0">&#40;</span><span class="kw2">new</span> Dog<span class="br0">&#40;</span><span class="br0">&#123;</span> bark: <span class="st0">&#39;Woof! Woof!&#39;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// &lt;div class=&quot;dog&quot;&gt;Woof! Woof!&lt;/div&gt;</span></div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">grab</span><span class="br0">&#40;</span><span class="kw2">new</span> Dog<span class="br0">&#40;</span><span class="br0">&#123;</span> bark: <span class="st0">&#39;Arf!&#39;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// &lt;div class=&quot;dog&quot;&gt;Arf!&lt;/div&gt;</span></div>
</li>
</ol>
</div>
<h2>Pass functions as arguments to template functions</h2>
<p>With Mooml 1.1, template functions accept functions as arguments. These function can be any function that returns an element, array of elements, string, number or any other argument type supported by Mooml template functions. For example:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> tpl = <span class="kw2">new</span> Mooml.<span class="me1">Template</span><span class="br0">&#40;</span><span class="st0">&#39;mytemplate&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; div<span class="br0">&#40;</span>content<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">grab</span><span class="br0">&#40;</span>tpl.<span class="me1">render</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">return</span> <span class="st0">&#39;Html &lt;u&gt;returned&lt;/u&gt; by a function()&#39;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// will create: &lt;div&gt;Html &lt;u&gt;returned&lt;/u&gt; by a function()&lt;/div&gt;</span></div>
</li>
</ol>
</div>
<h2>References to elements with an Id</h2>
<p>Finally, Mooml 1.1 templates can return references to all elements rendered that contain an Id, including elements rendered in nested templates:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> tpl = <span class="kw2">new</span> Mooml.<span class="me1">Template</span><span class="br0">&#40;</span><span class="st0">&#39;mytemplate&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>content<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; div<span class="br0">&#40;</span><span class="br0">&#123;</span>id:<span class="st0">&#39;div1&#39;</span><span class="br0">&#125;</span>, content<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; div<span class="br0">&#40;</span><span class="br0">&#123;</span>id:<span class="st0">&#39;div2&#39;</span><span class="br0">&#125;</span>, content<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; div<span class="br0">&#40;</span><span class="br0">&#123;</span>id:<span class="st0">&#39;div3&#39;</span><span class="br0">&#125;</span>, content<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>, <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; saveElementRefs: <span class="kw2">true</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">body</span>.<span class="me1">adopt</span><span class="br0">&#40;</span>tpl.<span class="me1">render</span><span class="br0">&#40;</span><span class="st0">&#39;some text&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">tpl.<span class="me1">elementRefs</span>.<span class="me1">div1</span>; <span class="co1">// reference to &lt;div id=&quot;div1&quot;&gt;some text&lt;/div&gt;</span></div>
</li>
<li class="li1">
<div class="de1">tpl.<span class="me1">elementRefs</span>.<span class="me1">div2</span>; <span class="co1">// reference to &lt;div id=&quot;div2&quot;&gt;some text&lt;/div&gt;</span></div>
</li>
<li class="li1">
<div class="de1">tpl.<span class="me1">elementRefs</span><span class="br0">&#91;</span><span class="st0">&#39;div3&#39;</span><span class="br0">&#93;</span>; <span class="co1">// reference to &lt;div id=&quot;div3&quot;&gt;some text&lt;/div&gt;</span></div>
</li>
</ol>
</div>
<p>Don&#8217;t miss the new demo: <a href="http://enekoalonso.com/projects/mooml/">http://enekoalonso.com/projects/mooml/</a><br />
Enjoy!</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>April 28, 2010 -- <a href="http://dev.enekoalonso.com/2010/04/28/mooml-1-2-3-bye-bye-with/" title="Mooml 1.2.3 &#8211; Bye, bye, with()">Mooml 1.2.3 &#8211; Bye, bye, with()</a> (3)</li><li>March 15, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/15/more-updates-to-mooml-coming-soon/" title="More updates to Mooml coming soon">More updates to Mooml coming soon</a> (0)</li><li>February 19, 2010 -- <a href="http://dev.enekoalonso.com/2010/02/19/having-fun-with-mooml-and-twitter/" title="Having fun with Mooml &#038; Twitter">Having fun with Mooml &#038; Twitter</a> (0)</li><li>February 1, 2010 -- <a href="http://dev.enekoalonso.com/2010/02/01/mooml-globalize-mooml-template-functions-going-global/" title="Mooml.globalize(): Mooml template functions going global">Mooml.globalize(): Mooml template functions going global</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating HTML blocks with Mootools</title>
		<link>http://dev.enekoalonso.com/2009/09/02/creating-html-blocks-with-mootools/</link>
		<comments>http://dev.enekoalonso.com/2009/09/02/creating-html-blocks-with-mootools/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 20:50:16 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[extend]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[implement]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[mootools]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=376</guid>
		<description><![CDATA[Sometimes we need to create HTML from JS. There are multiple ways to do this, from using innerHTML to creating element by element appending child to parents, setting attributes, etc. And there are as many different opinions about what is the right way to do it. Meanwhile, once thing I missed from jQuery, not available [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we need to create HTML from JS. There are multiple ways to do this, from using innerHTML to creating element by element appending child to parents, setting attributes, etc. And there are as many different opinions about what is the right way to do it.</p>
<p>Meanwhile, once thing I missed from jQuery, not available on Mootools, was the ability to do something like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> element = jQuery<span class="br0">&#40;</span><span class="st0">&#39;&lt;div id=&quot;foo&quot;&gt;bar&lt;/div&gt;&#39;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>In Mootools, the equivalent should be:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> element = <span class="kw2">new</span> Element<span class="br0">&#40;</span><span class="st0">&#39;&lt;div id=&quot;foo&quot;&gt;bar&lt;/div&gt;&#39;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>But that does not work.</p>
<p>On the Mootools mailing list, someone was asking about how to implement this and we just found a different approach, which instead of using the Element class, extends the String class like this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">String.<span class="me1">implement</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;toElement: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">return</span> <span class="kw2">new</span> Element<span class="br0">&#40;</span><span class="st0">&#39;div&#39;</span>, <span class="br0">&#123;</span>html:<span class="kw1">this</span><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">getFirst</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Now you can do this:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> element &nbsp;= <span class="st0">&#39;&lt;div id=&quot;foo&quot;&gt;bar&lt;/div&gt;&#39;</span>.<span class="me1">toElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>To try it, paste this snippet on Firebug&#8217;s console:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">String.<span class="me1">implement</span><span class="br0">&#40;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;toElement: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">return</span> <span class="kw2">new</span> Element<span class="br0">&#40;</span><span class="st0">&#39;div&#39;</span>, <span class="br0">&#123;</span>html:<span class="kw1">this</span><span class="br0">&#125;</span><span class="br0">&#41;</span>.<span class="me1">getFirst</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">&#39;&lt;div id=&quot;foo&quot;&gt;bar&lt;/div&gt;&#39;</span>.<span class="me1">toElement</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&#39;id&#39;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>Nice, uh? Of course, the HTML can be as complex as you need and where do you get the content of the string is up to you :)</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>March 24, 2010 -- <a href="http://dev.enekoalonso.com/2010/03/24/mooml-1-1-no-more-eval-say-hi-to-mooml-template-and-mooml-templates/" title="Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates">Mooml 1.1 &#8211; No more eval(), say Hi to Mooml.Template and Mooml.Templates</a> (0)</li><li>May 12, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/" title="Angry Birds as a Web App">Angry Birds as a Web App</a> (0)</li><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li><li>October 5, 2010 -- <a href="http://dev.enekoalonso.com/2010/10/05/javascript-console-in-the-terminal-command-line/" title="Javascript console in the terminal (command line)">Javascript console in the terminal (command line)</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2009/09/02/creating-html-blocks-with-mootools/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Handling events on iPhone webapps</title>
		<link>http://dev.enekoalonso.com/2008/12/05/handling-events-on-iphone-webapps/</link>
		<comments>http://dev.enekoalonso.com/2008/12/05/handling-events-on-iphone-webapps/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 22:02:29 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=82</guid>
		<description><![CDATA[This week I have been working on a website for iPhone phones and I have discovered some interesting things about events. I am using plain Javascript, with no third party libraries, so I don&#8217;t know if they have any fix for these issues or if they affect them. For example, a couple of days ago [...]]]></description>
			<content:encoded><![CDATA[<p>This week I have been working on a website for iPhone phones and I have discovered some interesting things about events. I am using plain Javascript, with no third party libraries, so I don&#8217;t know if they have any fix for these issues or if they affect them.</p>
<p>For example, a couple of days ago I was posting <a href="http://dev.enekoalonso.com/2008/12/02/detecting-iphones-orientation/">how to detect the iPhone&#8217;s orientation</a>. The problem with the method I used is that I am assigning explicitly the function to handle the event, which means only that function will handle the event. If I wanted to add a second function to handle the same event, for example inside an object, I would have to use the window.addEventListener method. But apparently <strong>addEventListener does not work on the iPhone for some events</strong>.</p>
<p>The following code wont work on the iPhone (although it works on the iPhone simulator)</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> updateLayout<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>window.<span class="me1">orientation</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; document.<span class="me1">body</span>.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">&#39;class&#39;</span>, <span class="st0">&#39;landscape&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; document.<span class="me1">body</span>.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">&#39;class&#39;</span>, <span class="st0">&#39;portrait&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">&#39;orientationchange&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>event<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; updateLayout<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">window.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">&#39;load&#39;</span>, <span class="kw2">function</span><span class="br0">&#40;</span>event<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; updateLayout<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>I have found the addEventListener function works with input fields (focus and blur events), with links (click event) and with window (load event). I have found it doesn&#8217;t work on forms (submit event) neither with the custom onorientationchange event as shown avobe. I haven&#8217;t tested other events yet.</p>
<p>It may be that all these issues have been fixed in newer versions of the iPhone OS X &#8211; the one I have for testing is 1.1.4 (4A102).</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>May 12, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/12/angry-birds-as-a-web-app/" title="Angry Birds as a Web App">Angry Birds as a Web App</a> (0)</li><li>June 14, 2011 -- <a href="http://dev.enekoalonso.com/2011/06/14/titanium-studio-and-titanium-mobile-1-7/" title="Titanium Studio and Titanium Mobile 1.7">Titanium Studio and Titanium Mobile 1.7</a> (0)</li><li>May 6, 2011 -- <a href="http://dev.enekoalonso.com/2011/05/06/finding-duplicate-ids-on-an-html-page/" title="Finding duplicate ID&#8217;s on an HTML page">Finding duplicate ID&#8217;s on an HTML page</a> (0)</li><li>September 17, 2010 -- <a href="http://dev.enekoalonso.com/2010/09/17/mootools-core-for-server-and-mobile-development/" title="MooTools Core for Server and Mobile Development">MooTools Core for Server and Mobile Development</a> (1)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2008/12/05/handling-events-on-iphone-webapps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

